Class TreeData

    • 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 of TreeData and initializes it with all data to be stored.
        Parameters:
        root - the root node of the current tree
        parentMapping - the mapping to parent nodes
        replacements - the map with the nodes that have been replaced
        tracker - the NodeTracker
        refTracker - the ReferenceTracker
    • 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 node
        mapping - 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 the NodeTracker
        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 interface NodeHandler<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 interface ReferenceNodeHandler
        Parameters:
        node - the node in question
        Returns:
        the reference object for this node or null
      • getReferenceTracker

        public ReferenceTracker getReferenceTracker()
        Gets the ReferenceTracker.
        Returns:
        the ReferenceTracker
      • 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 interface ReferenceNodeHandler
        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 specified NodeTracker. This method is called when there are updates of the state of tracked nodes.
        Parameters:
        newTracker - the new NodeTracker
        Returns:
        the updated instance
      • updateReferenceTracker

        public TreeData updateReferenceTracker​(ReferenceTracker newTracker)
        Creates a new instance which uses the specified ReferenceTracker. All other information are unchanged. This method is called when there updates for references.
        Parameters:
        newTracker - the new ReferenceTracker
        Returns:
        the updated instance