-
Notifications
You must be signed in to change notification settings - Fork 5
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
28 changed files
with
1,265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-jsonb-parent</artifactId> | ||
<version>3.0-RC1</version> | ||
</parent> | ||
|
||
<artifactId>avaje-json-node</artifactId> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-json</artifactId> | ||
<version>3.0-RC1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>1.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
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,66 @@ | ||
package io.avaje.json.node; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* JSON Array type. | ||
*/ | ||
public final class JsonArray implements JsonNode { | ||
|
||
private final List<JsonNode> children; | ||
|
||
/** | ||
* Create a new JsonArray that can be added to. | ||
*/ | ||
public static JsonArray create() { | ||
return new JsonArray(new ArrayList<>()); | ||
} | ||
|
||
/** | ||
* Create an unmodifiable JsonArray with the given elements. | ||
*/ | ||
public static JsonArray of(List<JsonNode> children) { | ||
return new JsonArray(Collections.unmodifiableList(children)); | ||
} | ||
|
||
JsonArray(List<JsonNode> children) { | ||
this.children = requireNonNull(children); | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.ARRAY; | ||
} | ||
|
||
@Override | ||
public String text() { | ||
return children.toString(); | ||
} | ||
|
||
/** | ||
* Return the child elements. | ||
*/ | ||
public List<JsonNode> elements() { | ||
return children; | ||
} | ||
|
||
/** | ||
* Return true if the json array is empty. | ||
*/ | ||
public boolean isEmpty() { | ||
return children.isEmpty(); | ||
} | ||
|
||
/** | ||
* Add an element to the json array. | ||
*/ | ||
public JsonArray add(JsonNode element) { | ||
children.add(element); | ||
return this; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
json-node/src/main/java/io/avaje/json/node/JsonBoolean.java
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,29 @@ | ||
package io.avaje.json.node; | ||
|
||
public final class JsonBoolean implements JsonNode { | ||
|
||
private final boolean value; | ||
|
||
public static JsonBoolean of(boolean value) { | ||
return new JsonBoolean(value); | ||
} | ||
|
||
private JsonBoolean(boolean value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.BOOLEAN; | ||
} | ||
|
||
@Override | ||
public String text() { | ||
return Boolean.toString(value); | ||
} | ||
|
||
public boolean value() { | ||
return value; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
json-node/src/main/java/io/avaje/json/node/JsonDecimal.java
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,58 @@ | ||
package io.avaje.json.node; | ||
|
||
import io.avaje.json.JsonWriter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public final class JsonDecimal implements JsonNumber { | ||
|
||
private final BigDecimal value; | ||
|
||
public static JsonDecimal of(BigDecimal value) { | ||
return new JsonDecimal(value); | ||
} | ||
|
||
private JsonDecimal(BigDecimal value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.NUMBER; | ||
} | ||
|
||
@Override | ||
public String text() { | ||
return value.toString(); | ||
} | ||
|
||
@Override | ||
public int intValue() { | ||
return value.intValueExact(); | ||
} | ||
|
||
@Override | ||
public long longValue() { | ||
return value.longValueExact(); | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return value.doubleValue(); | ||
} | ||
|
||
@Override | ||
public BigDecimal decimalValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public Number numberValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void toJson(JsonWriter writer) { | ||
writer.value(value); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
json-node/src/main/java/io/avaje/json/node/JsonDouble.java
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,58 @@ | ||
package io.avaje.json.node; | ||
|
||
import io.avaje.json.JsonWriter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public final class JsonDouble implements JsonNumber { | ||
|
||
private final double value; | ||
|
||
public static JsonDouble of(double value) { | ||
return new JsonDouble(value); | ||
} | ||
|
||
private JsonDouble(double value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.NUMBER; | ||
} | ||
|
||
@Override | ||
public String text() { | ||
return Double.toString(value); | ||
} | ||
|
||
@Override | ||
public int intValue() { | ||
return (int)value; | ||
} | ||
|
||
@Override | ||
public long longValue() { | ||
return (long)value; | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public BigDecimal decimalValue() { | ||
return BigDecimal.valueOf(this.value); | ||
} | ||
|
||
@Override | ||
public Number numberValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void toJson(JsonWriter writer) { | ||
writer.value(value); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
json-node/src/main/java/io/avaje/json/node/JsonInteger.java
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,58 @@ | ||
package io.avaje.json.node; | ||
|
||
import io.avaje.json.JsonWriter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public final class JsonInteger implements JsonNumber { | ||
|
||
private final int value; | ||
|
||
public static JsonInteger of(int value) { | ||
return new JsonInteger(value); | ||
} | ||
|
||
private JsonInteger(int value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.NUMBER; | ||
} | ||
|
||
@Override | ||
public String text() { | ||
return Long.toString(value); | ||
} | ||
|
||
@Override | ||
public int intValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public long longValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public BigDecimal decimalValue() { | ||
return BigDecimal.valueOf(value); | ||
} | ||
|
||
@Override | ||
public Number numberValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void toJson(JsonWriter writer) { | ||
writer.value(value); | ||
} | ||
} |
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,58 @@ | ||
package io.avaje.json.node; | ||
|
||
import io.avaje.json.JsonWriter; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public final class JsonLong implements JsonNumber { | ||
|
||
private final long value; | ||
|
||
public static JsonLong of(long value) { | ||
return new JsonLong(value); | ||
} | ||
|
||
private JsonLong(long value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public Type type() { | ||
return Type.NUMBER; | ||
} | ||
|
||
@Override | ||
public String text() { | ||
return Long.toString(value); | ||
} | ||
|
||
@Override | ||
public int intValue() { | ||
return (int)value; | ||
} | ||
|
||
@Override | ||
public long longValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public double doubleValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public BigDecimal decimalValue() { | ||
return BigDecimal.valueOf(value); | ||
} | ||
|
||
@Override | ||
public Number numberValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void toJson(JsonWriter writer) { | ||
writer.value(value); | ||
} | ||
} |
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,26 @@ | ||
package io.avaje.json.node; | ||
|
||
public interface JsonNode { | ||
|
||
/** | ||
* Return the type of the node. | ||
*/ | ||
Type type(); | ||
|
||
String text(); | ||
|
||
/** | ||
* The types for JsonNode. | ||
*/ | ||
enum Type { | ||
NULL, | ||
ARRAY, | ||
OBJECT, | ||
BOOLEAN, | ||
STRING, | ||
NUMBER, | ||
// BINARY, | ||
// MISSING, | ||
// POJO | ||
} | ||
} |
Oops, something went wrong.