Class ReferenceTracker
A class which allows an InMemoryNodeModel
to associate arbitrary objects with nodes.
Some special configuration implementations need additional data to be stored with their nodes structure. We call such data "references" because objects required by a configuration are referenced. In such constellations, it is necessary to keep track about the nodes associated with references even if they are replaced by others during an update operation of the model. This is the task of this class.
Basically, an instance manages a map associating nodes with reference objects. When a node is replaced the map gets
updated. References becoming orphans because the nodes pointing to them were removed are tracked, too. They may be of
importance for special configuration implementations as they might require additional updates. A concrete use case
for this class is XMLConfiguration
which stores the DOM nodes represented by configuration nodes as
references.
Implementation note: This class is intended to work in a concurrent environment. Instances are immutable. The represented state can be updated by creating new instances which are then stored by the owning node model.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<ImmutableNode,
Object> A map with reference data.A list with the removed references. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new instance ofReferenceTracker
.private
ReferenceTracker
(Map<ImmutableNode, Object> refs, List<Object> removedRefs) Creates a new instance ofReferenceTracker
and sets the data to be managed. -
Method Summary
Modifier and TypeMethodDescriptionaddReferences
(Map<ImmutableNode, ?> refs) Adds all references stored in the passed in map to the managed references.getReference
(ImmutableNode node) Gets the reference object associated with the given node.Gets the list with removed references.updateReferences
(Map<ImmutableNode, ImmutableNode> replacedNodes, Collection<ImmutableNode> removedNodes) Updates the references managed by this object at the end of a model transaction.
-
Field Details
-
references
A map with reference data. -
removedReferences
A list with the removed references.
-
-
Constructor Details
-
ReferenceTracker
Creates a new instance ofReferenceTracker
and sets the data to be managed. This constructor is used internally when references are updated.- Parameters:
refs
- the referencesremovedRefs
- the removed references
-
ReferenceTracker
public ReferenceTracker()Creates a new instance ofReferenceTracker
. This instance does not yet contain any data about references.
-
-
Method Details
-
addReferences
Adds all references stored in the passed in map to the managed references. A new instance is created managing this new set of references.- Parameters:
refs
- the references to be added- Returns:
- the new instance
-
updateReferences
public ReferenceTracker updateReferences(Map<ImmutableNode, ImmutableNode> replacedNodes, Collection<ImmutableNode> removedNodes) Updates the references managed by this object at the end of a model transaction. This method is called by the transaction with the nodes that have been replaced by others and the nodes that have been removed. The internal data structures are updated correspondingly.- Parameters:
replacedNodes
- the map with nodes that have been replacedremovedNodes
- the list with nodes that have been removed- Returns:
- the new instance
-
getReference
Gets the reference object associated with the given node.- Parameters:
node
- the node- Returns:
- the reference object for this node or null
-
getRemovedReferences
Gets the list with removed references. This list is immutable.- Returns:
- the list with removed references
-