- java.lang.Object
-
- io.github.astrapi69.tree.handler.SimpleTreeNodeHandlerExtensions
-
public class SimpleTreeNodeHandlerExtensions extends java.lang.Object
The classSimpleTreeNodeHandlerExtensions
provides handler methods for the classSimpleTreeNode
-
-
Constructor Summary
Constructors Constructor Description SimpleTreeNodeHandlerExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,K>
voidaccept(@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>
voidaccept(@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>
voidaddChild(@NonNull SimpleTreeNode<T,K> parentTreeNode, SimpleTreeNode<T,K> child)
Adds the given childSimpleTreeNode
object to the first given parentSimpleTreeNode
objectstatic <T,K>
voidaddChildren(@NonNull SimpleTreeNode<T,K> parentTreeNode, @NonNull java.util.Collection<SimpleTreeNode<T,K>> children)
Adds all the given children from the first given parentSimpleTreeNode
objectstatic <T,K>
voidclearAll(@NonNull SimpleTreeNode<T,K> treeNode)
Removes all the descendants from the givenSimpleTreeNode
objectstatic <T,K>
voidclearChildren(@NonNull SimpleTreeNode<T,K> treeNode)
Removes all the children from the givenSimpleTreeNode
objectstatic <T,K>
booleancontains(@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>
booleancontainsAll(@NonNull SimpleTreeNode<T,K> treeNode, @NonNull java.util.Collection<SimpleTreeNode<T,K>> treeNodes)
Checks if the givenCollection
object ofSimpleTreeNode
objects are descendants of the first givenSimpleTreeNode
objectstatic <T,K>
java.util.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>
java.util.Collection<SimpleTreeNode<T,K>>getAllLeftSiblings(@NonNull SimpleTreeNode<T,K> treeNode)
Gets all the left siblings from the givenSimpleTreeNode
objectstatic <T,K>
java.util.Collection<SimpleTreeNode<T,K>>getAllRightSiblings(@NonNull SimpleTreeNode<T,K> treeNode)
Gets all the right siblings from the givenSimpleTreeNode
objectstatic <T,K>
java.util.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>
intgetChildCount(@NonNull SimpleTreeNode<T,K> treeNode)
Gets the child count from the givenSimpleTreeNode
objectstatic <T,K>
java.util.Collection<SimpleTreeNode<T,K>>getChildren(@NonNull SimpleTreeNode<T,K> treeNode)
Gets the children from the givenSimpleTreeNode
objectstatic <T,K>
intgetLevel(@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>
booleanhasChildren(@NonNull SimpleTreeNode<T,K> treeNode)
Checks if the givenSimpleTreeNode
object has childrenstatic <T,K>
booleanhasParent(@NonNull SimpleTreeNode<T,K> treeNode)
Checks if the givenSimpleTreeNode
object has a parentSimpleTreeNode
objectstatic <T,K>
booleanisChildOf(@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>
booleanisNode(@NonNull SimpleTreeNode<T,K> treeNode)
Checks if the givenSimpleTreeNode
object is a nodestatic <T,K>
booleanisParentOf(@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>
booleanisRoot(@NonNull SimpleTreeNode<T,K> treeNode)
Checks if the givenSimpleTreeNode
is the rootSimpleTreeNode
objectstatic <T,K>
voidremoveChild(@NonNull SimpleTreeNode<T,K> parentTreeNode, SimpleTreeNode<T,K> child)
Removes the given child from the given firstSimpleTreeNode
static <T,K>
voidremoveChildren(@NonNull SimpleTreeNode<T,K> parentTreeNode)
Removes all children from the givenSimpleTreeNode
objectstatic <T,K>
voidremoveChildren(@NonNull SimpleTreeNode<T,K> parentTreeNode, @NonNull java.util.Collection<SimpleTreeNode<T,K>> children)
Removes all the given children from the first givenSimpleTreeNode
objectstatic <T,K>
java.util.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>
java.util.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
-
-
-
Method Detail
-
getChildren
public static <T,K> java.util.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> java.util.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
public static <T,K> SimpleTreeNode<T,K> getRoot(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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
public static <T,K> int getLevel(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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 java.util.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
public static <T,K> void removeChildren(@NonNull @NonNull SimpleTreeNode<T,K> parentTreeNode)
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
public static <T,K> boolean isRoot(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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
public static <T,K> boolean hasParent(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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
public static <T,K> boolean isNode(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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
public static <T,K> void clearAll(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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
public static <T,K> void clearChildren(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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 java.util.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
public static <T,K> int getChildCount(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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
public static <T,K> boolean hasChildren(@NonNull @NonNull SimpleTreeNode<T,K> treeNode)
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> java.util.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> java.util.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 java.util.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> java.util.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> java.util.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> java.util.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
-
-