Class ITreeNodeHandlerExtensions
java.lang.Object
io.github.astrapi69.gen.tree.handler.ITreeNodeHandlerExtensions
The class
ITreeNodeHandlerExtensions
provides handler methods for the class
ITreeNode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V,
T extends ITreeNode<V, T>>
voidaddChild
(T parentTreeNode, T child) static <V,
T extends ITreeNode<V, T>>
voidaddChild
(T parentTreeNode, T child, int index) static <V,
T extends ITreeNode<V, T>>
voidaddChildren
(T parentTreeNode, @NonNull 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 Collection<T> treeNodes) Checks if the givenCollection
object ofITreeNode
objects are descendants of the first givenITreeNode
objectstatic <V,
T extends ITreeNode<V, T>>
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>>
TfindFirstOccurenceOfDescendant
(T treeNode, T possibleDescendant) Find the occurrence ofITreeNode
object from the given possible descendant object that serves as the search targetstatic <V,
T extends ITreeNode<V, T>>
Collection<T>getAllSiblings
(T treeNode) Returns all siblings of the givenITreeNode
object in the parent's children listgetChildAt
(T parentTreeNode, int index) static <V,
T extends ITreeNode<V, T>>
intgetChildCount
(T treeNode) Gets the child count from the givenITreeNode
objectstatic <V,
T extends ITreeNode<V, T>>
intgetChildIndex
(T parentTreeNode, T child) Gets the index of the given child from the given index from the first given parentITreeNode
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>>
booleanhasNextSibling
(T treeNode) static <V,
T extends ITreeNode<V, T>>
booleanhasParent
(T treeNode) static <V,
T extends ITreeNode<V, T>>
booleanhasPreviousSibling
(T treeNode) static <V,
T extends ITreeNode<V, T>>
booleanisAncestor
(T treeNode, T possibleAncestor) static <V,
T extends ITreeNode<V, T>>
booleanisChild
(T parentTreeNode, T child) static <V,
T extends ITreeNode<V, T>>
booleanisChildOf
(T parentTreeNode, T child) static <V,
T extends ITreeNode<V, T>>
booleanisDescendant
(T treeNode, T possibleDescendant) 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>>
booleanmove
(T treeNodeToMove, T newParentTreeNode) 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>>
voidremoveChild
(T parentTreeNode, T child, boolean clearChildren) 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 Collection<T> children) Removes all the given children from the first givenITreeNode
objectstatic <V,
T extends ITreeNode<V, T>>
voidremoveFromParent
(T treeNode) Removes the parent from the givenITreeNode
objectstatic <V,
T extends ITreeNode<V, T>>
voidremoveFromParent
(T parentTreeNode, T child) Removes the parent from the given childITreeNode
objectstatic <V,
T extends ITreeNode<V, T>>
voidremoveFromParent
(T parentTreeNode, T child, boolean clearChildren) Removes the parent from the given childITreeNode
objecttoList
(T treeNode) static <V,
T extends ITreeNode<V, T>>
Collection<T>traverse
(T treeNode) Traverse the givenITreeNode
object and add all descendants with the givenITreeNode
object included in to the returnedCollection
object
-
Constructor Details
-
ITreeNodeHandlerExtensions
public ITreeNodeHandlerExtensions()
-
-
Method Details
-
getAllSiblings
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 concrete tree node- Parameters:
treeNode
- the tree node- Returns:
- Returns all siblings of the given
ITreeNode
object
-
getRoot
Gets the root from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node- Returns:
- the root from the given
ITreeNode
object
-
getNextSibling
-
getPreviousSibling
-
getLevel
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 concrete tree node- Parameters:
treeNode
- the tree node- Returns:
- the level from the given
ITreeNode
object
-
removeChild
Removes the given child from the given firstITreeNode
- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechild
- the child tree node
-
removeChild
public static <V,T extends ITreeNode<V, void removeChildT>> (@NonNull T parentTreeNode, T child, boolean clearChildren) Removes the given child from the given firstITreeNode
- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechild
- the child tree nodeclearChildren
- the flag that indicates if the children from the child tree node will be cleared
-
removeFromParent
Removes the parent from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node
-
removeFromParent
public static <V,T extends ITreeNode<V, void removeFromParentT>> (@NonNull T parentTreeNode, @NonNull T child) Removes the parent from the given childITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechild
- the child
-
removeFromParent
public static <V,T extends ITreeNode<V, void removeFromParentT>> (@NonNull T parentTreeNode, @NonNull T child, boolean clearChildren) Removes the parent from the given childITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechild
- the childclearChildren
- the flag that indicates if the children from the child tree node will be cleared
-
move
public static <V,T extends ITreeNode<V, boolean moveT>> (@NonNull T treeNodeToMove, T newParentTreeNode) - Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNodeToMove
- the tree node that will be moved to the new parent tree nodenewParentTreeNode
- the new parent tree node- Returns:
- true if the given
ITreeNode
object was moved otherwise false
-
isChild
-
isChildOf
public static <V,T extends ITreeNode<V, boolean isChildOfT>> (@NonNull T parentTreeNode, @NonNull T child) -
isParentOf
public static <V,T extends ITreeNode<V, boolean isParentOfT>> (@NonNull T parentTreeNode, @NonNull T child) -
removeChildren
public static <V,T extends ITreeNode<V, void removeChildrenT>> (@NonNull T parentTreeNode, @NonNull @NonNull 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 concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechildren
- the children to remove
-
removeChildren
Removes all children from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree node
-
isRoot
-
hasNextSibling
-
hasParent
-
hasPreviousSibling
-
isNode
Checks if the givenITreeNode
object is a node- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node- Returns:
- true, if the given
ITreeNode
object is a node otherwise false
-
clearAll
Removes all the descendants from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node
-
clearChildren
Removes all the children from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node
-
addChild
- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechild
- the child
-
addChild
public static <V,T extends ITreeNode<V, void addChildT>> (@NonNull T parentTreeNode, T child, int index) - Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechild
- the childindex
- the index of the child to insert
-
getChildAt
public static <V,T extends ITreeNode<V, Optional<T> getChildAtT>> (@NonNull T parentTreeNode, int index) Gets anOptional
object with the child tree node from the given index from the first given parentITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodeindex
- the index of the child to get- Returns:
- an
Optional
object with the child tree node
-
getChildIndex
Gets the index of the given child from the given index from the first given parentITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechild
- the child to resolve the index- Returns:
- the index of the given child in this tree node
-
addChildren
public static <V,T extends ITreeNode<V, void addChildrenT>> (@NonNull T parentTreeNode, @NonNull @NonNull 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 concrete tree node- Parameters:
parentTreeNode
- the parent tree nodechildren
- the children to add
-
getChildCount
Gets the child count from the givenITreeNode
object- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node- Returns:
- the child count
-
hasChildren
Checks if the givenITreeNode
object has children- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node- Returns:
- true, if the given
ITreeNode
object has children otherwise false
-
traverse
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 concrete tree node- Parameters:
treeNode
- the tree node- Returns:
- a
Collection
object with the givenITreeNode
object and add all descendants
-
findAllByValue
public static <V,T extends ITreeNode<V, Collection<T> findAllByValueT>> (@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 concrete tree 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
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 concrete tree 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, boolean containsT>> (@NonNull T treeNode, T descendantCandidate) -
containsAll
public static <V,T extends ITreeNode<V, boolean containsAllT>> (@NonNull T treeNode, @NonNull @NonNull 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 concrete tree 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
-
findFirstOccurenceOfDescendant
public static <V,T extends ITreeNode<V, T findFirstOccurenceOfDescendantT>> (@NonNull T treeNode, T possibleDescendant) Find the occurrence ofITreeNode
object from the given possible descendant object that serves as the search target- Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree nodepossibleDescendant
- the id for the search process- Returns:
- the first occurrence of
ITreeNode
object that have the same value as the given value
-
isDescendant
public static <V,T extends ITreeNode<V, boolean isDescendantT>> (@NonNull T treeNode, T possibleDescendant) - Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node to checkpossibleDescendant
- the possible descendant tree node to check- Returns:
- true, if the second given
ITreeNode
object is a descendant of the firstITreeNode
object otherwise false
-
isAncestor
public static <V,T extends ITreeNode<V, boolean isAncestorT>> (@NonNull T treeNode, @NonNull T possibleAncestor) - Type Parameters:
V
- the generic type of the valueT
- the generic type of the concrete tree node- Parameters:
treeNode
- the tree node to checkpossibleAncestor
- the possible ancestor tree node to check- Returns:
- true, if the second given
ITreeNode
object is a ancestor of the firstITreeNode
object otherwise false
-