public interface DataTree
Given the following example data:
{
"some-object": {
"some-nested-object": {
"a-string": "some special string",
"a-boolean": true,
"some-numbers": [4, 5, 7]
}
}
}
Various elements could be parsed as:
DataTree.from(root).resolve("some-object", "some-nested-object", "some-numbers", 2).asInt()
would result in the value 5.DataTree.from(root).resolve("some-object", "some-nested-object").map(Map.Entry::getKey).toArray(String[]::new)
would result in ["a-string", "a-boolean", "some-numbers"]Methods always return a value, throwing an exception if a value isn't present or appropriate.
| Modifier and Type | Method and Description |
|---|---|
Stream<? extends DataTree> |
asArray()
Gets a stream of the member nodes, as if this tree was a
JsonArray. |
boolean |
asBoolean()
Returns a
Boolean representation of this node. |
double |
asDouble()
Returns a
Double representation of this node. |
Stream<? extends Map.Entry<Integer,? extends DataTree>> |
asIndexedArray()
Gets an indexed stream of the member nodes, as if this tree was a
JsonArray. |
int |
asInt()
Returns an
Integer representation of this node. |
Number |
asNumber()
Returns a
Number representation of this node. |
Stream<? extends Map.Entry<String,? extends DataTree>> |
asObject()
Gets a stream of the member nodes, as if this tree was a
JsonObject. |
String |
asString()
Returns a
String representation of this node. |
static ConfigurateDataTree |
from(ninja.leaping.configurate.ConfigurationNode node)
Creates a new
DataTree from a ConfigurationNode. |
static GsonDataTree |
from(com.google.gson.JsonElement element)
Creates a new
DataTree from a JsonElement. |
DataTree |
resolve(Object... path)
Resolves the given path.
|
@Nonnull static GsonDataTree from(@Nonnull com.google.gson.JsonElement element)
DataTree from a JsonElement.element - the element@Nonnull static ConfigurateDataTree from(@Nonnull ninja.leaping.configurate.ConfigurationNode node)
DataTree from a ConfigurationNode.node - the node@Nonnull DataTree resolve(@Nonnull Object... path)
Paths can be made up of String or Integer components. Strings are used to
resolve a member of an object, and integers resolve a member of an array.
path - the path@Nonnull Stream<? extends Map.Entry<String,? extends DataTree>> asObject()
JsonObject.@Nonnull Stream<? extends DataTree> asArray()
JsonArray.@Nonnull Stream<? extends Map.Entry<Integer,? extends DataTree>> asIndexedArray()
JsonArray.@Nonnull String asString()
String representation of this node.@Nonnull Number asNumber()
Number representation of this node.int asInt()
Integer representation of this node.double asDouble()
Double representation of this node.boolean asBoolean()
Boolean representation of this node.Copyright © 2022. All rights reserved.