public class Node extends Object implements Iterable<Node>
A tree repesentation of a datastore Entity object.
A node can have a map, a list, or a property value. However, these are not exclusive; because of the entity storage structure a node can have a map and a property value at the same place. Lists, however, stand alone.
Here is an example of a set of entity properties:
This produces a tree that looks like:
root { field1: { field2: "foo" + { field3: "bar" } } }
Note that collection values are stored in their own property value nodes. For example:
Becomes this (note that each value in the collection is a node):
root { field1: [ { "foo" }, { "bar" } } }
This is roughly similar to Jackson's JsonNode. One major difference is that there is not a class hierarchy of node types; this is because nodes can actually switch types during tree reprocessing.
Modifier and Type | Method and Description |
---|---|
Node |
addToList()
Creates a new node at same path, adds it to the list, and returns it
|
void |
addToList(Node node)
Adds a node to the list
|
void |
addToMap(Node node)
Adds a node to the map, keyed by its path segment
|
boolean |
containsKey(String key)
Checks to see of the map contains the key
|
Node |
get(int index)
Gets the node at the index of the list, assuming this is a list node
|
Node |
get(String key)
Gets key on a map node
|
Path |
getPath()
Gets the path to this node
|
Object |
getPropertyValue() |
boolean |
hasList() |
boolean |
hasMap() |
boolean |
hasPropertyValue() |
boolean |
isEmpty()
Test for empty of any node type
|
boolean |
isPropertyIndexed() |
Iterator<Node> |
iterator()
Iterate over the values in either the map or list, whichever is appropriate
|
static Node |
of(Object value)
Create a simple unindexed property value node with a root (basically meaningless) path
|
Node |
path(int index)
Gets the node at the index of the list, making sure that a node exists there.
|
Node |
path(String key)
Gets the node with the specified key in the map, making sure that a node exists there.
|
void |
put(String key,
Node value)
Puts a value on a map node
|
Node |
remove(String key)
Removes from map node
|
void |
setList(List<Node> newNodes)
Changes any kind of node into a list node with the new contents
|
void |
setPropertyIndexed(boolean value) |
void |
setPropertyValue(Object value) |
void |
setPropertyValue(Object value,
boolean index) |
int |
size() |
String |
toString() |
public Node(Path path)
public boolean hasPropertyValue()
public Object getPropertyValue()
public void setPropertyValue(Object value)
public void setPropertyValue(Object value, boolean index)
public boolean isPropertyIndexed()
public void setPropertyIndexed(boolean value)
public Path getPath()
public boolean hasList()
public boolean hasMap()
public int size()
public boolean isEmpty()
public void setList(List<Node> newNodes)
public Iterator<Node> iterator()
public Node addToList()
public void addToList(Node node)
public void addToMap(Node node)
public Node path(int index)
public Node path(String key)
public Node get(int index)
public boolean containsKey(String key)
Copyright © 2014. All rights reserved.