java.lang.Object
com.yahoo.documentapi.messagebus.systemstate.rule.NodeState

public class NodeState extends Object
Author:
Simon Thoresen Hult
  • Field Details

    • NODE_PARENT

      public static final String NODE_PARENT
      A location string that expresses the use of the PARENT node.
      See Also:
    • NODE_CURRENT

      public static final String NODE_CURRENT
      A location string that expresses the use of THIS node.
      See Also:
  • Constructor Details

    • NodeState

      public NodeState()
      Creates a node state that no internal content.
    • NodeState

      public NodeState(List<Argument> args)
      Creates a node state based on a list of argument objects. These arguments are iterated and added to this node's internal state map.
      Parameters:
      args - The arguments to use as state.
  • Method Details

    • 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object