Package io.github.astrapi69.gen.tree
Class SimpleTreeNode<V,K>
java.lang.Object
io.github.astrapi69.gen.tree.SimpleTreeNode<V,K>
- Type Parameters:
V
- the generic type of the valueK
- the generic type of the id of the node
- All Implemented Interfaces:
io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<V,
K>>>
public class SimpleTreeNode<V,K>
extends Object
implements io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<V,K>>>
The generic class
SimpleTreeNode
holds only the parent, the left most child and the right
sibling-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(io.github.astrapi69.design.pattern.visitor.Visitor<SimpleTreeNode<V, K>> visitor) Gets all the left siblings from this nodeGets all the right siblings from this nodeGets all the siblings from this nodeGets the childrenint
getLevel()
Returns the distance from the root to this node.getRoot()
Gets the rootSimpleTreeNode
objectboolean
Checks if this node has a left most childboolean
Checks if this node has a parentboolean
Checks if this node has a right siblingboolean
isNode()
Checks if thisSimpleTreeNode
object is a nodeboolean
isRoot()
Checks if thisSimpleTreeNode
is the rootSimpleTreeNode
objecttraverse()
Traverse this node and add all descendants with this included in to aSet
-
Constructor Details
-
SimpleTreeNode
Instantiates a newSimpleTreeNode
object- Parameters:
value
- the value
-
-
Method Details
-
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
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
-
isNode
public boolean isNode()Checks if thisSimpleTreeNode
object is a node- Returns:
- true, if this
SimpleTreeNode
object is a node otherwise false
-
getAllSiblings
Gets all the siblings from this node- Returns:
- all the siblings from this node
-
getAllLeftSiblings
Gets all the left siblings from this node- Returns:
- all the left siblings from this node
-
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
Traverse this node and add all descendants with this included in to aSet
- Returns:
- a
Set
with this node and add all descendants
-
getChildren
Gets the children- Returns:
- the children
-
accept
- Specified by:
accept
in interfaceio.github.astrapi69.design.pattern.visitor.Acceptable<V>
-