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 parentITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
voidclearAll(T treeNode) Removes all the descendants from the givenITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
voidclearChildren(T treeNode) Removes all the children from the givenITreeNodeobjectstatic <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 givenCollectionobject ofITreeNodeobjects are descendants of the first givenITreeNodeobjectstatic <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 ofITreeNodeobject 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 givenITreeNodeobject 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 givenITreeNodeobjectstatic <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 parentITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
intgetLevel(T treeNode) Returns the distance from the root to the givenITreeNodeobject.static <V,T extends ITreeNode<V, T>>
TgetNextSibling(T currentTreeNode) Returns the next sibling of the givenITreeNodeobject in the parent's children list.static <V,T extends ITreeNode<V, T>>
TgetPreviousSibling(T currentTreeNode) Returns the previous sibling of the givenITreeNodeobject in the parent's children list.static <V,T extends ITreeNode<V, T>>
TgetRoot(T treeNode) Gets the root from the givenITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
booleanhasChildren(T treeNode) Checks if the givenITreeNodeobject 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 givenITreeNodeobject 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 firstITreeNodestatic <V,T extends ITreeNode<V, T>>
voidremoveChild(T parentTreeNode, T child, boolean clearChildren) Removes the given child from the given firstITreeNodestatic <V,T extends ITreeNode<V, T>>
voidremoveChildren(T parentTreeNode) Removes all children from the givenITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
voidremoveChildren(T parentTreeNode, @NonNull Collection<T> children) Removes all the given children from the first givenITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
voidremoveFromParent(T treeNode) Removes the parent from the givenITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
voidremoveFromParent(T parentTreeNode, T child) Removes the parent from the given childITreeNodeobjectstatic <V,T extends ITreeNode<V, T>>
voidremoveFromParent(T parentTreeNode, T child, boolean clearChildren) Removes the parent from the given childITreeNodeobjecttoList(T treeNode) static <V,T extends ITreeNode<V, T>>
Collection<T>traverse(T treeNode) Traverse the givenITreeNodeobject and add all descendants with the givenITreeNodeobject included in to the returnedCollectionobject
-
Constructor Details
-
ITreeNodeHandlerExtensions
public ITreeNodeHandlerExtensions()
-
-
Method Details
-
getAllSiblings
Returns all siblings of the givenITreeNodeobject 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
ITreeNodeobject
-
getRoot
Gets the root from the givenITreeNodeobject- 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
ITreeNodeobject
-
getNextSibling
-
getPreviousSibling
-
getLevel
Returns the distance from the root to the givenITreeNodeobject. Returns 0 if the givenITreeNodeobject is the rootITreeNodeobject- 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
ITreeNodeobject
-
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 givenITreeNodeobject- 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 childITreeNodeobject- 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 childITreeNodeobject- 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
ITreeNodeobject 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 givenITreeNodeobject- 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 givenITreeNodeobject- 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 givenITreeNodeobject 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
ITreeNodeobject is a node otherwise false
-
clearAll
Removes all the descendants from the givenITreeNodeobject- 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 givenITreeNodeobject- 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 anOptionalobject with the child tree node from the given index from the first given parentITreeNodeobject- 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
Optionalobject with the child tree node
-
getChildIndex
Gets the index of the given child from the given index from the first given parentITreeNodeobject- 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 parentITreeNodeobject- 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 givenITreeNodeobject- 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 givenITreeNodeobject 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
ITreeNodeobject has children otherwise false
-
traverse
Traverse the givenITreeNodeobject and add all descendants with the givenITreeNodeobject included in to the returnedCollectionobject- Type Parameters:
V- the generic type of the valueT- the generic type of the concrete tree node- Parameters:
treeNode- the tree node- Returns:
- a
Collectionobject with the givenITreeNodeobject and add all descendants
-
findAllByValue
public static <V,T extends ITreeNode<V, Collection<T> findAllByValueT>> (@NonNull T treeNode, V value) Find allITreeNodeobjects from the first givenITreeNodeobject 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
Collectionobject with all found occurrences that have the same value as the given value
-
findByValue
Find the first occurrence ofITreeNodeobject from the first givenITreeNodeobject 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
ITreeNodeobject 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 givenCollectionobject ofITreeNodeobjects are descendants of the first givenITreeNodeobject- 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
Collectionobject ofITreeNodeobjects are descendants of the first givenITreeNodeobject otherwise false
-
toList
-
findFirstOccurenceOfDescendant
public static <V,T extends ITreeNode<V, T findFirstOccurenceOfDescendantT>> (@NonNull T treeNode, T possibleDescendant) Find the occurrence ofITreeNodeobject 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
ITreeNodeobject 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
ITreeNodeobject is a descendant of the firstITreeNodeobject 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
ITreeNodeobject is a ancestor of the firstITreeNodeobject otherwise false
-