- 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 classSimpleTreeNodeholds only the parent, the left most child and the right sibling
-
-
Constructor Summary
Constructors Constructor Description SimpleTreeNode(T value)Instantiates a newSimpleTreeNodeobject
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(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 childrenintgetLevel()Returns the distance from the root to this node.SimpleTreeNode<T,K>getRoot()Gets the rootSimpleTreeNodeobjectbooleanhasLeftMostChild()Checks if this node has a left most childbooleanhasParent()Checks if this node has a parentbooleanhasRightSibling()Checks if this node has a right siblingbooleanisNode()Checks if thisSimpleTreeNodeobject is a nodebooleanisRoot()Checks if thisSimpleTreeNodeis the rootSimpleTreeNodeobjectjava.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 newSimpleTreeNodeobject- 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 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
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
Setwith 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:
acceptin interfaceio.github.astrapi69.design.pattern.visitor.Acceptable<T>
-
-