Package com.apicatalog.tree.io
Class TreeIO
java.lang.Object
com.apicatalog.tree.io.TreeIO
Immutable representation of a tree node where the node and its descendants
are accessed through a
TreeAdapter.
A TreeIO instance binds a node with its adapter, providing a uniform
way to traverse or compare trees of arbitrary underlying object models.
Pass a TreeIO from JSON, YAML, or CBOR into the tree to create
polyformic tree composed of various different serializations, libraries, in
order to uniformly prosses such a tree.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTreeIO(Object node, TreeAdapter adapter) Creates a new immutable tree with the given root node and adapter. -
Method Summary
Modifier and TypeMethodDescriptionadapter()static Comparator<Object>comparingElement(Function<Object, Comparable> keyExtractor) static Comparator<Map.Entry<?,?>> comparingEntry(Function<Map.Entry<?, ?>, Comparable> keyExtractor) static Comparator<?>comparingNode(Function<Object, Comparable> keyExtractor) static Comparator<Map.Entry<?,?>> comparingStringKeys(TreeAdapter adapter) static final booleandeepEquals(TreeIO left, TreeIO right) static final booleandeepEquals(Object left, TreeAdapter leftAdapter, Object right, TreeAdapter rightAdapter) protected static booleandeepEqualsCollection(Iterable<? extends Object> left, TreeAdapter leftAdapter, Iterable<? extends Object> right, TreeAdapter rightAdapter) booleanstatic final booleanisCollection(TreeIO node) booleanstatic final booleanisEmptyOrNull(TreeIO node) booleanisMap()static final booleanbooleanbooleanisSingleElement(TreeIO node) booleanbooleanisSingleEntry(TreeIO node) Collection<?>keys()Stream<?>node()Root node, can be scalar or a structure like Map or Collection.static final ObjectMap.Entry<?,?> voidtraverse(TreeGenerator generator) voidtraverse(Consumer<TreeTraversal> visitor) type()static final NodeType
-
Field Details
-
adapter
-
node
-
-
Constructor Details
-
TreeIO
Creates a new immutable tree with the given root node and adapter.- Parameters:
node- the root node of the tree, must not benulladapter- the adapter providing access to node types and values, must not benull- Throws:
NullPointerException- ifrootoradapterisnull
-
-
Method Details
-
adapter
-
node
Root node, can be scalar or a structure like Map or Collection.- Returns:
-
traverse
-
traverse
- Throws:
TreeIOException
-
deepEquals
-
deepEquals
public static final boolean deepEquals(Object left, TreeAdapter leftAdapter, Object right, TreeAdapter rightAdapter) -
deepEqualsCollection
protected static boolean deepEqualsCollection(Iterable<? extends Object> left, TreeAdapter leftAdapter, Iterable<? extends Object> right, TreeAdapter rightAdapter) -
comparingEntry
public static Comparator<Map.Entry<?,?>> comparingEntry(Function<Map.Entry<?, ?>, Comparable> keyExtractor) -
comparingNode
-
comparingStringKeys
-
comparingElement
-
isEmptyOrNull
public boolean isEmptyOrNull() -
isEmptyOrNull
-
isMap
public boolean isMap() -
isMap
-
property
-
property
-
isCollection
public boolean isCollection() -
isCollection
-
type
-
type
-
isSingleElement
public boolean isSingleElement() -
isSingleElement
-
singleElement
-
keys
-
isSingleEntry
public boolean isSingleEntry() -
isSingleEntry
-
singleEntry
-
keyStream
-