Module gen.tree

Interface ITreeNode<V,​T extends ITreeNode<V,​T>>

  • Type Parameters:
    V - the generic type of the value
    T - the generic type of the concrete tree node
    All Superinterfaces:
    io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<T>>, io.github.astrapi69.tree.api.ITree<V,​T>, java.io.Serializable
    All Known Subinterfaces:
    IBaseTreeNode<V,​K,​T>
    All Known Implementing Classes:
    BaseTreeNode, TreeNode

    public interface ITreeNode<V,​T extends ITreeNode<V,​T>>
    extends io.github.astrapi69.tree.api.ITree<V,​T>, io.github.astrapi69.design.pattern.visitor.Acceptable<io.github.astrapi69.design.pattern.visitor.Visitor<T>>
    The Interface ITreeNode holds the children in a Collection object
    • Method Summary

      All Methods Instance Methods Default Methods 
      Modifier and Type Method Description
      default void accept​(@NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)
      default void addChild​(T child)
      Adds the given child
      default void addChildren​(@NonNull java.util.Collection<T> children)
      Adds all the given children
      default void clearAll()
      Removes all the descendants
      default void clearChildren()
      Removes all the children
      default boolean contains​(T treeNode)
      Checks if the given ITreeNode object is a descendant of this tree node
      default boolean containsAll​(@NonNull java.util.Collection<T> treeNodes)
      Checks if the given Collection object of ITreeNode objects are descendants of this tree node
      default java.util.Collection<T> findAllByValue​(V value)
      Find all ITreeNode objects that have the same value as the given value
      default T findByValue​(V value)
      Find all ITreeNode objects that have the same value as the given value
      default java.util.Collection<T> getAllSiblings()
      Returns all siblings of this node in the parent's children list.
      default int getChildCount()
      Gets the child count.
      default int getLevel()
      Returns the distance from the root to this node.
      default T getNextSibling()
      Returns the next sibling of this node in the parent's children list.
      default T getPreviousSibling()
      Returns the previous sibling of this node in the parent's children list.
      default T getRoot()
      Gets the root object
      default boolean hasChildren()
      Checks for children.
      default boolean hasParent()
      Checks for parent
      default boolean isNode()
      Checks if is node.
      default boolean isRoot()
      Checks if this ITreeNode is the root ITreeNode object
      default void removeChild​(T child)
      Removes the child.
      default void removeChildren()
      Removes all the children
      default void removeChildren​(@NonNull java.util.Collection<T> children)
      Removes all the given children
      default java.util.List<T> toList()
      Traverse this node and adds all descendant with this included in to a List object
      default java.util.Collection<T> traverse()
      Traverse this node and adds all descendant with this included in to a Collection object
      • Methods inherited from interface io.github.astrapi69.tree.api.ITree

        getChildren, getDisplayValue, getParent, getValue, isLeaf, setChildren, setDisplayValue, setLeaf, setParent, setValue
    • Method Detail

      • addChild

        default void addChild​(T child)
        Adds the given child
        Specified by:
        addChild in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        child - the child
      • addChildren

        default void addChildren​(@NonNull
                                 @NonNull java.util.Collection<T> children)
        Adds all the given children
        Specified by:
        addChildren in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        children - the children to add
      • getAllSiblings

        default java.util.Collection<T> getAllSiblings()
        Returns all siblings of this node in the parent's children list. Returns null if this node is the root.
        Specified by:
        getAllSiblings in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        Returns all siblings of this node or null if this node is the root.
      • getPreviousSibling

        default T getPreviousSibling()
        Returns the previous sibling of this node in the parent's children list. Returns null if this node is the root or is the parent's first child.
        Specified by:
        getPreviousSibling in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        the next sibling of this node or null if this node is the root or is the parent's last child.
      • getNextSibling

        default T getNextSibling()
        Returns the next sibling of this node in the parent's children list. Returns null if this node is the root or is the parent's last child.
        Specified by:
        getNextSibling in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        the next sibling of this node or null if this node is the root or is the parent's last child.
      • getChildCount

        default int getChildCount()
        Gets the child count.
        Specified by:
        getChildCount in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        the child count
      • getLevel

        default int getLevel()
        Returns the distance from the root to this node. Returns 0 if this node is the root.
        Specified by:
        getLevel in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        the level from this node.
      • getRoot

        default T getRoot()
        Gets the root object
        Specified by:
        getRoot in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        the root object
      • hasChildren

        default boolean hasChildren()
        Checks for children.
        Specified by:
        hasChildren in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        true, if successful
      • hasParent

        default boolean hasParent()
        Checks for parent
        Specified by:
        hasParent in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        true, if successful
      • isNode

        default boolean isNode()
        Checks if is node.
        Specified by:
        isNode in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        true, if is node
      • isRoot

        default boolean isRoot()
        Checks if this ITreeNode is the root ITreeNode object
        Specified by:
        isRoot in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        true, if this ITreeNode is the root ITreeNode object
      • removeChild

        default void removeChild​(T child)
        Removes the child.
        Specified by:
        removeChild in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        child - the child
      • clearChildren

        default void clearChildren()
        Removes all the children
        Specified by:
        clearChildren in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
      • clearAll

        default void clearAll()
        Removes all the descendants
        Specified by:
        clearAll in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
      • removeChildren

        default void removeChildren()
        Removes all the children
        Specified by:
        removeChildren in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
      • removeChildren

        default void removeChildren​(@NonNull
                                    @NonNull java.util.Collection<T> children)
        Removes all the given children
        Specified by:
        removeChildren in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        children - the children to remove
      • accept

        default void accept​(@NonNull
                            @NonNull io.github.astrapi69.design.pattern.visitor.Visitor<T> visitor)
        Specified by:
        accept in interface io.github.astrapi69.design.pattern.visitor.Acceptable<V>
      • findAllByValue

        default java.util.Collection<T> findAllByValue​(V value)
        Find all ITreeNode objects that have the same value as the given value
        Specified by:
        findAllByValue in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        value - the value for the search process
        Returns:
        a Collection object with all found occurrences that have the same value as the given value
      • findByValue

        default T findByValue​(@NonNull
                              V value)
        Find all ITreeNode objects that have the same value as the given value
        Specified by:
        findByValue in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        value - the value for the search process
        Returns:
        a Collection object with all found occurrences that have the same value as the given value
      • contains

        default boolean contains​(T treeNode)
        Checks if the given ITreeNode object is a descendant of this tree node
        Specified by:
        contains in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        treeNode - the tree node to check
        Returns:
        true if the given ITreeNode object is a descendant of this tree node otherwise false
      • containsAll

        default boolean containsAll​(@NonNull
                                    @NonNull java.util.Collection<T> treeNodes)
        Checks if the given Collection object of ITreeNode objects are descendants of this tree node
        Specified by:
        containsAll in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Parameters:
        treeNodes - the children to add
        Returns:
        true if the given Collection object of ITreeNode objects are descendants of this tree node otherwise false
      • toList

        default java.util.List<T> toList()
        Traverse this node and adds all descendant with this included in to a List object
        Specified by:
        toList in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        a List object with this node and add all descendant
      • traverse

        default java.util.Collection<T> traverse()
        Traverse this node and adds all descendant with this included in to a Collection object
        Specified by:
        traverse in interface io.github.astrapi69.tree.api.ITree<V,​T extends ITreeNode<V,​T>>
        Returns:
        a Collection object with this node and add all descendant