Package io.github.astrapi69.tree.api
Interface ITreeNode<T>
-
- Type Parameters:
T- the generic type
- All Superinterfaces:
java.io.Serializable
- All Known Implementing Classes:
TreeNode
public interface ITreeNode<T> extends java.io.SerializableThe Interface ITreeNode.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidaddChild(ITreeNode<T> child)Adds the child.default voidaddChildAt(int index, ITreeNode<T> child)Adds the child.default java.util.List<ITreeNode<T>>getAllSiblings()Returns all siblings of this node in the parent's children list.default intgetChildCount()Gets the child count.java.util.List<ITreeNode<T>>getChildren()Gets the children.default intgetDepth()Returns the depth of the tree beginning at this node Returns 0 if this node has no children.java.lang.StringgetDisplayValue()Gets the optional display value.default intgetLevel()Returns the distance from the root to this node.default ITreeNode<T>getNextSibling()Returns the next sibling of this node in the parent's children list.ITreeNode<T>getParent()Gets the parent.default ITreeNode<T>getPreviousSibling()Returns the previous sibling of this node in the parent's children list.default ITreeNode<T>getRoot()Gets the rootITreeNodeobjectTgetValue()Gets the value.default booleanhasChildren()Checks for children.default booleanhasParent()Checks for parentdefault booleanisLeaf()Checks if is leaf.default booleanisNode()Checks if is node.default booleanisRoot()default voidremoveChild(ITreeNode<T> child)Removes the child.default voidremoveChildAt(int index)Removes the child.voidsetChildren(java.util.List<ITreeNode<T>> children)Sets the children.voidsetDisplayValue(java.lang.String displayValue)Sets the optional display value.voidsetParent(ITreeNode<T> parent)Sets the parent.voidsetValue(T value)Sets the value.default java.util.List<ITreeNode<T>>toList()To list.default voidtraverse(ITreeNode<T> node, java.util.List<ITreeNode<T>> list)Traverse.
-
-
-
Method Detail
-
addChildAt
default void addChildAt(int index, ITreeNode<T> child) throws java.lang.IndexOutOfBoundsExceptionAdds the child.- Parameters:
index- the indexchild- the child- Throws:
java.lang.IndexOutOfBoundsException- the index out of bounds exception
-
getAllSiblings
default java.util.List<ITreeNode<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.
-
getChildCount
default int getChildCount()
Gets the child count.- Returns:
- the child count
-
getDepth
default int getDepth()
Returns the depth of the tree beginning at this node Returns 0 if this node has no children.- Returns:
- the depth of the tree beginning at this node.
-
getDisplayValue
java.lang.String getDisplayValue()
Gets the optional display value.- Returns:
- the 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.
-
getNextSibling
default ITreeNode<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.
-
getPreviousSibling
default ITreeNode<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.
-
getRoot
default ITreeNode<T> getRoot()
Gets the rootITreeNodeobject- Returns:
- the root
ITreeNodeobject
-
getValue
T getValue()
Gets the value.- Returns:
- the value
-
hasChildren
default boolean hasChildren()
Checks for children.- Returns:
- true, if successful
-
hasParent
default boolean hasParent()
Checks for parent- Returns:
- true, if successful
-
isLeaf
default boolean isLeaf()
Checks if is leaf.- Returns:
- true, if is leaf
-
isNode
default boolean isNode()
Checks if is node.- Returns:
- true, if is node
-
removeChild
default void removeChild(ITreeNode<T> child)
Removes the child.- Parameters:
child- the child
-
removeChildAt
default void removeChildAt(int index) throws java.lang.IndexOutOfBoundsExceptionRemoves the child.- Parameters:
index- the index- Throws:
java.lang.IndexOutOfBoundsException- the index out of bounds exception
-
setChildren
void setChildren(java.util.List<ITreeNode<T>> children)
Sets the children.- Parameters:
children- the new children
-
setDisplayValue
void setDisplayValue(java.lang.String displayValue)
Sets the optional display value.- Parameters:
displayValue- the new optional display value
-
setValue
void setValue(T value)
Sets the value.- Parameters:
value- the new value
-
-