Class SimpleTreeNodeHandlerExtensions
java.lang.Object
io.github.astrapi69.gen.tree.handler.SimpleTreeNodeHandlerExtensions
The class
SimpleTreeNodeHandlerExtensions provides handler methods for the class
SimpleTreeNode-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,K> void accept(@NonNull SimpleTreeNode<T, K> treeNode, @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<T, K>> visitor) Accepts the given visitor that provides a custom algorithm for processing all elementsstatic <T,K> void accept(@NonNull SimpleTreeNode<T, K> treeNode, @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 elementsstatic <T,K> void addChild(@NonNull SimpleTreeNode<T, K> parentTreeNode, SimpleTreeNode<T, K> child) Adds the given childSimpleTreeNodeobject to the first given parentSimpleTreeNodeobjectstatic <T,K> void addChildren(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull Collection<SimpleTreeNode<T, K>> children) Adds all the given children from the first given parentSimpleTreeNodeobjectstatic <T,K> void clearAll(@NonNull SimpleTreeNode<T, K> treeNode) Removes all the descendants from the givenSimpleTreeNodeobjectstatic <T,K> void clearChildren(@NonNull SimpleTreeNode<T, K> treeNode) Removes all the children from the givenSimpleTreeNodeobjectstatic <T,K> boolean contains(@NonNull SimpleTreeNode<T, K> treeNode, SimpleTreeNode<T, K> descendantCandidate) Checks if the second givenSimpleTreeNodeobject is a descendant of the first givenSimpleTreeNodeobjectstatic <T,K> boolean containsAll(@NonNull SimpleTreeNode<T, K> treeNode, @NonNull Collection<SimpleTreeNode<T, K>> treeNodes) Checks if the givenCollectionobject ofSimpleTreeNodeobjects are descendants of the first givenSimpleTreeNodeobjectstatic <T,K> Collection<SimpleTreeNode<T, K>> findAllByValue(@NonNull SimpleTreeNode<T, K> treeNode, T value) Find allSimpleTreeNodeobjects from the first givenSimpleTreeNodeobject that serves as the search target, that have the same value as the given valuestatic <T,K> SimpleTreeNode<T, K> findByValue(@NonNull SimpleTreeNode<T, K> treeNode, T value) Find the first occurrence ofSimpleTreeNodeobject from the first givenSimpleTreeNodeobject that serves as the search target, that have the same value as the given valuestatic <T,K> Collection<SimpleTreeNode<T, K>> getAllLeftSiblings(@NonNull SimpleTreeNode<T, K> treeNode) Gets all the left siblings from the givenSimpleTreeNodeobjectstatic <T,K> Collection<SimpleTreeNode<T, K>> getAllRightSiblings(@NonNull SimpleTreeNode<T, K> treeNode) Gets all the right siblings from the givenSimpleTreeNodeobjectstatic <T,K> Collection<SimpleTreeNode<T, K>> getAllSiblings(@NonNull SimpleTreeNode<T, K> treeNode) Returns all siblings of the givenSimpleTreeNodeobject in the parent's children liststatic <T,K> int getChildCount(@NonNull SimpleTreeNode<T, K> treeNode) Gets the child count from the givenSimpleTreeNodeobjectstatic <T,K> Collection<SimpleTreeNode<T, K>> getChildren(@NonNull SimpleTreeNode<T, K> treeNode) Gets the children from the givenSimpleTreeNodeobjectstatic <T,K> int getLevel(@NonNull SimpleTreeNode<T, K> treeNode) Returns the distance from the root to the givenSimpleTreeNodeobject.static <T,K> SimpleTreeNode<T, K> getNextSibling(@NonNull SimpleTreeNode<T, K> currentTreeNode) Returns the next sibling of the givenSimpleTreeNodeobject in the parent's children list.static <T,K> SimpleTreeNode<T, K> getPreviousSibling(@NonNull SimpleTreeNode<T, K> currentTreeNode) Returns the previous sibling of the givenSimpleTreeNodeobject in the parent's children list.static <T,K> SimpleTreeNode<T, K> getRoot(@NonNull SimpleTreeNode<T, K> treeNode) Gets the root from the givenSimpleTreeNodeobjectstatic <T,K> boolean hasChildren(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNodeobject has childrenstatic <T,K> boolean hasParent(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNodeobject has a parentSimpleTreeNodeobjectstatic <T,K> boolean isChildOf(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull SimpleTreeNode<T, K> child) Checks if the second givenSimpleTreeNodeobject is a child of the firstSimpleTreeNodeobjectstatic <T,K> boolean isNode(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNodeobject is a nodestatic <T,K> boolean isParentOf(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull SimpleTreeNode<T, K> child) Checks if the first givenSimpleTreeNodeobject is the parent of the secondSimpleTreeNodeobjectstatic <T,K> boolean isRoot(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNodeis the rootSimpleTreeNodeobjectstatic <T,K> void removeChild(@NonNull SimpleTreeNode<T, K> parentTreeNode, SimpleTreeNode<T, K> child) Removes the given child from the given firstSimpleTreeNodestatic <T,K> void removeChildren(@NonNull SimpleTreeNode<T, K> parentTreeNode) Removes all children from the givenSimpleTreeNodeobjectstatic <T,K> void removeChildren(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull Collection<SimpleTreeNode<T, K>> children) Removes all the given children from the first givenSimpleTreeNodeobjectstatic <T,K> List<SimpleTreeNode<T, K>> toList(@NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNodeobject and adds all descendant with it self-included in to aListobjectstatic <T,K> Collection<SimpleTreeNode<T, K>> traverse(@NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNodeobject and add all descendants with the givenSimpleTreeNodeobject included in to the returnedCollectionobject
-
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 givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- the children from the given
SimpleTreeNodeobject
-
getAllSiblings
public static <T,K> Collection<SimpleTreeNode<T,K>> getAllSiblings(@NonNull @NonNull SimpleTreeNode<T, K> treeNode) Returns all siblings of the givenSimpleTreeNodeobject in the parent's children list- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- Returns all siblings of the given
SimpleTreeNodeobject
-
getRoot
Gets the root from the givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- the root from the given
SimpleTreeNodeobject
-
getNextSibling
public static <T,K> SimpleTreeNode<T,K> getNextSibling(@NonNull @NonNull SimpleTreeNode<T, K> currentTreeNode) Returns the next sibling of the givenSimpleTreeNodeobject in the parent's children list. Returns null if the givenSimpleTreeNodeobject is the root or is the parent's last child- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
currentTreeNode- the tree node- Returns:
- the next sibling of the given
SimpleTreeNodeobject or null if the givenSimpleTreeNodeobject 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 givenSimpleTreeNodeobject in the parent's children list. Returns null if the givenSimpleTreeNodeobject is the root or is the parent's first child.- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
currentTreeNode- the tree node- Returns:
- the next sibling of the given
SimpleTreeNodeobject or null if the givenSimpleTreeNodeobject is the root or is the parent's last child.
-
getLevel
Returns the distance from the root to the givenSimpleTreeNodeobject. Returns 0 if the givenSimpleTreeNodeobject is the rootSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- the level from the given
SimpleTreeNodeobject
-
removeChild
public static <T,K> void removeChild(@NonNull @NonNull SimpleTreeNode<T, K> parentTreeNode, SimpleTreeNode<T, K> child) Removes the given child from the given firstSimpleTreeNode- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
parentTreeNode- the parent tree nodechild- 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 givenSimpleTreeNodeobject is a child of the firstSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
parentTreeNode- the parent tree nodechild- the child- Returns:
- true, if the second given
SimpleTreeNodeobject is a child of the firstSimpleTreeNodeobject 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 givenSimpleTreeNodeobject is the parent of the secondSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
parentTreeNode- the parent tree nodechild- the child- Returns:
- true, if the first given
SimpleTreeNodeobject is the parent of the second givenSimpleTreeNodeobject 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 givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
parentTreeNode- the parent tree nodechildren- the children to remove
-
removeChildren
Removes all children from the givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
parentTreeNode- the parent tree node
-
isRoot
Checks if the givenSimpleTreeNodeis the rootSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- true, if the given
SimpleTreeNodeis the rootSimpleTreeNodeobject
-
hasParent
Checks if the givenSimpleTreeNodeobject has a parentSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- true, if the given
SimpleTreeNodeobject has a parentSimpleTreeNodeobject otherwise false
-
isNode
Checks if the givenSimpleTreeNodeobject is a node- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- true, if the given
SimpleTreeNodeobject is a node otherwise false
-
clearAll
Removes all the descendants from the givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node
-
clearChildren
Removes all the children from the givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- 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 childSimpleTreeNodeobject to the first given parentSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
parentTreeNode- the parent tree nodechild- 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 parentSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
parentTreeNode- the parent tree nodechildren- the children to add
-
getChildCount
Gets the child count from the givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- the child count
-
hasChildren
Checks if the givenSimpleTreeNodeobject has children- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- true, if the given
SimpleTreeNodeobject has children otherwise false
-
traverse
public static <T,K> Collection<SimpleTreeNode<T,K>> traverse(@NonNull @NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNodeobject and add all descendants with the givenSimpleTreeNodeobject included in to the returnedCollectionobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- a
Collectionobject with the givenSimpleTreeNodeobject 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 valueK- the generic type of the id of the node- Parameters:
treeNode- the tree nodevisitor- 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 valueK- the generic type of the id of the node- Parameters:
treeNode- the tree nodevisitor- the visitorvisitBefore- the flag if this flag is true the visit of the givenSimpleTreeNodeobject 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 allSimpleTreeNodeobjects from the first givenSimpleTreeNodeobject that serves as the search target, that have the same value as the given value- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree nodevalue- the value for the search process- Returns:
- a
Collectionobject 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 ofSimpleTreeNodeobject from the first givenSimpleTreeNodeobject that serves as the search target, that have the same value as the given value- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree nodevalue- the value for the search process- Returns:
- the first occurrence of
SimpleTreeNodeobject 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 givenSimpleTreeNodeobject is a descendant of the first givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree nodedescendantCandidate- the tree node to check- Returns:
- true if the given
SimpleTreeNodeobject is a descendant of the first givenSimpleTreeNodeobject 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 givenCollectionobject ofSimpleTreeNodeobjects are descendants of the first givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree nodetreeNodes- the collection of the tree nodes to check- Returns:
- true if the given
Collectionobject ofSimpleTreeNodeobjects are descendants of the first givenSimpleTreeNodeobject otherwise false
-
toList
public static <T,K> List<SimpleTreeNode<T,K>> toList(@NonNull @NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNodeobject and adds all descendant with it self-included in to aListobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- a
Listobject with the givenSimpleTreeNodeobject 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 givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- all the right siblings from the given
SimpleTreeNodeobject
-
getAllLeftSiblings
public static <T,K> Collection<SimpleTreeNode<T,K>> getAllLeftSiblings(@NonNull @NonNull SimpleTreeNode<T, K> treeNode) Gets all the left siblings from the givenSimpleTreeNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeNode- the tree node- Returns:
- all the left siblings from the given
SimpleTreeNodeobject
-