A class which can track specific nodes in an {@link InMemoryNodeModel}.
Sometimes it is necessary to keep track on a specific node, for instance when operating on a subtree of a model. For a model comprised of immutable nodes this is not trivial because each update of the model may cause the node to be replaced. So holding a direct pointer onto the target node is not an option; this instance may become outdated.
This class provides an API for selecting a specific node by using a {@link NodeSelector}. The selector is used to obtain an initial reference to the target node. It is then applied again after each update of the associated node model (which is done in the {@code update()} method). At this point oftime two things can happen:
- The {@code NodeSelector} associated with the tracked node still selects asingle node. Then this node becomes the new tracked node. This may be the same instance as before or a new one.
- The selector does no longer find the target node. This can happen for instance if it has been removed by an operation. In this case, the previous node instance is used. It is now detached from the model, but can still be used for operations on this subtree. It may even become life again after another update of the model.
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.
@version $Id: NodeTracker.java 1624601 2014-09-12 18:04:36Z oheger $
@since 2.0