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.Serializable
The Interface ITreeNode.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
addChild(ITreeNode<T> child)
Adds the child.default void
addChildAt(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 int
getChildCount()
Gets the child count.java.util.List<ITreeNode<T>>
getChildren()
Gets the children.default int
getDepth()
Returns the depth of the tree beginning at this node Returns 0 if this node has no children.java.lang.String
getDisplayValue()
Gets the optional display value.default int
getLevel()
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 rootITreeNode
objectT
getValue()
Gets the value.default boolean
hasChildren()
Checks for children.default boolean
hasParent()
Checks for parentdefault boolean
isLeaf()
Checks if is leaf.default boolean
isNode()
Checks if is node.default boolean
isRoot()
default void
removeChild(ITreeNode<T> child)
Removes the child.default void
removeChildAt(int index)
Removes the child.void
setChildren(java.util.List<ITreeNode<T>> children)
Sets the children.void
setDisplayValue(java.lang.String displayValue)
Sets the optional display value.void
setParent(ITreeNode<T> parent)
Sets the parent.void
setValue(T value)
Sets the value.default java.util.List<ITreeNode<T>>
toList()
To list.default void
traverse(ITreeNode<T> node, java.util.List<ITreeNode<T>> list)
Traverse.
-
-
-
Method Detail
-
addChildAt
default void addChildAt(int index, ITreeNode<T> child) throws java.lang.IndexOutOfBoundsException
Adds 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 rootITreeNode
object- Returns:
- the root
ITreeNode
object
-
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.IndexOutOfBoundsException
Removes 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
-
-