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 childSimpleTreeNode
object to the first given parentSimpleTreeNode
objectstatic <T,
K> void addChildren
(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull Collection<SimpleTreeNode<T, K>> children) Adds all the given children from the first given parentSimpleTreeNode
objectstatic <T,
K> void clearAll
(@NonNull SimpleTreeNode<T, K> treeNode) Removes all the descendants from the givenSimpleTreeNode
objectstatic <T,
K> void clearChildren
(@NonNull SimpleTreeNode<T, K> treeNode) Removes all the children from the givenSimpleTreeNode
objectstatic <T,
K> boolean contains
(@NonNull SimpleTreeNode<T, K> treeNode, SimpleTreeNode<T, K> descendantCandidate) Checks if the second givenSimpleTreeNode
object is a descendant of the first givenSimpleTreeNode
objectstatic <T,
K> boolean containsAll
(@NonNull SimpleTreeNode<T, K> treeNode, @NonNull Collection<SimpleTreeNode<T, K>> treeNodes) Checks if the givenCollection
object ofSimpleTreeNode
objects are descendants of the first givenSimpleTreeNode
objectstatic <T,
K> Collection<SimpleTreeNode<T, K>> findAllByValue
(@NonNull SimpleTreeNode<T, K> treeNode, T value) Find allSimpleTreeNode
objects from the first givenSimpleTreeNode
object 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 ofSimpleTreeNode
object from the first givenSimpleTreeNode
object 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 givenSimpleTreeNode
objectstatic <T,
K> Collection<SimpleTreeNode<T, K>> getAllRightSiblings
(@NonNull SimpleTreeNode<T, K> treeNode) Gets all the right siblings from the givenSimpleTreeNode
objectstatic <T,
K> Collection<SimpleTreeNode<T, K>> getAllSiblings
(@NonNull SimpleTreeNode<T, K> treeNode) Returns all siblings of the givenSimpleTreeNode
object in the parent's children liststatic <T,
K> int getChildCount
(@NonNull SimpleTreeNode<T, K> treeNode) Gets the child count from the givenSimpleTreeNode
objectstatic <T,
K> Collection<SimpleTreeNode<T, K>> getChildren
(@NonNull SimpleTreeNode<T, K> treeNode) Gets the children from the givenSimpleTreeNode
objectstatic <T,
K> int getLevel
(@NonNull SimpleTreeNode<T, K> treeNode) Returns the distance from the root to the givenSimpleTreeNode
object.static <T,
K> SimpleTreeNode<T, K> getNextSibling
(@NonNull SimpleTreeNode<T, K> currentTreeNode) Returns the next sibling of the givenSimpleTreeNode
object in the parent's children list.static <T,
K> SimpleTreeNode<T, K> getPreviousSibling
(@NonNull SimpleTreeNode<T, K> currentTreeNode) Returns the previous sibling of the givenSimpleTreeNode
object in the parent's children list.static <T,
K> SimpleTreeNode<T, K> getRoot
(@NonNull SimpleTreeNode<T, K> treeNode) Gets the root from the givenSimpleTreeNode
objectstatic <T,
K> boolean hasChildren
(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNode
object has childrenstatic <T,
K> boolean hasParent
(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNode
object has a parentSimpleTreeNode
objectstatic <T,
K> boolean isChildOf
(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull SimpleTreeNode<T, K> child) Checks if the second givenSimpleTreeNode
object is a child of the firstSimpleTreeNode
objectstatic <T,
K> boolean isNode
(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNode
object is a nodestatic <T,
K> boolean isParentOf
(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull SimpleTreeNode<T, K> child) Checks if the first givenSimpleTreeNode
object is the parent of the secondSimpleTreeNode
objectstatic <T,
K> boolean isRoot
(@NonNull SimpleTreeNode<T, K> treeNode) Checks if the givenSimpleTreeNode
is the rootSimpleTreeNode
objectstatic <T,
K> void removeChild
(@NonNull SimpleTreeNode<T, K> parentTreeNode, SimpleTreeNode<T, K> child) Removes the given child from the given firstSimpleTreeNode
static <T,
K> void removeChildren
(@NonNull SimpleTreeNode<T, K> parentTreeNode) Removes all children from the givenSimpleTreeNode
objectstatic <T,
K> void removeChildren
(@NonNull SimpleTreeNode<T, K> parentTreeNode, @NonNull Collection<SimpleTreeNode<T, K>> children) Removes all the given children from the first givenSimpleTreeNode
objectstatic <T,
K> List<SimpleTreeNode<T, K>> toList
(@NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNode
object and adds all descendant with it self-included in to aList
objectstatic <T,
K> Collection<SimpleTreeNode<T, K>> traverse
(@NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNode
object and add all descendants with the givenSimpleTreeNode
object included in to the returnedCollection
object
-
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 givenSimpleTreeNode
object- 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
SimpleTreeNode
object
-
getAllSiblings
public static <T,K> Collection<SimpleTreeNode<T,K>> getAllSiblings(@NonNull @NonNull SimpleTreeNode<T, K> treeNode) Returns all siblings of the givenSimpleTreeNode
object 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
SimpleTreeNode
object
-
getRoot
Gets the root from the givenSimpleTreeNode
object- 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
SimpleTreeNode
object
-
getNextSibling
public static <T,K> SimpleTreeNode<T,K> getNextSibling(@NonNull @NonNull SimpleTreeNode<T, K> currentTreeNode) Returns the next sibling of the givenSimpleTreeNode
object in the parent's children list. Returns null if the givenSimpleTreeNode
object 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
SimpleTreeNode
object or null if the givenSimpleTreeNode
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 givenSimpleTreeNode
object in the parent's children list. Returns null if the givenSimpleTreeNode
object 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
SimpleTreeNode
object or null if the givenSimpleTreeNode
object is the root or is the parent's last child.
-
getLevel
Returns the distance from the root to the givenSimpleTreeNode
object. Returns 0 if the givenSimpleTreeNode
object is the rootSimpleTreeNode
object- 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
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 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 givenSimpleTreeNode
object is a child of the firstSimpleTreeNode
object- 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
SimpleTreeNode
object is a child of the firstSimpleTreeNode
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 givenSimpleTreeNode
object is the parent of the secondSimpleTreeNode
object- 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
SimpleTreeNode
object is the parent of the second givenSimpleTreeNode
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 givenSimpleTreeNode
object- 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 givenSimpleTreeNode
object- 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 givenSimpleTreeNode
is the rootSimpleTreeNode
object- 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
SimpleTreeNode
is the rootSimpleTreeNode
object
-
hasParent
Checks if the givenSimpleTreeNode
object has a parentSimpleTreeNode
object- 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
SimpleTreeNode
object has a parentSimpleTreeNode
object otherwise false
-
isNode
Checks if the givenSimpleTreeNode
object 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
SimpleTreeNode
object is a node otherwise false
-
clearAll
Removes all the descendants from the givenSimpleTreeNode
object- 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 givenSimpleTreeNode
object- 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 childSimpleTreeNode
object to the first given parentSimpleTreeNode
object- 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 parentSimpleTreeNode
object- 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 givenSimpleTreeNode
object- 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 givenSimpleTreeNode
object 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
SimpleTreeNode
object has children otherwise false
-
traverse
public static <T,K> Collection<SimpleTreeNode<T,K>> traverse(@NonNull @NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNode
object and add all descendants with the givenSimpleTreeNode
object included in to the returnedCollection
object- 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
Collection
object with the givenSimpleTreeNode
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 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 givenSimpleTreeNode
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 allSimpleTreeNode
objects from the first givenSimpleTreeNode
object 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
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 ofSimpleTreeNode
object from the first givenSimpleTreeNode
object 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
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 givenSimpleTreeNode
object is a descendant of the first givenSimpleTreeNode
object- 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
SimpleTreeNode
object is a descendant of the first givenSimpleTreeNode
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 givenCollection
object ofSimpleTreeNode
objects are descendants of the first givenSimpleTreeNode
object- 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
Collection
object ofSimpleTreeNode
objects are descendants of the first givenSimpleTreeNode
object otherwise false
-
toList
public static <T,K> List<SimpleTreeNode<T,K>> toList(@NonNull @NonNull SimpleTreeNode<T, K> treeNode) Traverse the givenSimpleTreeNode
object and adds all descendant with it self-included in to aList
object- 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
List
object with the givenSimpleTreeNode
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 givenSimpleTreeNode
object- 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
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 givenSimpleTreeNode
object- 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
SimpleTreeNode
object
-