Class InMemoryNodeModel

java.lang.Object
org.apache.commons.configuration2.tree.InMemoryNodeModel
All Implemented Interfaces:
NodeModel<ImmutableNode>

public class InMemoryNodeModel extends Object implements NodeModel<ImmutableNode>

A specialized node model implementation which operates on ImmutableNode structures.

This NodeModel implementation keeps all its data as a tree of ImmutableNode objects in memory. The managed structure can be manipulated in a thread-safe, non-blocking way. This is achieved by using atomic variables: The root of the tree is stored in an atomic reference variable. Each update operation causes a new structure to be constructed (which reuses as much from the original structure as possible). The old root node is then replaced by the new one using an atomic compare-and-set operation. If this fails, the manipulation has to be done anew on the updated structure.

Since:
2.0
  • Field Details

    • DUMMY_HANDLER

      private static final NodeHandler<ImmutableNode> DUMMY_HANDLER
      A dummy node handler instance used in operations which require only a limited functionality.
    • structure

      private final AtomicReference<TreeData> structure
      Stores information about the current nodes structure.
  • Constructor Details

    • InMemoryNodeModel

      public InMemoryNodeModel()
      Creates a new instance of InMemoryNodeModel which is initialized with an empty root node.
    • InMemoryNodeModel

      public InMemoryNodeModel(ImmutableNode root)
      Creates a new instance of InMemoryNodeModel and initializes it from the given root node. If the passed in node is null, a new, empty root node is created.
      Parameters:
      root - the new root node for this model
  • Method Details

    • getRootNode

      public ImmutableNode getRootNode()
      Gets the root node of this mode. Note: This method should be used with care. The model may be updated concurrently which causes the root node to be replaced. If the root node is to be processed further (e.g. by executing queries on it), the model should be asked for its NodeHandler, and the root node should be obtained from there. The connection between a node handler and its root node remain constant because an update of the model causes the whole node handler to be replaced.
      Returns:
      the current root node
    • getNodeHandler

      public NodeHandler<ImmutableNode> getNodeHandler()
      Gets a NodeHandler for dealing with the nodes managed by this model. InMemoryNodeModel implements the NodeHandler interface itself. So this implementation just returns the this reference.
      Specified by:
      getNodeHandler in interface NodeModel<ImmutableNode>
      Returns:
      the NodeHandler
    • addProperty

      public void addProperty(String key, Iterable<?> values, NodeKeyResolver<ImmutableNode> resolver)
      Description copied from interface: NodeModel
      Adds a new property to this node model consisting of an arbitrary number of values. The key for the add operation is provided. For each value a new node has to be added. The passed in resolver is queried for a NodeAddData object defining the add operation to be performed.
      Specified by:
      addProperty in interface NodeModel<ImmutableNode>
      Parameters:
      key - the key
      values - the values to be added at the position defined by the key
      resolver - the NodeKeyResolver
    • addProperty

      public void addProperty(String key, NodeSelector selector, Iterable<?> values, NodeKeyResolver<ImmutableNode> resolver)
      Adds new property values using a tracked node as root node. This method works like the normal addProperty() method, but the origin of the operation (also for the interpretation of the passed in key) is a tracked node identified by the passed in NodeSelector. The selector can be null, then the root node is assumed.
      Parameters:
      key - the key
      selector - the NodeSelector defining the root node (or null)
      values - the values to be added
      resolver - the NodeKeyResolver
      Throws:
      ConfigurationRuntimeException - if the selector cannot be resolved
    • addNodes

      public void addNodes(String key, Collection<? extends ImmutableNode> nodes, NodeKeyResolver<ImmutableNode> resolver)
      Description copied from interface: NodeModel
      Adds a collection of new nodes to this model. This operation corresponds to the addNodes() method of the HierarchicalConfiguration interface. The new nodes are either added to an existing node (if the passed in key selects exactly one node) or to a newly created node. The passed in NodeKeyResolver is used to interpret the given key.
      Specified by:
      addNodes in interface NodeModel<ImmutableNode>
      Parameters:
      key - the key
      nodes - the collection of nodes to be added (may be null)
      resolver - the NodeKeyResolver
    • addNodes

      public void addNodes(String key, NodeSelector selector, Collection<? extends ImmutableNode> nodes, NodeKeyResolver<ImmutableNode> resolver)
      Adds new nodes using a tracked node as root node. This method works like the normal addNodes() method, but the origin of the operation (also for the interpretation of the passed in key) is a tracked node identified by the passed in NodeSelector. The selector can be null, then the root node is assumed.
      Parameters:
      key - the key
      selector - the NodeSelector defining the root node (or null)
      nodes - the collection of new nodes to be added
      resolver - the NodeKeyResolver
      Throws:
      ConfigurationRuntimeException - if the selector cannot be resolved
    • setProperty

      public void setProperty(String key, Object value, NodeKeyResolver<ImmutableNode> resolver)
      Description copied from interface: NodeModel
      Changes the value of a property. This is a more complex operation as it might involve adding, updating, or deleting nodes and attributes from the model. The object representing the new value is passed to the NodeKeyResolver which will produce a corresponding NodeUpdateData object. Based on the content of this object, update operations are performed.
      Specified by:
      setProperty in interface NodeModel<ImmutableNode>
      Parameters:
      key - the key
      value - the new value for this property (to be evaluated by the NodeKeyResolver)
      resolver - the NodeKeyResolver
    • setProperty

      public void setProperty(String key, NodeSelector selector, Object value, NodeKeyResolver<ImmutableNode> resolver)
      Sets the value of a property using a tracked node as root node. This method works like the normal setProperty() method, but the origin of the operation (also for the interpretation of the passed in key) is a tracked node identified by the passed in NodeSelector. The selector can be null, then the root node is assumed.
      Parameters:
      key - the key
      selector - the NodeSelector defining the root node (or null)
      value - the new value for this property
      resolver - the NodeKeyResolver
      Throws:
      ConfigurationRuntimeException - if the selector cannot be resolved
    • clearTree

      public List<QueryResult<ImmutableNode>> clearTree(String key, NodeKeyResolver<ImmutableNode> resolver)
      Removes the sub trees defined by the given key from this model. All nodes selected by this key are retrieved from the specified NodeKeyResolver and removed from the model. This implementation checks whether nodes become undefined after subtrees have been removed. If this is the case, such nodes are removed, too. Return value is a collection with QueryResult objects for the elements to be removed from the model.
      Specified by:
      clearTree in interface NodeModel<ImmutableNode>
      Parameters:
      key - the key selecting the properties to be removed
      resolver - the NodeKeyResolver
      Returns:
      an object with information about the data removed
    • clearTree

      public List<QueryResult<ImmutableNode>> clearTree(String key, NodeSelector selector, NodeKeyResolver<ImmutableNode> resolver)
      Clears a whole sub tree using a tracked node as root node. This method works like the normal clearTree() method, but the origin of the operation (also for the interpretation of the passed in key) is a tracked node identified by the passed in NodeSelector. The selector can be null, then the root node is assumed.
      Parameters:
      key - the key
      selector - the NodeSelector defining the root node (or null)
      resolver - the NodeKeyResolver
      Returns:
      a list with the results to be removed
      Throws:
      ConfigurationRuntimeException - if the selector cannot be resolved
    • clearProperty

      public void clearProperty(String key, NodeKeyResolver<ImmutableNode> resolver)
      Clears the value of a property. This method is similar to NodeModel.clearTree(String, NodeKeyResolver): However, the nodes referenced by the passed in key are not removed completely, but only their value is set to null. If this operation leaves an affected node in an undefined state, it is removed from the model.
      Specified by:
      clearProperty in interface NodeModel<ImmutableNode>
      Parameters:
      key - the key selecting the properties to be cleared
      resolver - the NodeKeyResolver
    • clearProperty

      public void clearProperty(String key, NodeSelector selector, NodeKeyResolver<ImmutableNode> resolver)
      Clears a property using a tracked node as root node. This method works like the normal clearProperty() method, but the origin of the operation (also for the interpretation of the passed in key) is a tracked node identified by the passed in NodeSelector. The selector can be null, then the root node is assumed.
      Parameters:
      key - the key
      selector - the NodeSelector defining the root node (or null)
      resolver - the NodeKeyResolver
      Throws:
      ConfigurationRuntimeException - if the selector cannot be resolved
    • clear

      public void clear(NodeKeyResolver<ImmutableNode> resolver)
      Removes all data from this model. A new empty root node is created with the same name as the current root node. Implementation note: Because this is a hard reset the usual dance for dealing with concurrent updates is not required here.
      Specified by:
      clear in interface NodeModel<ImmutableNode>
      Parameters:
      resolver - the NodeKeyResolver
    • getInMemoryRepresentation

      public ImmutableNode getInMemoryRepresentation()
      Gets a representation of the data stored in this model in form of a nodes hierarchy of ImmutableNode objects. A concrete model implementation can use an arbitrary means to store its data. When a model's data is to be used together with other functionality of the Configuration library (e.g. when combining multiple configuration sources) it has to be transformed into a common format. This is done by this method. ImmutableNode is a generic representation of a hierarchical structure. Thus, it should be possible to generate a corresponding structure from arbitrary model data. This implementation simply returns the current root node of this model.
      Specified by:
      getInMemoryRepresentation in interface NodeModel<ImmutableNode>
      Returns:
      the root node of an in-memory hierarchy representing the data stored in this model
    • setRootNode

      public void setRootNode(ImmutableNode newRoot)
      Sets a new root node for this model. The whole structure is replaced by the new node and its children. All tracked nodes and reference objects managed by this model are cleared.Care has to be taken when this method is used and the model is accessed by multiple threads. It is not deterministic which concurrent operations see the old root and which see the new root node.
      Specified by:
      setRootNode in interface NodeModel<ImmutableNode>
      Parameters:
      newRoot - the new root node to be set (can be null, then an empty root node is set)
    • replaceRoot

      public void replaceRoot(ImmutableNode newRoot, NodeKeyResolver<ImmutableNode> resolver)
      Replaces the root node of this model. This method is similar to setRootNode(ImmutableNode); however, tracked nodes will not get lost. The model applies the selectors of all tracked nodes on the new nodes hierarchy, so that corresponding nodes are selected (this may cause nodes to become detached if a select operation fails). This operation is useful if the new nodes hierarchy to be set is known to be similar to the old one. Note that reference objects are lost; there is no way to automatically match nodes between the old and the new nodes hierarchy.
      Parameters:
      newRoot - the new root node to be set (must not be null)
      resolver - the NodeKeyResolver
      Throws:
      IllegalArgumentException - if the new root node is null
    • mergeRoot

      public void mergeRoot(ImmutableNode node, String rootName, Map<ImmutableNode,?> references, Object rootRef, NodeKeyResolver<ImmutableNode> resolver)
      Merges the root node of this model with the specified node. This method is typically caused by configuration implementations when a configuration source is loaded, and its data has to be added to the model. It is possible to define the new name of the root node and to pass in a map with reference objects.
      Parameters:
      node - the node to be merged with the root node
      rootName - the new name of the root node; can be null, then the name of the root node is not changed unless it is null
      references - an optional map with reference objects
      rootRef - an optional reference object for the new root node
      resolver - the NodeKeyResolver
    • trackNode

      public void trackNode(NodeSelector selector, NodeKeyResolver<ImmutableNode> resolver)
      Adds a node to be tracked. After this method has been called with a specific NodeSelector, the node associated with this key can be always obtained using getTrackedNode(NodeSelector) with the same selector. This is useful because during updates of a model parts of the structure are replaced. Therefore, it is not a good idea to simply hold a reference to a node; this might become outdated soon. Rather, the node should be tracked. This mechanism ensures that always the correct node reference can be obtained.
      Parameters:
      selector - the NodeSelector defining the desired node
      resolver - the NodeKeyResolver
      Throws:
      ConfigurationRuntimeException - if the selector does not select a single node
    • selectAndTrackNodes

      public Collection<NodeSelector> selectAndTrackNodes(String key, NodeKeyResolver<ImmutableNode> resolver)
      Allows tracking all nodes selected by a key. This method evaluates the specified key on the current nodes structure. For all selected nodes corresponding NodeSelector objects are created, and they are tracked. The returned collection of NodeSelector objects can be used for interacting with the selected nodes.
      Parameters:
      key - the key for selecting the nodes to track
      resolver - the NodeKeyResolver
      Returns:
      a collection with the NodeSelector objects for the new tracked nodes
    • trackChildNodes

      public Collection<NodeSelector> trackChildNodes(String key, NodeKeyResolver<ImmutableNode> resolver)
      Tracks all nodes which are children of the node selected by the passed in key. If the key selects exactly one node, for all children of this node NodeSelector objects are created, and they become tracked nodes. The returned collection of NodeSelector objects can be used for interacting with the selected nodes.
      Parameters:
      key - the key for selecting the parent node whose children are to be tracked
      resolver - the NodeKeyResolver
      Returns:
      a collection with the NodeSelector objects for the new tracked nodes
    • trackChildNodeWithCreation

      public NodeSelector trackChildNodeWithCreation(String key, String childName, NodeKeyResolver<ImmutableNode> resolver)
      Tracks a node which is a child of another node selected by the passed in key. If the selected node has a child node with this name, it is tracked and its selector is returned. Otherwise, a new child node with this name is created first.
      Parameters:
      key - the key for selecting the parent node
      childName - the name of the child node
      resolver - the NodeKeyResolver
      Returns:
      the NodeSelector for the tracked child node
      Throws:
      ConfigurationRuntimeException - if the passed in key does not select a single node
    • getTrackedNode

      public ImmutableNode getTrackedNode(NodeSelector selector)
      Gets the current ImmutableNode instance associated with the given NodeSelector. The node must be a tracked node, i.e. trackNode(NodeSelector, NodeKeyResolver) must have been called before with the given selector.
      Parameters:
      selector - the NodeSelector defining the desired node
      Returns:
      the current ImmutableNode associated with this selector
      Throws:
      ConfigurationRuntimeException - if the selector is unknown
    • replaceTrackedNode

      public void replaceTrackedNode(NodeSelector selector, ImmutableNode newNode)
      Replaces a tracked node by another node. If the tracked node is not yet detached, it becomes now detached. The passed in node (which must not be null) becomes the new root node of an independent model for this tracked node. Further updates of this model do not affect the tracked node's model and vice versa.
      Parameters:
      selector - the NodeSelector defining the tracked node
      newNode - the node replacing the tracked node (must not be null)
      Throws:
      ConfigurationRuntimeException - if the selector cannot be resolved
      IllegalArgumentException - if the replacement node is null
    • getTrackedNodeHandler

      public NodeHandler<ImmutableNode> getTrackedNodeHandler(NodeSelector selector)
      Gets a NodeHandler for a tracked node. Such a handler may be required for operations on a sub tree of the model. The handler to be returned depends on the current state of the tracked node. If it is still active, a handler is used which shares some data (especially the parent mapping) with this model. Detached track nodes in contrast have their own separate model; in this case a handler associated with this model is returned.
      Parameters:
      selector - the NodeSelector defining the tracked node
      Returns:
      a NodeHandler for this tracked node
      Throws:
      ConfigurationRuntimeException - if the selector is unknown
    • isTrackedNodeDetached

      public boolean isTrackedNodeDetached(NodeSelector selector)
      Returns a flag whether the specified tracked node is detached. As long as the NodeSelector associated with that node returns a single instance, the tracked node is said to be life. If now an update of the model happens which invalidates the selector (maybe the target node was removed), the tracked node becomes detached. It is still possible to query the node; here the latest valid instance is returned. But further changes on the node model are no longer tracked for this node. So even if there are further changes which would make the NodeSelector valid again, the tracked node stays in detached state.
      Parameters:
      selector - the NodeSelector defining the desired node
      Returns:
      a flag whether this tracked node is in detached state
      Throws:
      ConfigurationRuntimeException - if the selector is unknown
    • untrackNode

      public void untrackNode(NodeSelector selector)
      Removes a tracked node. This method is the opposite of trackNode(). It has to be called if there is no longer the need to track a specific node. Note that for each call of trackNode() there has to be a corresponding untrackNode() call. This ensures that multiple observers can track the same node.
      Parameters:
      selector - the NodeSelector defining the desired node
      Throws:
      ConfigurationRuntimeException - if the specified node is not tracked
    • getReferenceNodeHandler

      public ReferenceNodeHandler getReferenceNodeHandler()
      Gets a ReferenceNodeHandler object for this model. This extended node handler can be used to query references objects stored for this model.
      Returns:
      the ReferenceNodeHandler
    • getTreeData

      TreeData getTreeData()
      Gets the current TreeData object. This object contains all information about the current node structure.
      Returns:
      the current TreeData object
    • updateParentMapping

      static void updateParentMapping(Map<ImmutableNode,ImmutableNode> parents, ImmutableNode root)
      Updates the mapping from nodes to their parents for the passed in hierarchy of nodes. This method traverses all children and grand-children of the passed in root node. For each node in the subtree the parent relation is added to the map.
      Parameters:
      parents - the map with parent nodes
      root - the root node of the current tree
    • checkIfNodeDefined

      static boolean checkIfNodeDefined(ImmutableNode node)
      Checks if the passed in node is defined. Result is true if the node contains any data.
      Parameters:
      node - the node in question
      Returns:
      true if the node is defined, false otherwise
    • initializeAddTransaction

      private void initializeAddTransaction(ModelTransaction tx, String key, Iterable<?> values, NodeKeyResolver<ImmutableNode> resolver)
      Initializes a transaction for an add operation.
      Parameters:
      tx - the transaction to be initialized
      key - the key
      values - the collection with node values
      resolver - the NodeKeyResolver
    • createTreeData

      private TreeData createTreeData(ImmutableNode root, TreeData current)
      Creates a TreeData object for the specified root node.
      Parameters:
      root - the root node of the current tree
      current - the current TreeData object (may be null)
      Returns:
      the TreeData describing the current tree
    • createTreeDataForRootAndTracker

      private TreeData createTreeDataForRootAndTracker(ImmutableNode root, NodeTracker newTracker)
      Creates a TreeData object for the specified root node and NodeTracker. Other parameters are set to default values.
      Parameters:
      root - the new root node for this model
      newTracker - the new NodeTracker
      Returns:
      the new TreeData object
    • addNodeProperty

      private static void addNodeProperty(ModelTransaction tx, NodeAddData<ImmutableNode> addData, Iterable<?> values)
      Handles an add property operation if the property to be added is a node.
      Parameters:
      tx - the transaction
      addData - the NodeAddData
      values - the collection with node values
    • addNodesByAddData

      private static void addNodesByAddData(ModelTransaction tx, NodeAddData<ImmutableNode> addData, Collection<ImmutableNode> newNodes)
      Initializes a transaction to add a collection of nodes as described by a NodeAddData object. If necessary, new path nodes are created. Eventually, the new nodes are added as children to the specified target node.
      Parameters:
      tx - the transaction
      addData - the NodeAddData
      newNodes - the collection of new child nodes
    • addAttributeProperty

      private static void addAttributeProperty(ModelTransaction tx, NodeAddData<ImmutableNode> addData, Iterable<?> values)
      Handles an add property operation if the property to be added is an attribute.
      Parameters:
      tx - the transaction
      addData - the NodeAddData
      values - the collection with node values
    • createNodesToAdd

      private static Collection<ImmutableNode> createNodesToAdd(String newNodeName, Iterable<?> values)
      Creates a collection with new nodes with a given name and a value from a given collection.
      Parameters:
      newNodeName - the name of the new nodes
      values - the collection with node values
      Returns:
      the newly created collection
    • createNodeToAddWithPath

      private static ImmutableNode createNodeToAddWithPath(NodeAddData<ImmutableNode> addData, Collection<ImmutableNode> newNodes)
      Creates a node structure consisting of the path nodes defined by the passed in NodeAddData instance and all new child nodes.
      Parameters:
      addData - the NodeAddData
      newNodes - the collection of new child nodes
      Returns:
      the parent node of the newly created hierarchy
    • createNodeOnPath

      private static ImmutableNode createNodeOnPath(Iterator<String> it, Collection<ImmutableNode> newNodes)
      Recursive helper method for creating a path node for an add operation. All path nodes except for the last have a single child. The last path node has the new nodes as children.
      Parameters:
      it - the iterator over the names of the path nodes
      newNodes - the collection of new child nodes
      Returns:
      the newly created path node
    • initializeClearTransaction

      private static boolean initializeClearTransaction(ModelTransaction tx, Collection<QueryResult<ImmutableNode>> results)
      Initializes a transaction to clear the values of a property based on the passed in collection of affected results.
      Parameters:
      tx - the transaction to be initialized
      results - a collection with results pointing to the nodes to be cleared
      Returns:
      a flag whether there are elements to be cleared
    • initializeUpdateTransaction

      private static boolean initializeUpdateTransaction(ModelTransaction tx, Map<QueryResult<ImmutableNode>,Object> changedValues)
      Initializes a transaction to change the values of some query results based on the passed in map.
      Parameters:
      tx - the transaction to be initialized
      changedValues - the map defining the elements to be changed
      Returns:
      a flag whether there are elements to be updated
    • initialRootNode

      private static ImmutableNode initialRootNode(ImmutableNode providedRoot)
      Determines the initial root node of this model. If a root node has been provided, it is used. Otherwise, an empty dummy root node is created.
      Parameters:
      providedRoot - the passed in root node
      Returns:
      the root node to be used
    • determineRootName

      private static String determineRootName(ImmutableNode rootNode, ImmutableNode node, String rootName)
      Determines the name of the root node for a merge operation. If a root name is provided, it is used. Otherwise, if the current root node has no name, the name of the node to be merged is used. A result of null means that no node name has to be set.
      Parameters:
      rootNode - the current root node
      node - the node to be merged with the root node
      rootName - the name of the resulting node
      Returns:
      the new name of the root node
    • createParentMapping

      private Map<ImmutableNode,ImmutableNode> createParentMapping(ImmutableNode root)
      Creates the mapping to parent nodes for the nodes structured represented by the passed in root node. Each node is assigned its parent node. Here an iterative algorithm is used rather than a recursive one to avoid stack overflow for huge structures.
      Parameters:
      root - the root node of the structure
      Returns:
      the parent node mapping
    • updateModel

      private void updateModel(InMemoryNodeModel.TransactionInitializer txInit, NodeSelector selector, NodeKeyResolver<ImmutableNode> resolver)
      Performs a non-blocking, thread-safe update of this model based on a transaction initialized by the passed in initializer. This method uses the atomic reference for the model's current data to ensure that an update was successful even if the model is concurrently accessed.
      Parameters:
      txInit - the TransactionInitializer
      selector - an optional NodeSelector defining the target node of the transaction
      resolver - the NodeKeyResolver
    • executeTransactionOnCurrentStructure

      private boolean executeTransactionOnCurrentStructure(InMemoryNodeModel.TransactionInitializer txInit, NodeSelector selector, TreeData currentData, NodeKeyResolver<ImmutableNode> resolver)
      Executes a transaction on the current data of this model. This method is called if an operation is to be executed on the model's root node or a tracked node which is not yet detached.
      Parameters:
      txInit - the TransactionInitializer
      selector - an optional NodeSelector defining the target node
      currentData - the current data of the model
      resolver - the NodeKeyResolver
      Returns:
      a flag whether the operation has been completed successfully
    • executeTransactionOnDetachedTrackedNode

      private boolean executeTransactionOnDetachedTrackedNode(InMemoryNodeModel.TransactionInitializer txInit, NodeSelector selector, TreeData currentData, NodeKeyResolver<ImmutableNode> resolver)
      Tries to execute a transaction on the model of a detached tracked node. This method checks whether the target node of the transaction is a tracked node and if this node is already detached. If this is the case, the update operation is independent on this model and has to be executed on the specific model for the detached node.
      Parameters:
      txInit - the TransactionInitializer
      selector - an optional NodeSelector defining the target node
      currentData - the current data of the model
      resolver - the NodeKeyResolver @return a flag whether the transaction could be executed
      Throws:
      ConfigurationRuntimeException - if the selector cannot be resolved
    • replaceDetachedTrackedNode

      private boolean replaceDetachedTrackedNode(TreeData currentData, NodeSelector selector, ImmutableNode newNode)
      Replaces a tracked node if it is already detached.
      Parameters:
      currentData - the current data of the model
      selector - the NodeSelector defining the tracked node
      newNode - the node replacing the tracked node
      Returns:
      a flag whether the operation was successful
    • replaceActiveTrackedNode

      private boolean replaceActiveTrackedNode(TreeData currentData, NodeSelector selector, ImmutableNode newNode)
      Replaces an active tracked node. The node then becomes detached.
      Parameters:
      currentData - the current data of the model
      selector - the NodeSelector defining the tracked node
      newNode - the node replacing the tracked node
      Returns:
      a flag whether the operation was successful
    • createSelectorsForTrackedNodes

      private static TreeData createSelectorsForTrackedNodes(org.apache.commons.lang3.mutable.Mutable<Collection<NodeSelector>> refSelectors, List<ImmutableNode> nodes, TreeData current, NodeKeyResolver<ImmutableNode> resolver)
      Creates tracked node entries for the specified nodes and creates the corresponding selectors.
      Parameters:
      refSelectors - the reference where to store the selectors
      nodes - the nodes to be tracked
      current - the current TreeData object
      resolver - the NodeKeyResolver
      Returns:
      the updated TreeData object
    • updateDataWithNewTrackedNode

      private static TreeData updateDataWithNewTrackedNode(TreeData current, ImmutableNode node, NodeKeyResolver<ImmutableNode> resolver, org.apache.commons.lang3.mutable.MutableObject<NodeSelector> refSelector)
      Adds a tracked node that has already been resolved to the specified data object.
      Parameters:
      current - the current TreeData object
      node - the node in question
      resolver - the NodeKeyResolver
      refSelector - here the newly created NodeSelector is returned
      Returns:
      the new TreeData instance
    • createDataWithTrackedChildNode

      private static TreeData createDataWithTrackedChildNode(TreeData current, ImmutableNode parent, String childName, NodeKeyResolver<ImmutableNode> resolver, org.apache.commons.lang3.mutable.MutableObject<NodeSelector> refSelector)
      Creates a new data object with a tracked child node of the given parent node. If such a child node already exists, it is used. Otherwise, a new one is created.
      Parameters:
      current - the current TreeData object
      parent - the parent node
      childName - the name of the child node
      resolver - the NodeKeyResolver
      refSelector - here the newly created NodeSelector is returned
      Returns:
      the new TreeData instance
    • valuesNotEmpty

      private static boolean valuesNotEmpty(Iterable<?> values)
      Checks whether the specified collection with values is not empty.
      Parameters:
      values - the collection with node values
      Returns:
      true if values are provided, false otherwise
    • attributeKeyException

      private static IllegalArgumentException attributeKeyException(String key)
      Creates an exception referring to an invalid key for adding properties. Such an exception is thrown when an operation tries to add something to an attribute.
      Parameters:
      key - the invalid key causing this exception
      Returns:
      the exception