forked from Nolij/Zume
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
definitely larger but at least get() works now
- Loading branch information
Showing
4 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.nolij.zson; | ||
|
||
public class ZsonKey { | ||
public final String key; | ||
public String comment; | ||
|
||
public ZsonKey(String key, String comment) { | ||
this.key = key; | ||
this.comment = comment; | ||
} | ||
|
||
public ZsonKey(String key) { | ||
this(key, null); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return key.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
package dev.nolij.zson; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class ZsonMap extends LinkedHashMap<Map.Entry<String, String>, Object> { | ||
public class ZsonMap extends LinkedHashMap<ZsonKey, Object> { | ||
public ZsonMap() { | ||
super(); | ||
} | ||
|
||
@SafeVarargs | ||
public ZsonMap(Map.Entry<Map.Entry<String, String>, Object>... entries) { | ||
public ZsonMap(Map.Entry<ZsonKey, Object>... entries) { | ||
super(entries.length); | ||
for (var entry : entries) { | ||
this.put(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
|
||
public ZsonMap put(String key, String comment, Object value) { | ||
this.put(new AbstractMap.SimpleEntry<>(key, comment), value); | ||
this.put(new ZsonKey(key, comment), value); | ||
return this; | ||
} | ||
|
||
public ZsonMap put(String key, Object value) { | ||
return this.put(key, "", value); | ||
this.put(new ZsonKey(key), value); | ||
return this; | ||
} | ||
|
||
public Object get(String key) { | ||
return this.get(new ZsonKey(key)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters