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.
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 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,5 @@ | ||
operator fun String.invoke(): String = rootProject.properties[this] as? String ?: error("Property $this not found") | ||
|
||
dependencies { | ||
implementation(project(":api")) | ||
} |
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,68 @@ | ||
package dev.nolij.zson; | ||
|
||
public class JsonElement { | ||
public final String key; | ||
|
||
// 0/1 if boolean, value if number | ||
private double value; | ||
|
||
// true = floating point, false = non-floating point, null = boolean | ||
private final Boolean type; | ||
|
||
private JsonElement(String key, double value, Boolean type) { | ||
this.key = key; | ||
this.value = value; | ||
this.type = type; | ||
} | ||
|
||
public static JsonElement doubleElement(String key, double value) { | ||
return new JsonElement(key, value, true); | ||
} | ||
|
||
public static JsonElement intElement(String key, int value) { | ||
return new JsonElement(key, value, false); | ||
} | ||
|
||
public static JsonElement booleanElement(String key, boolean value) { | ||
return new JsonElement(key, value ? 1 : 0, null); | ||
} | ||
|
||
public String toString() { | ||
return key + ": " + (type == null ? | ||
value == 1 ? "true" : "false" | ||
: type ? value : (int) value); | ||
} | ||
|
||
public int getAsInt() { | ||
if(!isInt()) { | ||
throw new IllegalStateException("Element is not an integer"); | ||
} | ||
return (int) value; | ||
} | ||
|
||
public double getAsDouble() { | ||
if(!isDouble()) { | ||
throw new IllegalStateException("Element is not a double"); | ||
} | ||
return value; | ||
} | ||
|
||
public boolean getAsBoolean() { | ||
if(!isBoolean()) { | ||
throw new IllegalStateException("Element is not a boolean"); | ||
} | ||
return value == 1; | ||
} | ||
|
||
public boolean isInt() { | ||
return Boolean.FALSE.equals(type); | ||
} | ||
|
||
public boolean isDouble() { | ||
return Boolean.TRUE.equals(type); | ||
} | ||
|
||
public boolean isBoolean() { | ||
return type == null; | ||
} | ||
} |