Class EmptyNodeState
- All Implemented Interfaces:
NodeState
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription@NotNull NodeBuilder
builder()
Returns a builder for constructing a new node state based on this state, i.e.boolean
compareAgainstBaseState
(NodeState base, NodeStateDiff diff) Compares this node state against the given base state.static boolean
compareAgainstEmptyState
(NodeState state, NodeStateDiff diff) boolean
boolean
exists()
Checks whether this node exists.boolean
getBoolean
(@NotNull String name) Returns the boolean value of the named property.@NotNull NodeState
getChildNode
(@NotNull String name) Returns the named, possibly non-existent, child node.long
getChildNodeCount
(long max) Returns the number of iterable child nodes of this node.@NotNull Iterable<? extends ChildNodeEntry>
Returns the iterable child node entries of this instance.Returns the names of all iterable child nodes.long
Returns the long value of the named property.@Nullable String
Returns the name value of the named property.Returns the name values of the named property.@NotNull Iterable<? extends PropertyState>
Returns an iterable of the properties of this node.@Nullable PropertyState
getProperty
(@NotNull String name) Returns the named property, ornull
if no such property exists.long
Returns the number of properties of this node.Returns the string value of the named property.getStrings
(@NotNull String name) Returns the string values of the named property.boolean
hasChildNode
(@NotNull String name) Checks whether the named child node exists.int
hashCode()
boolean
hasProperty
(@NotNull String name) Checks whether the named property exists.static boolean
isEmptyState
(NodeState state) toString()
-
Field Details
-
EMPTY_NODE
-
MISSING_NODE
-
-
Method Details
-
exists
public boolean exists()Description copied from interface:NodeState
Checks whether this node exists. See the above discussion about the existence of node states. -
getPropertyCount
public long getPropertyCount()Description copied from interface:NodeState
Returns the number of properties of this node.- Specified by:
getPropertyCount
in interfaceNodeState
- Returns:
- number of properties
-
hasProperty
Description copied from interface:NodeState
Checks whether the named property exists. The implementation is equivalent togetProperty(name) != null
, but may be optimized to avoid having to load the property value.- Specified by:
hasProperty
in interfaceNodeState
- Parameters:
name
- property name- Returns:
true
if the named property exists,false
otherwise
-
getProperty
Description copied from interface:NodeState
Returns the named property, ornull
if no such property exists.- Specified by:
getProperty
in interfaceNodeState
- Parameters:
name
- name of the property to return- Returns:
- named property, or
null
if not found
-
getBoolean
Description copied from interface:NodeState
Returns the boolean value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); return property != null && property.getType() == Type.BOOLEAN && property.getValue(Type.BOOLEAN);
- Specified by:
getBoolean
in interfaceNodeState
- Parameters:
name
- property name- Returns:
- boolean value of the named property, or
false
-
getLong
Description copied from interface:NodeState
Returns the long value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.LONG) { return property.getValue(Type.LONG); } else { return 0; }
-
getString
Description copied from interface:NodeState
Returns the string value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRING) { return property.getValue(Type.STRING); } else { return null; }
-
getStrings
Description copied from interface:NodeState
Returns the string values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRINGS) { return property.getValue(Type.STRINGS); } else { return Collections.emptyList(); }
- Specified by:
getStrings
in interfaceNodeState
- Parameters:
name
- property name- Returns:
- string values of the named property, or an empty collection
-
getName
Description copied from interface:NodeState
Returns the name value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAME) { return property.getValue(Type.NAME); } else { return null; }
-
getNames
Description copied from interface:NodeState
Returns the name values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAMES) { return property.getValue(Type.NAMES); } else { return Collections.emptyList(); }
-
getProperties
Description copied from interface:NodeState
Returns an iterable of the properties of this node. Multiple iterations are guaranteed to return the properties in the same order, but the specific order used is implementation-dependent and may change across different states of the same node.- Specified by:
getProperties
in interfaceNodeState
- Returns:
- properties in some stable order
-
getChildNodeCount
public long getChildNodeCount(long max) Description copied from interface:NodeState
Returns the number of iterable child nodes of this node.If an implementation knows the exact value, it returns it (even if the value is higher than max). If the implementation does not know the exact value, and the child node count is higher than max, it may return Long.MAX_VALUE. The cost of the operation is at most O(max).
- Specified by:
getChildNodeCount
in interfaceNodeState
- Parameters:
max
- the maximum number of entries to traverse- Returns:
- number of iterable child nodes
-
hasChildNode
Description copied from interface:NodeState
Checks whether the named child node exists. The implementation is equivalent togetChildNode(name).exists()
, except that passing an invalid name as argument will result in afalse
return value instead of anIllegalArgumentException
.- Specified by:
hasChildNode
in interfaceNodeState
- Parameters:
name
- name of the child node- Returns:
true
if the named child node exists,false
otherwise
-
getChildNode
Description copied from interface:NodeState
Returns the named, possibly non-existent, child node. Use theNodeState.exists()
method on the returned child node to determine whether the node exists or not.- Specified by:
getChildNode
in interfaceNodeState
- Parameters:
name
- name of the child node to return- Returns:
- named child node
-
getChildNodeNames
Description copied from interface:NodeState
Returns the names of all iterable child nodes.- Specified by:
getChildNodeNames
in interfaceNodeState
- Returns:
- child node names in some stable order
-
getChildNodeEntries
Description copied from interface:NodeState
Returns the iterable child node entries of this instance. Multiple iterations are guaranteed to return the child nodes in the same order, but the specific order used is implementation dependent and may change across different states of the same node.Note on cost and performance: while it is possible to iterate over all child
NodeState
s with the two methodsNodeState.getChildNodeNames()
andNodeState.getChildNode(String)
, this method is considered more efficient because an implementation can potentially perform the retrieval of the name andNodeState
in one call. This results in O(n) vs. O(n log n) when iterating over the child node names and then look up theNodeState
by name.- Specified by:
getChildNodeEntries
in interfaceNodeState
- Returns:
- child node entries in some stable order
-
builder
Description copied from interface:NodeState
Returns a builder for constructing a new node state based on this state, i.e. starting with all the properties and child nodes of this state. -
compareAgainstBaseState
Description copied from interface:NodeState
Compares this node state against the given base state. Any differences are reported by calling the relevant added/changed/deleted methods of the given handler.TODO: Define the behavior of this method with regards to iterability/existence of child nodes.
- Specified by:
compareAgainstBaseState
in interfaceNodeState
- Parameters:
base
- base statediff
- handler of node state differences- Returns:
true
if the full diff was performed, orfalse
if it was aborted as requested by the handler (see theNodeStateDiff
contract for more details)
-
compareAgainstEmptyState
-
isEmptyState
-
toString
-
equals
-
hashCode
public int hashCode()
-