- java.lang.Object
-
- io.github.astrapi69.gen.tree.handler.ITreeNodeHandlerExtensions
-
public class ITreeNodeHandlerExtensions extends java.lang.ObjectThe classITreeNodeHandlerExtensionsprovides 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>>
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 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 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 givenITreeNodeobject in the parent's children liststatic <V,T extends ITreeNode<V,T>>
intgetChildCount(T treeNode)Gets the child count from the givenITreeNodeobjectstatic <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>>
booleanisChild(T parentTreeNode, T child)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 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>>
voidremoveChild(T parentTreeNode, T child)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 java.util.Collection<T> children)Removes all the given children from the first givenITreeNodeobjectstatic <V,T extends ITreeNode<V,T>>
java.util.List<T>toList(T treeNode)Traverse the givenITreeNodeobject and adds all descendant with it self-included in to aListobjectstatic <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 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
public static <V,T extends ITreeNode<V,T>> T getRoot(@NonNull T treeNode)
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
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 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
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 concrete tree node- Parameters:
parentTreeNode- the parent tree nodechild- the child tree node
-
isChild
public static <V,T extends ITreeNode<V,T>> boolean isChild(@NonNull T parentTreeNode, T child)
-
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 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
public static <V,T extends ITreeNode<V,T>> void removeChildren(@NonNull T parentTreeNode)
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
public static <V,T extends ITreeNode<V,T>> boolean isRoot(@NonNull T treeNode)
-
hasNextSibling
public static <V,T extends ITreeNode<V,T>> boolean hasNextSibling(@NonNull T treeNode)
-
hasParent
public static <V,T extends ITreeNode<V,T>> boolean hasParent(@NonNull T treeNode)
-
hasPreviousSibling
public static <V,T extends ITreeNode<V,T>> boolean hasPreviousSibling(@NonNull T treeNode)
-
isNode
public static <V,T extends ITreeNode<V,T>> boolean isNode(@NonNull T treeNode)
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
public static <V,T extends ITreeNode<V,T>> void clearAll(@NonNull T treeNode)
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
public static <V,T extends ITreeNode<V,T>> void clearChildren(@NonNull T treeNode)
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
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 concrete tree 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 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
public static <V,T extends ITreeNode<V,T>> int getChildCount(@NonNull T treeNode)
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
public static <V,T extends ITreeNode<V,T>> boolean hasChildren(@NonNull T treeNode)
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
public static <V,T extends ITreeNode<V,T>> java.util.Collection<T> traverse(@NonNull T treeNode)
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,T>> java.util.Collection<T> findAllByValue(@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
public static <V,T extends ITreeNode<V,T>> T findByValue(@NonNull T treeNode, V value)
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,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 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
public static <V,T extends ITreeNode<V,T>> java.util.List<T> toList(@NonNull T treeNode)
Traverse the givenITreeNodeobject and adds all descendant with it self-included in to aListobject- Type Parameters:
V- the generic type of the valueT- the generic type of the concrete tree node- Parameters:
treeNode- the tree node- Returns:
- a
Listobject with the givenITreeNodeobject and all descendants
-
-