- java.lang.Object
-
- io.github.astrapi69.tree.SimpleTreeNode<T,K>
-
- Type Parameters:
T
- the generic type of the value
- All Implemented Interfaces:
io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<T,K>>>
public class SimpleTreeNode<T,K> extends java.lang.Object implements io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<T,K>>>
The generic classSimpleTreeNode
holds only the parent, the left most child and the right sibling
-
-
Constructor Summary
Constructors Constructor Description SimpleTreeNode(T value)
Instantiates a newSimpleTreeNode
object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<T,K>> visitor)
java.util.Collection<SimpleTreeNode<T,K>>
getAllLeftSiblings()
Gets all the left siblings from this nodejava.util.Collection<SimpleTreeNode<T,K>>
getAllRightSiblings()
Gets all the right siblings from this nodejava.util.Collection<SimpleTreeNode<T,K>>
getAllSiblings()
Gets all the siblings from this nodejava.util.Collection<SimpleTreeNode<T,K>>
getChildren()
Gets the childrenint
getLevel()
Returns the distance from the root to this node.SimpleTreeNode<T,K>
getRoot()
Gets the rootSimpleTreeNode
objectboolean
hasLeftMostChild()
Checks if this node has a left most childboolean
hasParent()
Checks if this node has a parentboolean
hasRightSibling()
Checks if this node has a right siblingboolean
isRoot()
Checks if thisSimpleTreeNode
is the rootSimpleTreeNode
objectjava.util.Collection<SimpleTreeNode<T,K>>
traverse()
Traverse this node and add all descendant with this included in to aSet
-
-
-
Constructor Detail
-
SimpleTreeNode
public SimpleTreeNode(T value)
Instantiates a newSimpleTreeNode
object- Parameters:
value
- the value
-
-
Method Detail
-
getLevel
public 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.
-
getRoot
public SimpleTreeNode<T,K> getRoot()
Gets the rootSimpleTreeNode
object- Returns:
- the root
SimpleTreeNode
object
-
isRoot
public boolean isRoot()
Checks if thisSimpleTreeNode
is the rootSimpleTreeNode
object- Returns:
- true, if this
SimpleTreeNode
is the rootSimpleTreeNode
object
-
getAllSiblings
public java.util.Collection<SimpleTreeNode<T,K>> getAllSiblings()
Gets all the siblings from this node- Returns:
- all the siblings from this node
-
getAllLeftSiblings
public java.util.Collection<SimpleTreeNode<T,K>> getAllLeftSiblings()
Gets all the left siblings from this node- Returns:
- all the left siblings from this node
-
getAllRightSiblings
public java.util.Collection<SimpleTreeNode<T,K>> getAllRightSiblings()
Gets all the right siblings from this node- Returns:
- all the right siblings from this node
-
hasParent
public boolean hasParent()
Checks if this node has a parent- Returns:
- true, if successful
-
hasRightSibling
public boolean hasRightSibling()
Checks if this node has a right sibling- Returns:
- true, if successful
-
hasLeftMostChild
public boolean hasLeftMostChild()
Checks if this node has a left most child- Returns:
- true, if successful
-
traverse
public java.util.Collection<SimpleTreeNode<T,K>> traverse()
Traverse this node and add all descendant with this included in to aSet
- Returns:
- a
Set
with this node and add all descendant
-
getChildren
public java.util.Collection<SimpleTreeNode<T,K>> getChildren()
Gets the children- Returns:
- the children
-
accept
public void accept(io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<T,K>> visitor)
- Specified by:
accept
in interfaceio.github.astrapi69.design.pattern.visitor.Acceptable<T>
-
-