Interface TreeNode<T>

  • Type Parameters:
    T - node label type
    All Known Implementing Classes:
    ListTreeNode

    public interface TreeNode<T>
    Interface that represents a node in a tree data structure. Nodes of this type are aware of their parents and children.
    • Method Detail

      • children

        Iterable<TreeNode<T>> children()
        Gets an iterable of this node's children
        Returns:
        an iterable of this node's children; never null
      • breadthFirstTraversal

        TreeNode.NodeTraversal<T> breadthFirstTraversal()
        Gets an iterable that provides a breadth-first iteration of nodes in the tree rooted at this node. The iteration includes this node.
        Returns:
        an iterable
      • getLevel

        int getLevel()
        Gets the level, which is the distance to the root. The level of the root node is zero.
        Returns:
        the level
      • getChildCount

        int getChildCount()
        Gets the count of this node's children.
        Returns:
        the child count
      • getParent

        TreeNode<T> getParent()
        Gets this node's parent.
        Returns:
        this node's parent node, or null if this is the root node
      • setParent

        TreeNode<T> setParent​(TreeNode<T> parent)
        Sets the parent of a given node.
        Parameters:
        parent - the parent, or null to remove existing parent
        Returns:
        the old parent, or null if no parent had been set
      • isRoot

        boolean isRoot()
        Checks whether this node is the root node of a tree.
        Returns:
        true iff this node is the root node, meaning it has no parent
      • getLabel

        T getLabel()
        Gets this node's label.
        Returns:
        the label; allowing null depends on the implementation
      • addChild

        TreeNode<T> addChild​(TreeNode<T> child)
        Adds a child to this node's children. Returns this instance (to facilitate chaining).
        Parameters:
        child - the child to add
        Returns:
        this instance
      • isLeaf

        boolean isLeaf()
        Checks whether this node is a leaf node. Leaf nodes have no children.
        Returns:
        true iff this node is a leaf node