Class PathMap.Element<T>

  • Enclosing class:

    public static final class PathMap.Element<T>
    extends Object
    Internal class holding the object associated with a certain path element.
    • Method Detail

      • insert

        public void insert​(Path.Element nameIndex)
        Insert an empty child. Will shift all children having an index greater than or equal to the child inserted to the right.
        nameIndex - position where child is inserted
      • put

        public void put​(Path.Element nameIndex,
                        PathMap.Element<T> element)
        Link a child of this node. Position is given by nameIndex.
        nameIndex - position where child should be located
        element - element to add
      • remove

        public PathMap.Element<T> remove​(Path.Element nameIndex)
        Remove a child. Will shift all children having an index greater than the child removed to the left. If there are no more children left in this element and no object is associated with this element, the element itself gets removed.
        nameIndex - child's path element
        removed child, may be null
      • remove

        public void remove()
        Remove this element. Delegates the call to the parent item. Index of same name siblings will be shifted!
      • remove

        public void remove​(boolean shift)
        Remove this element. Delegates the call to the parent item.
        shift - if index of same name siblings will be shifted.
      • removeAll

        public void removeAll()
        Remove all children of this element. Removes this element itself if this element does not contain associated information.
      • setChildren

        public void setChildren​(Map<Path.Element,​PathMap.Element<T>> children)
        Sets a new list of children of this element.
        children - map of children; keys are of type Path.PathElement and values are of type Element
      • get

        public T get()
        Return the object associated with this element
        object associated with this element
      • set

        public void set​(T obj)
        Set the object associated with this element
        obj - object associated with this element
      • getName

        public Name getName()
        Return the name of this element
      • getIndex

        public int getIndex()
        Return the non-normalized 1-based index of this element. Note that this method can return a value of 0 which should be treated as 1.
        See Also:
      • getNormalizedIndex

        public int getNormalizedIndex()
        Return the 1-based index of this element. Same as getIndex() except that an undefined index value is automatically converted to the default index value.
        1-based index
      • getPathElement

        public Path.Element getPathElement()
        Return a path element pointing to this element
        path element
      • hasPath

        public boolean hasPath​(Path path)
        Checks whether this element has the specified path. Introduced to avoid catching a MalformedPathException for simple path comparisons.
        path - path to compare to
        true if this child has the path path, false otherwise
      • traverse

        public void traverse​(PathMap.ElementVisitor<T> visitor,
                             boolean includeEmpty)
        Recursively invoked traversal method. This method visits the element first, then its children.
        visitor - visitor to invoke
        includeEmpty - if true invoke call back on every element regardless, whether the associated object is empty or not; otherwise call back on non-empty children only
      • getDepth

        public int getDepth()
        Return the depth of this element. Defined to be 0 for the root element and n + 1 for some element if the depth of its parent is n.
      • isAncestorOf

        public boolean isAncestorOf​(PathMap.Element<T> other)
        Return a flag indicating whether the specified node is a child of this node.
        other - node to check
      • getParent

        public PathMap.Element<T> getParent()
        Return the parent of this element
        parent or null if this is the root element
      • getChildrenCount

        public int getChildrenCount()
        Return the children count of this element
        children count
      • getChildren

        public List<PathMap.Element<T>> getChildren()
        Return an iterator over all of this element's children. Every element returned by this iterator is of type PathMap.Element.
      • getDescendant

        public PathMap.Element<T> getDescendant​(Path relPath,
                                                boolean exact)
        Map a relPath starting at this Element. If exact is false, returns the last available item along the relPath that is stored in the map.
        relPath - relPath to map
        exact - flag indicating whether an exact match is required
        descendant, maybe null if exact is true