- java.lang.Object
-
- io.github.astrapi69.tree.handler.ITreeNodeHandlerExtensions
-
public class ITreeNodeHandlerExtensions extends java.lang.Object
The classITreeNodeHandlerExtensions
provides handler methods for the classITreeNode
-
-
Constructor Summary
Constructors Constructor Description ITreeNodeHandlerExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V,T extends ITreeNode<V,T>>
voidaccept(T treeNode, @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)
Accepts the given visitor that provides a custom algorithm for processing all elementsstatic <V,T extends ITreeNode<V,T>>
voidaccept(T treeNode, @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor, boolean visitBefore)
Accepts the given visitor that provides a custom algorithm for processing all elementsstatic <V,T extends ITreeNode<V,T>>
voidaddChild(T parentTreeNode, T child)
static <V,T extends ITreeNode<V,T>>
voidaddChildren(T parentTreeNode, @NonNull java.util.Collection<T> children)
Adds all the given children from the first given parentITreeNode
objectstatic <V,T extends ITreeNode<V,T>>
voidclearAll(T treeNode)
Removes all the descendants from the givenITreeNode
objectstatic <V,T extends ITreeNode<V,T>>
voidclearChildren(T treeNode)
Removes all the children from the givenITreeNode
objectstatic <V,T extends ITreeNode<V,T>>
booleancontains(T treeNode, T descendantCandidate)
static <V,T extends ITreeNode<V,T>>
booleancontainsAll(T treeNode, @NonNull java.util.Collection<T> treeNodes)
static <V,T extends ITreeNode<V,T>>
java.util.Collection<T>findAllByValue(T treeNode, V value)
static <V,T extends ITreeNode<V,T>>
TfindByValue(T treeNode, V value)
static <V,T extends ITreeNode<V,T>>
java.util.Collection<T>getAllSiblings(T treeNode)
Returns all siblings of the givenITreeNode
object in the parent's children liststatic <V,T extends ITreeNode<V,T>>
intgetChildCount(T treeNode)
Gets the child count from the givenITreeNode
objectstatic <V,T extends ITreeNode<V,T>>
intgetLevel(T treeNode)
Returns the distance from the root to the givenITreeNode
object.static <V,T extends ITreeNode<V,T>>
TgetNextSibling(T currentTreeNode)
Returns the next sibling of the givenITreeNode
object in the parent's children list.static <V,T extends ITreeNode<V,T>>
TgetPreviousSibling(T currentTreeNode)
Returns the previous sibling of the givenITreeNode
object in the parent's children list.static <V,T extends ITreeNode<V,T>>
TgetRoot(T treeNode)
Gets the root from the givenITreeNode
objectstatic <V,T extends ITreeNode<V,T>>
booleanhasChildren(T treeNode)
Checks if the givenITreeNode
object has childrenstatic <V,T extends ITreeNode<V,T>>
booleanhasParent(T treeNode)
static <V,T extends ITreeNode<V,T>>
booleanisChildOf(T parentTreeNode, T child)
static <V,T extends ITreeNode<V,T>>
booleanisNode(T treeNode)
Checks if the givenITreeNode
object is a nodestatic <V,T extends ITreeNode<V,T>>
booleanisParentOf(T parentTreeNode, T child)
static <V,T extends ITreeNode<V,T>>
booleanisRoot(T treeNode)
static <V,T extends ITreeNode<V,T>>
voidremoveChild(T parentTreeNode, T child)
Removes the given child from the given firstITreeNode
static <V,T extends ITreeNode<V,T>>
voidremoveChildren(T parentTreeNode)
Removes all children from the givenITreeNode
objectstatic <V,T extends ITreeNode<V,T>>
voidremoveChildren(T parentTreeNode, @NonNull java.util.Collection<T> children)
Removes all the given children from the first givenITreeNode
objectstatic <V,T extends ITreeNode<V,T>>
java.util.List<T>toList(T treeNode)
Traverse the givenITreeNode
object and adds all descendant with it self-included in to aList
objectstatic <V,T extends ITreeNode<V,T>>
java.util.Collection<T>traverse(T treeNode)
-
-
-
Method Detail
-
getAllSiblings
public static <V,T extends ITreeNode<V,T>> java.util.Collection<T> getAllSiblings(@NonNull T treeNode)
Returns all siblings of the givenITreeNode
object in the parent's children list- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the 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 givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the 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)
-
getPreviousSibling
public static <V,T extends ITreeNode<V,T>> T getPreviousSibling(@NonNull T currentTreeNode)
-
getLevel
public static <V,T extends ITreeNode<V,T>> int getLevel(@NonNull T treeNode)
Returns the distance from the root to the givenITreeNode
object. Returns 0 if the givenITreeNode
object is the rootITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the 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 firstITreeNode
- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
parentTreeNode
- the parent tree nodechild
- the child tree node
-
isChildOf
public static <V,T extends ITreeNode<V,T>> boolean isChildOf(@NonNull T parentTreeNode, @NonNull T child)
-
isParentOf
public static <V,T extends ITreeNode<V,T>> boolean isParentOf(@NonNull T parentTreeNode, @NonNull T child)
-
removeChildren
public static <V,T extends ITreeNode<V,T>> void removeChildren(@NonNull T parentTreeNode, @NonNull @NonNull java.util.Collection<T> children)
Removes all the given children from the first givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
parentTreeNode
- the parent tree nodechildren
- the children to remove
-
removeChildren
public static <V,T extends ITreeNode<V,T>> void removeChildren(@NonNull T parentTreeNode)
Removes all children from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
parentTreeNode
- the parent tree node
-
isRoot
public static <V,T extends ITreeNode<V,T>> boolean isRoot(@NonNull T treeNode)
-
hasParent
public static <V,T extends ITreeNode<V,T>> boolean hasParent(@NonNull T treeNode)
-
isNode
public static <V,T extends ITreeNode<V,T>> boolean isNode(@NonNull T treeNode)
Checks if the givenITreeNode
object is a node- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the 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 givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the 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 givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
treeNode
- the tree node
-
addChild
public static <V,T extends ITreeNode<V,T>> void addChild(@NonNull T parentTreeNode, T child)
- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
parentTreeNode
- the parent tree nodechild
- the child
-
addChildren
public static <V,T extends ITreeNode<V,T>> void addChildren(@NonNull T parentTreeNode, @NonNull @NonNull java.util.Collection<T> children)
Adds all the given children from the first given parentITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
parentTreeNode
- the parent tree nodechildren
- the children to add
-
getChildCount
public static <V,T extends ITreeNode<V,T>> int getChildCount(@NonNull T treeNode)
Gets the child count from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the 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 givenITreeNode
object has children- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the 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>> java.util.Collection<T> traverse(@NonNull T treeNode)
Traverse the givenITreeNode
object and add all descendants with the givenITreeNode
object included in to the returnedCollection
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
treeNode
- the tree node- Returns:
- a
Collection
object with the givenITreeNode
object and add all descendants
-
accept
public static <V,T extends ITreeNode<V,T>> void accept(@NonNull T treeNode, @NonNull @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)
Accepts the given visitor that provides a custom algorithm for processing all elements- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
treeNode
- the tree nodevisitor
- the visitor
-
accept
public static <V,T extends ITreeNode<V,T>> void accept(@NonNull T treeNode, @NonNull @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor, boolean visitBefore)
Accepts the given visitor that provides a custom algorithm for processing all elements- Type Parameters:
V
- the generic type of the valueT
- 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 givenITreeNode
object is before visit the children otherwise the visit is after visit the children
-
findAllByValue
public static <V,T extends ITreeNode<V,T>> java.util.Collection<T> findAllByValue(@NonNull T treeNode, V value)
Find allITreeNode
objects from the first givenITreeNode
object that serves as the search target, that have the same value as the given value- Type Parameters:
V
- the generic type of the valueT
- 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 <V,T extends ITreeNode<V,T>> T findByValue(@NonNull T treeNode, V value)
Find the first occurrence ofITreeNode
object from the first givenITreeNode
object that serves as the search target, that have the same value as the given value- Type Parameters:
V
- the generic type of the valueT
- 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
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)
-
containsAll
public static <V,T extends ITreeNode<V,T>> boolean containsAll(@NonNull T treeNode, @NonNull @NonNull java.util.Collection<T> treeNodes)
Checks if the givenCollection
object ofITreeNode
objects are descendants of the first givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- 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 ofITreeNode
objects are descendants of the first givenITreeNode
object otherwise false
-
toList
public static <V,T extends ITreeNode<V,T>> java.util.List<T> toList(@NonNull T treeNode)
Traverse the givenITreeNode
object and adds all descendant with it self-included in to aList
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the id of the node- Parameters:
treeNode
- the tree node- Returns:
- a
List
object with the givenITreeNode
object and all descendants
-
-