Class TreeData
- java.lang.Object
-
- org.apache.commons.configuration2.tree.AbstractImmutableNodeHandler
-
- org.apache.commons.configuration2.tree.TreeData
-
- All Implemented Interfaces:
NodeHandler<ImmutableNode>
,ReferenceNodeHandler
final class TreeData extends AbstractImmutableNodeHandler implements 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 theImmutableNode
class.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<ImmutableNode,ImmutableNode>
inverseReplacementMapping
An inverse replacement mapping.private NodeTracker
nodeTracker
The node tracker.private java.util.Map<ImmutableNode,ImmutableNode>
parentMapping
A map that associates the parent node to each node.private ReferenceTracker
referenceTracker
The reference tracker.private java.util.Map<ImmutableNode,ImmutableNode>
replacementMapping
Stores information about nodes which have been replaced by manipulations of the structure.private ImmutableNode
root
The root node of the tree.
-
Constructor Summary
Constructors Constructor Description TreeData(ImmutableNode root, java.util.Map<ImmutableNode,ImmutableNode> parentMapping, java.util.Map<ImmutableNode,ImmutableNode> replacements, NodeTracker tracker, ReferenceTracker refTracker)
Creates a new instance ofTreeData
and initializes it with all data to be stored.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<ImmutableNode,ImmutableNode>
copyParentMapping()
Returns a copy of the mapping from nodes to their parents.java.util.Map<ImmutableNode,ImmutableNode>
copyReplacementMapping()
Returns a copy of the map storing the replaced nodes.private java.util.Map<ImmutableNode,ImmutableNode>
createInverseMapping(java.util.Map<ImmutableNode,ImmutableNode> replacements)
Creates the inverse replacement mapping.NodeTracker
getNodeTracker()
Gets theNodeTracker
ImmutableNode
getParent(ImmutableNode node)
Gets the parent node of the specified node.java.lang.Object
getReference(ImmutableNode node)
Gets the reference object associated with the specified node.ReferenceTracker
getReferenceTracker()
Gets theReferenceTracker
.ImmutableNode
getRootNode()
Gets the root node of the underlying hierarchy.private static ImmutableNode
handleReplacements(ImmutableNode replace, java.util.Map<ImmutableNode,ImmutableNode> mapping)
Checks whether the passed in node is subject of a replacement by another one.java.util.List<java.lang.Object>
removedReferences()
Returns a list with the reference objects for nodes which have been removed.TreeData
updateNodeTracker(NodeTracker newTracker)
Creates a new instance which uses the specifiedNodeTracker
.TreeData
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 Detail
-
root
private final ImmutableNode root
The root node of the tree.
-
parentMapping
private final java.util.Map<ImmutableNode,ImmutableNode> parentMapping
A map that associates the parent node to each node.
-
replacementMapping
private final java.util.Map<ImmutableNode,ImmutableNode> 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
private final java.util.Map<ImmutableNode,ImmutableNode> inverseReplacementMapping
An inverse replacement mapping.
-
nodeTracker
private final NodeTracker nodeTracker
The node tracker.
-
referenceTracker
private final ReferenceTracker referenceTracker
The reference tracker.
-
-
Constructor Detail
-
TreeData
public TreeData(ImmutableNode root, java.util.Map<ImmutableNode,ImmutableNode> parentMapping, java.util.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 Detail
-
handleReplacements
private static ImmutableNode handleReplacements(ImmutableNode replace, java.util.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
-
copyParentMapping
public java.util.Map<ImmutableNode,ImmutableNode> copyParentMapping()
Returns a copy of the mapping from nodes to their parents.- Returns:
- the copy of the parent mapping
-
copyReplacementMapping
public java.util.Map<ImmutableNode,ImmutableNode> copyReplacementMapping()
Returns a copy of the map storing the replaced nodes.- Returns:
- the copy of the replacement mapping
-
createInverseMapping
private java.util.Map<ImmutableNode,ImmutableNode> createInverseMapping(java.util.Map<ImmutableNode,ImmutableNode> replacements)
Creates the inverse replacement mapping.- Parameters:
replacements
- the original replacement mapping- Returns:
- the inverse replacement mapping
-
getNodeTracker
public NodeTracker getNodeTracker()
Gets theNodeTracker
- Returns:
- the
NodeTracker
-
getParent
public ImmutableNode getParent(ImmutableNode node)
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:
java.lang.IllegalArgumentException
- if the node cannot be resolved
-
getReference
public java.lang.Object getReference(ImmutableNode node)
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
-
getReferenceTracker
public ReferenceTracker getReferenceTracker()
Gets theReferenceTracker
.- Returns:
- the
ReferenceTracker
-
getRootNode
public ImmutableNode 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
-
removedReferences
public java.util.List<java.lang.Object> 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
-
updateNodeTracker
public TreeData updateNodeTracker(NodeTracker newTracker)
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
public TreeData updateReferenceTracker(ReferenceTracker newTracker)
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
-
-