Class NodeState
- java.lang.Object
-
- com.yahoo.documentapi.messagebus.systemstate.rule.NodeState
-
public class NodeState extends Object
- Author:
- Simon Thoresen Hult
-
-
Field Summary
Fields Modifier and Type Field Description static String
NODE_CURRENT
A location string that expresses the use of THIS node.static String
NODE_PARENT
A location string that expresses the use of the PARENT node.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NodeState
addChild(String key, NodeState child)
Adds a child to this node at the given location.NodeState
clear()
Clears both the internal state and child list, then compacts the tree from this node upwards.NodeState
copy(NodeState node)
Copies the state content of another node state object into this.NodeState
getChild(String key)
Returns the child at the given location relative to this.NodeState
getChild(String key, boolean force)
Returns the child at the given location relative to this.Map<String,NodeState>
getChildren()
Returns the map of child nodes for iteration.String
getState(String key)
Retrieves some arbitrary state information for a given key.NodeState
removeChild(String key)
Removes the named child node from this node, and attempts to compact the system state from this node upwards by removing empty nodes.NodeState
removeState(String key)
Removes the named (key, value) state pair from this node, and attempts to compact the system state from this node upwards by removing empty nodes.NodeState
setParent(NodeState parent, String id)
Sets the parent of this node.NodeState
setState(String key, String value)
Sets some arbitrary state data in this node.String
toString()
-
-
-
Field Detail
-
NODE_PARENT
public static final String NODE_PARENT
A location string that expresses the use of the PARENT node.- See Also:
- Constant Field Values
-
NODE_CURRENT
public static final String NODE_CURRENT
A location string that expresses the use of THIS node.- See Also:
- Constant Field Values
-
-
Method Detail
-
addChild
public NodeState addChild(String key, NodeState child)
Adds a child to this node at the given location. The key can be a location string, in which case the necessary intermediate node states are created.- Parameters:
key
- The location at which to add the child.child
- The child node to add.- Returns:
- This, to allow chaining.
-
getChild
public NodeState getChild(String key)
Returns the child at the given location relative to this.- Parameters:
key
- The location of the child to return.- Returns:
- The child object, null if not found.
-
getChild
public NodeState getChild(String key, boolean force)
Returns the child at the given location relative to this. This method can be forced to return a child node even if it does not exist, by adding all intermediate nodes and the target node itself.- Parameters:
key
- The location of the child to return.force
- Whether or not to force a return value by creating missing nodes.- Returns:
- The child object, null if not found.
-
getChildren
public Map<String,NodeState> getChildren()
Returns the map of child nodes for iteration.- Returns:
- The internal child map.
-
removeChild
public NodeState removeChild(String key)
Removes the named child node from this node, and attempts to compact the system state from this node upwards by removing empty nodes.- Parameters:
key
- The child to remove.- Returns:
- The result of invoking
compact()
after the remove.
-
getState
public String getState(String key)
Retrieves some arbitrary state information for a given key. The key can be a location string, in which case the necessary intermediate nodes are traversed. If the key is not found, this method returns null.- Parameters:
key
- The name of the state information to return.- Returns:
- The value of the state key.
-
setState
public NodeState setState(String key, String value)
Sets some arbitrary state data in this node. The key can be a location string, in which case the necessary intermediate nodes are traversed and even created if missing.- Parameters:
key
- The key to set.value
- The value to assign to the key.- Returns:
- This, to allow chaining.
-
removeState
public NodeState removeState(String key)
Removes the named (key, value) state pair from this node, and attempts to compact the system state from this node upwards by removing empty nodes.- Parameters:
key
- The state variable to clear.- Returns:
- The result of invoking
compact()
after the remove.
-
copy
public NodeState copy(NodeState node)
Copies the state content of another node state object into this.- Parameters:
node
- The node state to copy into this.- Returns:
- This, to allow chaining.
-
clear
public NodeState clear()
Clears both the internal state and child list, then compacts the tree from this node upwards.- Returns:
- The result of invoking
compact()
after the remove.
-
setParent
public NodeState setParent(NodeState parent, String id)
Sets the parent of this node.- Parameters:
parent
- The parent node.id
- The identifier of this node as seen in the parent.- Returns:
- This, to allow chaining.
-
-