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 TypeMethodDescriptionvoidaccept(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 childrenintgetLevel()Returns the distance from the root to this node.getRoot()Gets the rootSimpleTreeNodeobjectbooleanChecks if this node has a left most childbooleanChecks if this node has a parentbooleanChecks if this node has a right siblingbooleanisNode()Checks if thisSimpleTreeNodeobject is a nodebooleanisRoot()Checks if thisSimpleTreeNodeis the rootSimpleTreeNodeobjecttraverse()Traverse this node and add all descendants with this included in to aSet
-
Constructor Details
-
SimpleTreeNode
Instantiates a newSimpleTreeNodeobject- 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 rootSimpleTreeNodeobject- Returns:
- the root
SimpleTreeNodeobject
-
isRoot
public boolean isRoot()Checks if thisSimpleTreeNodeis the rootSimpleTreeNodeobject- Returns:
- true, if this
SimpleTreeNodeis the rootSimpleTreeNodeobject
-
isNode
public boolean isNode()Checks if thisSimpleTreeNodeobject is a node- Returns:
- true, if this
SimpleTreeNodeobject 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
Setwith this node and add all descendants
-
getChildren
Gets the children- Returns:
- the children
-
accept
- Specified by:
acceptin interfaceio.github.astrapi69.design.pattern.visitor.Acceptable<V>
-