Module gen.tree
Package io.github.astrapi69.tree.api
Interface ITreeNode<V,T extends ITreeNode<V,T>>
-
- Type Parameters:
V- the generic type of the valueT- the generic type of the concrete tree node
- All Superinterfaces:
io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<T>>,java.io.Serializable
- All Known Subinterfaces:
IBaseTreeNode<V,K,T>
- All Known Implementing Classes:
BaseTreeNode,TreeNode
public interface ITreeNode<V,T extends ITreeNode<V,T>> extends java.io.Serializable, io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<T>>The InterfaceITreeNodeholds the children in aCollectionobject
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidaccept(@NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)default voidaddChild(T child)Adds the given childdefault voidaddChildren(@NonNull java.util.Collection<T> children)Adds all the given childrendefault voidclearAll()Removes all the descendantsdefault voidclearChildren()Removes all the childrendefault booleancontains(T treeNode)Checks if the givenITreeNodeobject is a descendant of this tree nodedefault booleancontainsAll(@NonNull java.util.Collection<T> treeNodes)Checks if the givenCollectionobject ofITreeNodeobjects are descendants of this tree nodedefault java.util.Collection<T>findAllByValue(V value)Find allITreeNodeobjects that have the same value as the given valuedefault TfindByValue(V value)Find allITreeNodeobjects that have the same value as the given valuedefault java.util.Collection<T>getAllSiblings()Returns all siblings of this node in the parent's children list.default intgetChildCount()Gets the child count.java.util.Collection<T>getChildren()Gets the children.java.lang.StringgetDisplayValue()Gets the optional display value.default intgetLevel()Returns the distance from the root to this node.default TgetNextSibling()Returns the next sibling of this node in the parent's children list.TgetParent()Gets the parent.default TgetPreviousSibling()Returns the previous sibling of this node in the parent's children list.default TgetRoot()Gets the root objectVgetValue()Gets the value.default booleanhasChildren()Checks for children.default booleanhasParent()Checks for parentbooleanisLeaf()Checks if is leaf.default booleanisNode()Checks if is node.default booleanisRoot()default voidremoveChild(T child)Removes the child.default voidremoveChildren()Removes all the childrendefault voidremoveChildren(@NonNull java.util.Collection<T> children)Removes all the given childrenvoidsetChildren(java.util.Collection<T> children)Sets the children.voidsetDisplayValue(java.lang.String displayValue)Sets the optional display value.voidsetLeaf(boolean leaf)Sets the flag that indicates if this tree node is a node or a leafvoidsetParent(T parent)Sets the parent.voidsetValue(V value)Sets the value.default java.util.List<T>toList()Traverse this node and adds all descendant with this included in to aListobjectdefault java.util.Collection<T>traverse()Traverse this node and adds all descendant with this included in to aCollectionobject
-
-
-
Method Detail
-
addChild
default void addChild(T child)
Adds the given child- Parameters:
child- the child
-
addChildren
default void addChildren(@NonNull @NonNull java.util.Collection<T> children)Adds all the given children- Parameters:
children- the children to add
-
getAllSiblings
default java.util.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
default 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
default 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
default int getChildCount()
Gets the child count.- Returns:
- the child count
-
getChildren
java.util.Collection<T> getChildren()
Gets the children.- Returns:
- the children
-
setChildren
void setChildren(java.util.Collection<T> children)
Sets the children.- Parameters:
children- the new children
-
getDisplayValue
java.lang.String getDisplayValue()
Gets the optional display value.- Returns:
- the display value
-
setDisplayValue
void setDisplayValue(java.lang.String displayValue)
Sets the optional display value.- Parameters:
displayValue- the new optional display value
-
getLevel
default 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.- Returns:
- the parent
-
setParent
void setParent(T parent)
Sets the parent.- Parameters:
parent- the new parent
-
getRoot
default T getRoot()
Gets the root object- Returns:
- the root object
-
getValue
V getValue()
Gets the value.- Returns:
- the value
-
setValue
void setValue(V value)
Sets the value.- Parameters:
value- the new value
-
hasChildren
default boolean hasChildren()
Checks for children.- Returns:
- true, if successful
-
hasParent
default boolean hasParent()
Checks for parent- Returns:
- true, if successful
-
isLeaf
boolean isLeaf()
Checks if is leaf.- Returns:
- true, if is leaf
-
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
-
isNode
default boolean isNode()
Checks if is node.- Returns:
- true, if is node
-
removeChild
default void removeChild(T child)
Removes the child.- Parameters:
child- the child
-
clearChildren
default void clearChildren()
Removes all the children
-
clearAll
default void clearAll()
Removes all the descendants
-
removeChildren
default void removeChildren()
Removes all the children
-
removeChildren
default void removeChildren(@NonNull @NonNull java.util.Collection<T> children)Removes all the given children- Parameters:
children- the children to remove
-
accept
default void accept(@NonNull @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)- Specified by:
acceptin interfaceio.github.astrapi69.design.pattern.visitor.Acceptable<V>
-
findAllByValue
default java.util.Collection<T> findAllByValue(V value)
Find allITreeNodeobjects 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
default T findByValue(@NonNull V value)
Find allITreeNodeobjects 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
-
contains
default boolean contains(T treeNode)
Checks if the givenITreeNodeobject is a descendant of this tree node- Parameters:
treeNode- the tree node to check- Returns:
- true if the given
ITreeNodeobject is a descendant of this tree node otherwise false
-
containsAll
default boolean containsAll(@NonNull @NonNull java.util.Collection<T> treeNodes)Checks if the givenCollectionobject ofITreeNodeobjects are descendants of this tree node- Parameters:
treeNodes- the children to add- Returns:
- true if the given
Collectionobject ofITreeNodeobjects are descendants of this tree node otherwise false
-
toList
default java.util.List<T> 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
default java.util.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
-
-