Module gen.tree

Class 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 class SimpleTreeNode holds only the parent, the left most child and the right sibling
    • Constructor Detail

      • SimpleTreeNode

        public SimpleTreeNode​(T value)
        Instantiates a new SimpleTreeNode 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.
      • isNode

        public boolean isNode()
        Checks if this SimpleTreeNode object is a node
        Returns:
        true, if this SimpleTreeNode object 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 a Set
        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 interface io.github.astrapi69.design.pattern.visitor.Acceptable<T>