Module gen.tree

Class ITreeNodeHandlerExtensions

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <V,​T extends ITreeNode<V,​T>>
      void
      accept​(T treeNode, @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)
      Accepts the given visitor that provides a custom algorithm for processing all elements
      static <V,​T extends ITreeNode<V,​T>>
      void
      accept​(T treeNode, @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor, boolean visitBefore)
      Accepts the given visitor that provides a custom algorithm for processing all elements
      static <V,​T extends ITreeNode<V,​T>>
      void
      addChild​(T parentTreeNode, T child)
      Adds the given child ITreeNode object to the first given parent ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      void
      addChildren​(T parentTreeNode, @NonNull java.util.Collection<T> children)
      Adds all the given children from the first given parent ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      void
      clearAll​(T treeNode)
      Removes all the descendants from the given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      void
      clearChildren​(T treeNode)
      Removes all the children from the given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      contains​(T treeNode, T descendantCandidate)
      Checks if the second given ITreeNode object is a descendant of the first given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      containsAll​(T treeNode, @NonNull java.util.Collection<T> treeNodes)
      Checks if the given Collection object of ITreeNode objects are descendants of the first given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      java.util.Collection<T>
      findAllByValue​(T treeNode, V value)
      Find all ITreeNode objects from the first given ITreeNode object that serves as the search target, that have the same value as the given value
      static <V,​T extends ITreeNode<V,​T>>
      T
      findByValue​(T treeNode, V value)
      Find the first occurrence of ITreeNode object from the first given ITreeNode object that serves as the search target, that have the same value as the given value
      static <V,​T extends ITreeNode<V,​T>>
      java.util.Collection<T>
      getAllSiblings​(T treeNode)
      Returns all siblings of the given ITreeNode object in the parent's children list
      static <V,​T extends ITreeNode<V,​T>>
      int
      getChildCount​(T treeNode)
      Gets the child count from the given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      int
      getLevel​(T treeNode)
      Returns the distance from the root to the given ITreeNode object.
      static <V,​T extends ITreeNode<V,​T>>
      T
      getNextSibling​(T currentTreeNode)
      Returns the next sibling of the given ITreeNode object in the parent's children list.
      static <V,​T extends ITreeNode<V,​T>>
      T
      getPreviousSibling​(T currentTreeNode)
      Returns the previous sibling of the given ITreeNode object in the parent's children list.
      static <V,​T extends ITreeNode<V,​T>>
      T
      getRoot​(T treeNode)
      Gets the root from the given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      hasChildren​(T treeNode)
      Checks if the given ITreeNode object has children
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      hasParent​(T treeNode)
      Checks if the given ITreeNode object has a parent ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      isChildOf​(T parentTreeNode, T child)
      Checks if the second given ITreeNode object is a child of the first ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      isNode​(T treeNode)
      Checks if the given ITreeNode object is a node
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      isParentOf​(T parentTreeNode, T child)
      Checks if the first given ITreeNode object is the parent of the second ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      boolean
      isRoot​(T treeNode)
      Checks if the given ITreeNode is the root ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      void
      removeChild​(T parentTreeNode, T child)
      Removes the given child from the given first ITreeNode
      static <V,​T extends ITreeNode<V,​T>>
      void
      removeChildren​(T parentTreeNode)
      Removes all children from the given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      void
      removeChildren​(T parentTreeNode, @NonNull java.util.Collection<T> children)
      Removes all the given children from the first given ITreeNode object
      static <V,​T extends ITreeNode<V,​T>>
      java.util.List<T>
      toList​(T treeNode)
      Traverse the given ITreeNode object and adds all descendant with it self-included in to a List object
      static <V,​T extends ITreeNode<V,​T>>
      java.util.Collection<T>
      traverse​(T treeNode)
      Traverse the given ITreeNode object and add all descendants with the given ITreeNode object included in to the returned Collection object
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ITreeNodeHandlerExtensions

        public ITreeNodeHandlerExtensions()
    • Method Detail

      • getAllSiblings

        public static <V,​T extends ITreeNode<V,​T>> java.util.Collection<T> getAllSiblings​(@NonNull
                                                                                                      T treeNode)
        Returns all siblings of the given ITreeNode object in the parent's children list
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        Returns all siblings of the given ITreeNode object
      • getRoot

        public static <V,​T extends ITreeNode<V,​T>> T getRoot​(@NonNull
                                                                         T treeNode)
        Gets the root from the given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        the root from the given ITreeNode object
      • getNextSibling

        public static <V,​T extends ITreeNode<V,​T>> T getNextSibling​(@NonNull
                                                                                T currentTreeNode)
        Returns the next sibling of the given ITreeNode object in the parent's children list. Returns null if the given ITreeNode object is the root or is the parent's last child
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        currentTreeNode - the tree node
        Returns:
        the next sibling of the given ITreeNode object or null if the given ITreeNode object is the root or is the parent's last child
      • getPreviousSibling

        public static <V,​T extends ITreeNode<V,​T>> T getPreviousSibling​(@NonNull
                                                                                    T currentTreeNode)
        Returns the previous sibling of the given ITreeNode object in the parent's children list. Returns null if the given ITreeNode object is the root or is the parent's first child.
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        currentTreeNode - the tree node
        Returns:
        the next sibling of the given ITreeNode object or null if the given ITreeNode object is the root or is the parent's last child.
      • getLevel

        public static <V,​T extends ITreeNode<V,​T>> int getLevel​(@NonNull
                                                                            T treeNode)
        Returns the distance from the root to the given ITreeNode object. Returns 0 if the given ITreeNode object is the root ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        the level from the given ITreeNode object
      • removeChild

        public static <V,​T extends ITreeNode<V,​T>> void removeChild​(@NonNull
                                                                                T parentTreeNode,
                                                                                T child)
        Removes the given child from the given first ITreeNode
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        parentTreeNode - the parent tree node
        child - the child tree node
      • isChildOf

        public static <V,​T extends ITreeNode<V,​T>> boolean isChildOf​(@NonNull
                                                                                 T parentTreeNode,
                                                                                 @NonNull
                                                                                 T child)
        Checks if the second given ITreeNode object is a child of the first ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        parentTreeNode - the parent tree node
        child - the child
        Returns:
        true, if the second given ITreeNode object is a child of the first ITreeNode object otherwise false
      • isParentOf

        public static <V,​T extends ITreeNode<V,​T>> boolean isParentOf​(@NonNull
                                                                                  T parentTreeNode,
                                                                                  @NonNull
                                                                                  T child)
        Checks if the first given ITreeNode object is the parent of the second ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        parentTreeNode - the parent tree node
        child - the child
        Returns:
        true, if the first given ITreeNode object is the parent of the second given ITreeNode object otherwise false
      • removeChildren

        public static <V,​T extends ITreeNode<V,​T>> void removeChildren​(@NonNull
                                                                                   T parentTreeNode,
                                                                                   @NonNull
                                                                                   @NonNull java.util.Collection<T> children)
        Removes all the given children from the first given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        parentTreeNode - the parent tree node
        children - the children to remove
      • removeChildren

        public static <V,​T extends ITreeNode<V,​T>> void removeChildren​(@NonNull
                                                                                   T parentTreeNode)
        Removes all children from the given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        parentTreeNode - the parent tree node
      • isRoot

        public static <V,​T extends ITreeNode<V,​T>> boolean isRoot​(@NonNull
                                                                              T treeNode)
        Checks if the given ITreeNode is the root ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        true, if the given ITreeNode is the root ITreeNode object
      • hasParent

        public static <V,​T extends ITreeNode<V,​T>> boolean hasParent​(@NonNull
                                                                                 T treeNode)
        Checks if the given ITreeNode object has a parent ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        true, if the given ITreeNode object has a parent ITreeNode object otherwise false
      • isNode

        public static <V,​T extends ITreeNode<V,​T>> boolean isNode​(@NonNull
                                                                              T treeNode)
        Checks if the given ITreeNode object is a node
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        true, if the given ITreeNode object is a node otherwise false
      • clearAll

        public static <V,​T extends ITreeNode<V,​T>> void clearAll​(@NonNull
                                                                             T treeNode)
        Removes all the descendants from the given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
      • clearChildren

        public static <V,​T extends ITreeNode<V,​T>> void clearChildren​(@NonNull
                                                                                  T treeNode)
        Removes all the children from the given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
      • addChild

        public static <V,​T extends ITreeNode<V,​T>> void addChild​(@NonNull
                                                                             T parentTreeNode,
                                                                             T child)
        Adds the given child ITreeNode object to the first given parent ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        parentTreeNode - the parent tree node
        child - the child
      • addChildren

        public static <V,​T extends ITreeNode<V,​T>> void addChildren​(@NonNull
                                                                                T parentTreeNode,
                                                                                @NonNull
                                                                                @NonNull java.util.Collection<T> children)
        Adds all the given children from the first given parent ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        parentTreeNode - the parent tree node
        children - the children to add
      • getChildCount

        public static <V,​T extends ITreeNode<V,​T>> int getChildCount​(@NonNull
                                                                                 T treeNode)
        Gets the child count from the given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        the child count
      • hasChildren

        public static <V,​T extends ITreeNode<V,​T>> boolean hasChildren​(@NonNull
                                                                                   T treeNode)
        Checks if the given ITreeNode object has children
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        true, if the given ITreeNode object has children otherwise false
      • traverse

        public static <V,​T extends ITreeNode<V,​T>> java.util.Collection<T> traverse​(@NonNull
                                                                                                T treeNode)
        Traverse the given ITreeNode object and add all descendants with the given ITreeNode object included in to the returned Collection object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        a Collection object with the given ITreeNode object and add all descendants
      • accept

        public static <V,​T extends ITreeNode<V,​T>> void accept​(@NonNull
                                                                           T treeNode,
                                                                           @NonNull
                                                                           @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)
        Accepts the given visitor that provides a custom algorithm for processing all elements
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        visitor - the visitor
      • accept

        public static <V,​T extends ITreeNode<V,​T>> void accept​(@NonNull
                                                                           T treeNode,
                                                                           @NonNull
                                                                           @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor,
                                                                           boolean visitBefore)
        Accepts the given visitor that provides a custom algorithm for processing all elements
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        visitor - the visitor
        visitBefore - the flag if this flag is true the visit of the given ITreeNode object is before visit the children otherwise the visit is after visit the children
      • findAllByValue

        public static <V,​T extends ITreeNode<V,​T>> java.util.Collection<T> findAllByValue​(@NonNull
                                                                                                      T treeNode,
                                                                                                      V value)
        Find all ITreeNode objects from the first given ITreeNode object that serves as the search target, that have the same value as the given value
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        value - the value for the search process
        Returns:
        a Collection object with all found occurrences that have the same value as the given value
      • findByValue

        public static <V,​T extends ITreeNode<V,​T>> T findByValue​(@NonNull
                                                                             T treeNode,
                                                                             V value)
        Find the first occurrence of ITreeNode object from the first given ITreeNode object that serves as the search target, that have the same value as the given value
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        value - the value for the search process
        Returns:
        the first occurrence of ITreeNode object that have the same value as the given value
      • contains

        public static <V,​T extends ITreeNode<V,​T>> boolean contains​(@NonNull
                                                                                T treeNode,
                                                                                T descendantCandidate)
        Checks if the second given ITreeNode object is a descendant of the first given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        descendantCandidate - the tree node to check
        Returns:
        true if the given ITreeNode object is a descendant of the first given ITreeNode object otherwise false
      • containsAll

        public static <V,​T extends ITreeNode<V,​T>> boolean containsAll​(@NonNull
                                                                                   T treeNode,
                                                                                   @NonNull
                                                                                   @NonNull java.util.Collection<T> treeNodes)
        Checks if the given Collection object of ITreeNode objects are descendants of the first given ITreeNode object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        treeNodes - the collection of the tree nodes to check
        Returns:
        true if the given Collection object of ITreeNode objects are descendants of the first given ITreeNode object otherwise false
      • toList

        public static <V,​T extends ITreeNode<V,​T>> java.util.List<T> toList​(@NonNull
                                                                                        T treeNode)
        Traverse the given ITreeNode object and adds all descendant with it self-included in to a List object
        Type Parameters:
        V - the generic type of the value
        T - the generic type of the id of the node
        Parameters:
        treeNode - the tree node
        Returns:
        a List object with the given ITreeNode object and all descendants