Class ITreeNodeHandlerExtensions

java.lang.Object
io.github.astrapi69.gen.tree.handler.ITreeNodeHandlerExtensions

public class ITreeNodeHandlerExtensions extends Object
The class ITreeNodeHandlerExtensions provides handler methods for the class ITreeNode
  • Constructor Details

    • ITreeNodeHandlerExtensions

      public ITreeNodeHandlerExtensions()
  • Method Details

    • getAllSiblings

      public static <V, T extends ITreeNode<V, T>> 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 concrete tree 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 concrete tree 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 concrete tree 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 concrete tree 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 concrete tree 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 concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      child - the child tree node
    • removeChild

      public static <V, T extends ITreeNode<V, T>> void removeChild(@NonNull T parentTreeNode, T child, boolean clearChildren)
      Removes the given child from the given first ITreeNode
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      child - the child tree node
      clearChildren - the flag that indicates if the children from the child tree node will be cleared
    • removeFromParent

      public static <V, T extends ITreeNode<V, T>> void removeFromParent(@NonNull T treeNode)
      Removes the parent from the given ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      treeNode - the tree node
    • removeFromParent

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

      public static <V, T extends ITreeNode<V, T>> void removeFromParent(@NonNull T parentTreeNode, @NonNull T child, boolean clearChildren)
      Removes the parent from the given child ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      child - the child
      clearChildren - the flag that indicates if the children from the child tree node will be cleared
    • move

      public static <V, T extends ITreeNode<V, T>> boolean move(@NonNull T treeNodeToMove, T newParentTreeNode)
      Moves the given ITreeNode object to the new given parent ITreeNode object that can be null
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      treeNodeToMove - the tree node that will be moved to the new parent tree node
      newParentTreeNode - the new parent tree node
      Returns:
      true if the given ITreeNode object was moved otherwise false
    • isChild

      public static <V, T extends ITreeNode<V, T>> boolean isChild(@NonNull T parentTreeNode, T child)
      Checks if the second given ITreeNode object is a child of the first given ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      child - the child tree node to check
      Returns:
      true, if the second given ITreeNode object is a child of the first ITreeNode object otherwise false
    • 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 concrete tree 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 concrete tree 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 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 concrete tree 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 concrete tree 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 concrete tree node
      Parameters:
      treeNode - the tree node
      Returns:
      true, if the given ITreeNode is the root ITreeNode object
    • hasNextSibling

      public static <V, T extends ITreeNode<V, T>> boolean hasNextSibling(@NonNull T treeNode)
      Checks if the given ITreeNode object has a next sibling ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      treeNode - the tree node
      Returns:
      true, if the given ITreeNode object has a next sibling ITreeNode object otherwise false
    • 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 concrete tree node
      Parameters:
      treeNode - the tree node
      Returns:
      true, if the given ITreeNode object has a parent ITreeNode object otherwise false
    • hasPreviousSibling

      public static <V, T extends ITreeNode<V, T>> boolean hasPreviousSibling(@NonNull T treeNode)
      Checks if the given ITreeNode object has a previous sibling ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      treeNode - the tree node
      Returns:
      true, if the given ITreeNode object has a previous sibling 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 concrete tree 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 concrete tree 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 concrete tree 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 concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      child - the child
    • addChild

      public static <V, T extends ITreeNode<V, T>> void addChild(@NonNull T parentTreeNode, T child, int index)
      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 concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      child - the child
      index - the index of the child to insert
    • getChildAt

      public static <V, T extends ITreeNode<V, T>> Optional<T> getChildAt(@NonNull T parentTreeNode, int index)
      Gets an Optional object with the child tree node from the given index from the first given parent ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      index - the index of the child to get
      Returns:
      an Optional object with the child tree node
    • getChildIndex

      public static <V, T extends ITreeNode<V, T>> int getChildIndex(@NonNull T parentTreeNode, T child)
      Gets the index of the given child from the given index from the first given parent ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      parentTreeNode - the parent tree node
      child - the child to resolve the index
      Returns:
      the index of the given child in this tree node
    • addChildren

      public static <V, T extends ITreeNode<V, T>> void addChildren(@NonNull T parentTreeNode, @NonNull @NonNull 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 concrete tree 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 concrete tree 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 concrete tree 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>> 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 concrete tree node
      Parameters:
      treeNode - the tree node
      Returns:
      a Collection object with the given ITreeNode object and add all descendants
    • findAllByValue

      public static <V, T extends ITreeNode<V, T>> 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 concrete tree 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 concrete tree 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 concrete tree 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 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 concrete tree 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>> 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 concrete tree node
      Parameters:
      treeNode - the tree node
      Returns:
      a List object with the given ITreeNode object and all descendants
    • findFirstOccurenceOfDescendant

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

      public static <V, T extends ITreeNode<V, T>> boolean isDescendant(@NonNull T treeNode, T possibleDescendant)
      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 concrete tree node
      Parameters:
      treeNode - the tree node to check
      possibleDescendant - the possible descendant tree node to check
      Returns:
      true, if the second given ITreeNode object is a descendant of the first ITreeNode object otherwise false
    • isAncestor

      public static <V, T extends ITreeNode<V, T>> boolean isAncestor(@NonNull T treeNode, @NonNull T possibleAncestor)
      Checks if the second given ITreeNode object is an ancestor of the first given ITreeNode object
      Type Parameters:
      V - the generic type of the value
      T - the generic type of the concrete tree node
      Parameters:
      treeNode - the tree node to check
      possibleAncestor - the possible ancestor tree node to check
      Returns:
      true, if the second given ITreeNode object is a ancestor of the first ITreeNode object otherwise false