Class TreeData
java.lang.Object
org.apache.commons.configuration2.tree.AbstractImmutableNodeHandler
org.apache.commons.configuration2.tree.TreeData
- All Implemented Interfaces:
NodeHandler<ImmutableNode>
,ReferenceNodeHandler
An internally used helper class for storing information about the managed node structure. An instance of this class
represents the current tree. It stores the current root node and additional information which is not part of the
ImmutableNode
class.- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<ImmutableNode,
ImmutableNode> An inverse replacement mapping.private final NodeTracker
The node tracker.private final Map<ImmutableNode,
ImmutableNode> A map that associates the parent node to each node.private final ReferenceTracker
The reference tracker.private final Map<ImmutableNode,
ImmutableNode> Stores information about nodes which have been replaced by manipulations of the structure.private final ImmutableNode
The root node of the tree. -
Constructor Summary
ConstructorsConstructorDescriptionTreeData
(ImmutableNode root, Map<ImmutableNode, ImmutableNode> parentMapping, Map<ImmutableNode, ImmutableNode> replacements, NodeTracker tracker, ReferenceTracker refTracker) Creates a new instance ofTreeData
and initializes it with all data to be stored. -
Method Summary
Modifier and TypeMethodDescriptionReturns a copy of the mapping from nodes to their parents.Returns a copy of the map storing the replaced nodes.private Map<ImmutableNode,
ImmutableNode> createInverseMapping
(Map<ImmutableNode, ImmutableNode> replacements) Creates the inverse replacement mapping.Gets theNodeTracker
getParent
(ImmutableNode node) Gets the parent node of the specified node.getReference
(ImmutableNode node) Gets the reference object associated with the specified node.Gets theReferenceTracker
.Gets the root node of the underlying hierarchy.private static ImmutableNode
handleReplacements
(ImmutableNode replace, Map<ImmutableNode, ImmutableNode> mapping) Checks whether the passed in node is subject of a replacement by another one.Returns a list with the reference objects for nodes which have been removed.updateNodeTracker
(NodeTracker newTracker) Creates a new instance which uses the specifiedNodeTracker
.updateReferenceTracker
(ReferenceTracker newTracker) Creates a new instance which uses the specifiedReferenceTracker
.Methods inherited from class org.apache.commons.configuration2.tree.AbstractImmutableNodeHandler
checkIfNodeDefined, getAttributes, getAttributeValue, getChild, getChildren, getChildren, getChildrenCount, getMatchingChildren, getMatchingChildrenCount, getValue, hasAttributes, indexOfChild, isDefined, nodeName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.configuration2.tree.NodeHandler
getAttributes, getAttributeValue, getChild, getChildren, getChildren, getChildrenCount, getMatchingChildren, getMatchingChildrenCount, getValue, hasAttributes, indexOfChild, isDefined, nodeName
-
Field Details
-
root
The root node of the tree. -
parentMapping
A map that associates the parent node to each node. -
replacementMapping
Stores information about nodes which have been replaced by manipulations of the structure. This map is used to avoid that the parent mapping has to be updated after each change. -
inverseReplacementMapping
An inverse replacement mapping. -
nodeTracker
The node tracker. -
referenceTracker
The reference tracker.
-
-
Constructor Details
-
TreeData
public TreeData(ImmutableNode root, Map<ImmutableNode, ImmutableNode> parentMapping, Map<ImmutableNode, ImmutableNode> replacements, NodeTracker tracker, ReferenceTracker refTracker) Creates a new instance ofTreeData
and initializes it with all data to be stored.- Parameters:
root
- the root node of the current treeparentMapping
- the mapping to parent nodesreplacements
- the map with the nodes that have been replacedtracker
- theNodeTracker
refTracker
- theReferenceTracker
-
-
Method Details
-
getRootNode
Description copied from interface:NodeHandler
Gets the root node of the underlying hierarchy.- Specified by:
getRootNode
in interfaceNodeHandler<ImmutableNode>
- Returns:
- the current root node
-
getNodeTracker
Gets theNodeTracker
- Returns:
- the
NodeTracker
-
getReferenceTracker
Gets theReferenceTracker
.- Returns:
- the
ReferenceTracker
-
getParent
Gets the parent node of the specified node. Result is null for the root node. If the passed in node cannot be resolved, an exception is thrown.- Specified by:
getParent
in interfaceNodeHandler<ImmutableNode>
- Parameters:
node
- the node in question- Returns:
- the parent node for this node
- Throws:
IllegalArgumentException
- if the node cannot be resolved
-
copyParentMapping
Returns a copy of the mapping from nodes to their parents.- Returns:
- the copy of the parent mapping
-
copyReplacementMapping
Returns a copy of the map storing the replaced nodes.- Returns:
- the copy of the replacement mapping
-
updateNodeTracker
Creates a new instance which uses the specifiedNodeTracker
. This method is called when there are updates of the state of tracked nodes.- Parameters:
newTracker
- the newNodeTracker
- Returns:
- the updated instance
-
updateReferenceTracker
Creates a new instance which uses the specifiedReferenceTracker
. All other information are unchanged. This method is called when there updates for references.- Parameters:
newTracker
- the newReferenceTracker
- Returns:
- the updated instance
-
getReference
Gets the reference object associated with the specified node. If no reference data is associated with this node, result is null. This implementation delegates to the reference tracker.- Specified by:
getReference
in interfaceReferenceNodeHandler
- Parameters:
node
- the node in question- Returns:
- the reference object for this node or null
-
removedReferences
Returns a list with the reference objects for nodes which have been removed. Whenever a node associated with a reference object is removed from the nodes structure managed by the owning model, the reference object is recorded. This is necessary for instance to free some resources. With this method all recorded reference objects can be queried. They are typically returned in the order in which they have been removed. This implementation delegates to the reference tracker.- Specified by:
removedReferences
in interfaceReferenceNodeHandler
- Returns:
- a list with reference objects for nodes removed from the model
-
handleReplacements
private static ImmutableNode handleReplacements(ImmutableNode replace, Map<ImmutableNode, ImmutableNode> mapping) Checks whether the passed in node is subject of a replacement by another one. If so, the other node is returned. This is done until a node is found which had not been replaced. Updating the parent mapping may be expensive for large node structures. Therefore, it initially remains constant, and a map with replacements is used. When querying a parent node, the replacement map has to be consulted whether the parent node is still valid.- Parameters:
replace
- the replacement nodemapping
- the replacement mapping- Returns:
- the corresponding node according to the mapping
-
createInverseMapping
private Map<ImmutableNode,ImmutableNode> createInverseMapping(Map<ImmutableNode, ImmutableNode> replacements) Creates the inverse replacement mapping.- Parameters:
replacements
- the original replacement mapping- Returns:
- the inverse replacement mapping
-