Package io.github.astrapi69.tree.api
Interface ITree<V,T>
- Type Parameters:
V- the generic type of the valueT- the generic type of the concrete tree node
- All Superinterfaces:
Serializable
The interface
ITree represents a generic tree structure-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given child to this tree nodevoidAdds the given child to this tree nodevoidaddChildren(@NonNull Collection<T> children) Adds all the given children to this tree nodevoidclearAll()Removes all the descendants from this tree nodevoidRemoves all the children from this tree nodebooleanChecks if the givenITreeobject is a descendant of this tree nodebooleancontainsAll(@NonNull Collection<T> treeNodes) Checks if the givenCollectionobject ofITreeobjects are descendants of this tree nodefindAllByValue(V value) Find allITreeobjects that have the same value as the given valuefindByValue(V value) Find the firstITreeobject that have the same value as the given valueReturns all siblings of this node in the parent's children list.getChildAt(int index) Gets the child tree node from the given indexintGets the child count of this tree nodeintgetChildIndex(T child) Gets the index of the given child in this tree nodeGets the children of this tree nodeGets the optional display value of this tree nodeintgetLevel()Returns the distance from the root to this node.Returns the next sibling of this node in the parent's children list.Gets the parent of this tree nodeReturns the previous sibling of this node in the parent's children list.getRoot()Gets the root objectgetValue()Gets the value of this tree nodebooleanChecks if this tree node has childrenbooleanChecks if this node has a next siblingbooleanChecks if this tree node has a parentbooleanChecks if this node has a previous siblingbooleanisAncestor(T treeNode) booleanChecks if the given tree node is a child of this tree nodebooleanisDescendant(T treeNode) booleanisLeaf()Checks if this node is a leafbooleanisNode()Checks if this node is a nodebooleanisRoot()booleanvoidremoveChild(T child) Removes the given child from this tree nodevoidRemoves all the children from this tree nodevoidremoveChildren(@NonNull Collection<T> children) Removes all the given children from this tree nodevoidsetChildren(Collection<T> children) Sets the children of this tree nodevoidsetDisplayValue(String displayValue) Sets the optional display value of this tree nodevoidsetLeaf(boolean leaf) Sets the flag that indicates if this tree node is a node or a leafvoidSets the parent of this tree nodevoidSets the value of this tree nodetoList()Traverse this node and adds all descendant with this included in to aListobjecttraverse()Traverse this node and adds all descendant with this included in to aCollectionobject
-
Method Details
-
addChild
Adds the given child to this tree node- Parameters:
child- the child
-
addChild
Adds the given child to this tree node- Parameters:
child- the childindex- the index of the child to insert
-
addChildren
Adds all the given children to this tree node- Parameters:
children- the children to add
-
getAllSiblings
Collection<T> getAllSiblings()Returns all siblings of this node in the parent's children list. Returns null if this node is the root- Returns:
- Returns all siblings of this node or null if this node is the root
-
getPreviousSibling
T getPreviousSibling()Returns the previous sibling of this node in the parent's children list. Returns null if this node is the root or is the parent's first child- Returns:
- the next sibling of this node or null if this node is the root or is the parent's last child
-
getNextSibling
T getNextSibling()Returns the next sibling of this node in the parent's children list. Returns null if this node is the root or is the parent's last child- Returns:
- the next sibling of this node or null if this node is the root or is the parent's last child
-
getChildCount
int getChildCount()Gets the child count of this tree node- Returns:
- the child count
-
getChildren
Collection<T> getChildren()Gets the children of this tree node- Returns:
- the children
-
getChildAt
Gets the child tree node from the given index- Parameters:
index- the index of the child to get- Returns:
- an
Optionalobject with the child tree node from the given index
-
getChildIndex
Gets the index of the given child in this tree node- Parameters:
child- the child to resolve the index- Returns:
- the index of the given child in this tree node
-
setChildren
Sets the children of this tree node- Parameters:
children- the new children
-
getDisplayValue
String getDisplayValue()Gets the optional display value of this tree node- Returns:
- the display value
-
setDisplayValue
Sets the optional display value of this tree node- Parameters:
displayValue- the new optional display value
-
getLevel
int getLevel()Returns the distance from the root to this node. Returns 0 if this node is the root- Returns:
- the level from this node
-
getParent
T getParent()Gets the parent of this tree node- Returns:
- the parent
-
setParent
Sets the parent of this tree node- Parameters:
parent- the new parent
-
getRoot
T getRoot()Gets the root object- Returns:
- the root object
-
getValue
V getValue()Gets the value of this tree node- Returns:
- the value
-
setValue
Sets the value of this tree node- Parameters:
value- the new value
-
hasChildren
boolean hasChildren()Checks if this tree node has children- Returns:
- true, if this tree node has children otherwise false
-
isChild
Checks if the given tree node is a child of this tree node- Parameters:
treeNode- the tree node to check- Returns:
- true, if the given tree node is a child of this tree node otherwise false
-
hasNextSibling
boolean hasNextSibling()Checks if this node has a next sibling- Returns:
- true, if this node has a next sibling otherwise false
-
hasParent
boolean hasParent()Checks if this tree node has a parent- Returns:
- true, if this tree node has a parent otherwise false
-
hasPreviousSibling
boolean hasPreviousSibling()Checks if this node has a previous sibling- Returns:
- true, if this node has a previous sibling otherwise false
-
isLeaf
boolean isLeaf()Checks if this node is a leaf- Returns:
- true, if this node is a leaf otherwise false
-
setLeaf
void setLeaf(boolean leaf) Sets the flag that indicates if this tree node is a node or a leaf- Parameters:
leaf- The flag to set that indicates if this tree node is a node or a leaf
-
isAncestor
-
isDescendant
-
move
-
isNode
boolean isNode()Checks if this node is a node- Returns:
- true, if this node is a node otherwise false
-
isRoot
boolean isRoot() -
removeChild
Removes the given child from this tree node- Parameters:
child- the child
-
clearChildren
void clearChildren()Removes all the children from this tree node -
clearAll
void clearAll()Removes all the descendants from this tree node -
removeChildren
void removeChildren()Removes all the children from this tree node -
removeChildren
Removes all the given children from this tree node- Parameters:
children- the children to remove
-
findAllByValue
Find allITreeobjects that have the same value as the given value- Parameters:
value- 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 firstITreeobject that have the same value as the given value- Parameters:
value- the value for the search process- Returns:
- the first
ITreeobject that have the same value as the given value
-
contains
Checks if the givenITreeobject is a descendant of this tree node- Parameters:
treeNode- the tree node to check- Returns:
- true if the given
ITreeobject is a descendant of this tree node otherwise false
-
containsAll
Checks if the givenCollectionobject ofITreeobjects are descendants of this tree node- Parameters:
treeNodes- the tree nodes- Returns:
- true if the given
Collectionof tree node objects are descendants of this tree node otherwise false
-
toList
Traverse this node and adds all descendant with this included in to aListobject- Returns:
- a
Listobject with this node and add all descendant
-
traverse
Collection<T> traverse()Traverse this node and adds all descendant with this included in to aCollectionobject- Returns:
- a
Collectionobject with this node and add all descendant
-