Class SimpleTreeNodeHandlerExtensions

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

public class SimpleTreeNodeHandlerExtensions extends Object
The class SimpleTreeNodeHandlerExtensions provides handler methods for the class SimpleTreeNode
  • Constructor Details

    • SimpleTreeNodeHandlerExtensions

      public SimpleTreeNodeHandlerExtensions()
  • Method Details

    • getChildren

      public static <T, K> Collection<SimpleTreeNode<T,K>> getChildren(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
      Gets the children from the given SimpleTreeNode object
      Type Parameters:
      T - the generic type of the value
      K - the generic type of the id of the node
      Parameters:
      treeNode - the tree node
      Returns:
      the children from the given SimpleTreeNode object
    • getAllSiblings

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      public static <T, K> void accept(@NonNull @NonNull SimpleTreeNode<T,K> treeNode, @NonNull @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<T,K>> visitor, boolean visitBefore)
      Accepts the given visitor that provides a custom algorithm for processing all elements
      Type Parameters:
      T - the generic type of the value
      K - 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 SimpleTreeNode object is before visit the children otherwise the visit is after visit the children
    • findAllByValue

      public static <T, K> Collection<SimpleTreeNode<T,K>> findAllByValue(@NonNull @NonNull SimpleTreeNode<T,K> treeNode, T value)
      Find all SimpleTreeNode objects from the first given SimpleTreeNode object that serves as the search target, that have the same value as the given value
      Type Parameters:
      T - the generic type of the value
      K - 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 <T, K> SimpleTreeNode<T,K> findByValue(@NonNull @NonNull SimpleTreeNode<T,K> treeNode, T value)
      Find the first occurrence of SimpleTreeNode object from the first given SimpleTreeNode object that serves as the search target, that have the same value as the given value
      Type Parameters:
      T - the generic type of the value
      K - 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 SimpleTreeNode object that have the same value as the given value
    • contains

      public static <T, K> boolean contains(@NonNull @NonNull SimpleTreeNode<T,K> treeNode, SimpleTreeNode<T,K> descendantCandidate)
      Checks if the second given SimpleTreeNode object is a descendant of the first given SimpleTreeNode object
      Type Parameters:
      T - the generic type of the value
      K - 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 SimpleTreeNode object is a descendant of the first given SimpleTreeNode object otherwise false
    • containsAll

      public static <T, K> boolean containsAll(@NonNull @NonNull SimpleTreeNode<T,K> treeNode, @NonNull @NonNull Collection<SimpleTreeNode<T,K>> treeNodes)
      Checks if the given Collection object of SimpleTreeNode objects are descendants of the first given SimpleTreeNode object
      Type Parameters:
      T - the generic type of the value
      K - 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 SimpleTreeNode objects are descendants of the first given SimpleTreeNode object otherwise false
    • toList

      public static <T, K> List<SimpleTreeNode<T,K>> toList(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
      Traverse the given SimpleTreeNode object and adds all descendant with it self-included in to a List object
      Type Parameters:
      T - the generic type of the value
      K - the generic type of the id of the node
      Parameters:
      treeNode - the tree node
      Returns:
      a List object with the given SimpleTreeNode object and all descendants
    • getAllRightSiblings

      public static <T, K> Collection<SimpleTreeNode<T,K>> getAllRightSiblings(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
      Gets all the right siblings from the given SimpleTreeNode object
      Type Parameters:
      T - the generic type of the value
      K - the generic type of the id of the node
      Parameters:
      treeNode - the tree node
      Returns:
      all the right siblings from the given SimpleTreeNode object
    • getAllLeftSiblings

      public static <T, K> Collection<SimpleTreeNode<T,K>> getAllLeftSiblings(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
      Gets all the left siblings from the given SimpleTreeNode object
      Type Parameters:
      T - the generic type of the value
      K - the generic type of the id of the node
      Parameters:
      treeNode - the tree node
      Returns:
      all the left siblings from the given SimpleTreeNode object