Interface TreeNode

    • Method Detail

      • getRoot

        TreeNode getRoot()
        Get the root of the tree
        Returns:
        root node
      • getParent

        TreeNode getParent()
        Get the parent of this node
        Returns:
        parent node
      • addChild

        void addChild​(TreeNode child)
        Add a child node below this node. Children are registered in the order in which they are added.

        Important: this also automatically creates a link in the opposite direction. All implementations must adhere to this rule.

        Parameters:
        child - child node
      • getChildren

        List<TreeNode> getChildren()
        Get all child nodes of this node
        Returns:
        child nodes
      • getChild

        TreeNode getChild​(int index)
        Get child node by position in the list of siblings. The position depends on the order in which the children were added.
        Parameters:
        index - position in the list of siblings
        Returns:
        child node at position
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index ≥ size())
      • isRoot

        boolean isRoot()
        Check whether this node is the root of the tree.
        Returns:
        true if this node is the root
      • isChild

        boolean isChild()
        Check whether this node is a child node
        Returns:
        true if the node is a child of another node
      • isFirstSibling

        boolean isFirstSibling()
        Check whether a child is the first in the list of siblings
        Returns:
        true if the child is the first in the list of siblings
      • isSibling

        boolean isSibling​(TreeNode node)
        Check whether this node is a sibling of the second node.
        Parameters:
        node - second node
        Returns:
        true if two nodes are siblings
      • setParent

        void setParent​(TreeNode parent)
        Set a parent for this node.
        Parameters:
        parent - a node to set as a parent