Class ListTreeNode<T>

  • Type Parameters:
    T - the label type
    All Implemented Interfaces:
    TreeNode<T>

    @NotThreadSafe
    public class ListTreeNode<T>
    extends Object
    implements TreeNode<T>
    Implementation of a tree node that uses an array list for its children.
    • Constructor Detail

      • ListTreeNode

        public ListTreeNode​(T label)
    • Method Detail

      • getLabel

        public T getLabel()
        Description copied from interface: TreeNode
        Gets this node's label.
        Specified by:
        getLabel in interface TreeNode<T>
        Returns:
        the label; allowing null depends on the implementation
      • children

        public Iterable<TreeNode<T>> children()
        Description copied from interface: TreeNode
        Gets an iterable of this node's children
        Specified by:
        children in interface TreeNode<T>
        Returns:
        an iterable of this node's children; never null
      • getLevel

        public int getLevel()
        Description copied from interface: TreeNode
        Gets the level, which is the distance to the root. The level of the root node is zero.
        Specified by:
        getLevel in interface TreeNode<T>
        Returns:
        the level
      • getChildCount

        public int getChildCount()
        Description copied from interface: TreeNode
        Gets the count of this node's children.
        Specified by:
        getChildCount in interface TreeNode<T>
        Returns:
        the child count
      • getParent

        public TreeNode<T> getParent()
        Description copied from interface: TreeNode
        Gets this node's parent.
        Specified by:
        getParent in interface TreeNode<T>
        Returns:
        this node's parent node, or null if this is the root node
      • setParent

        public TreeNode<T> setParent​(TreeNode<T> parent)
        Description copied from interface: TreeNode
        Sets the parent of a given node.
        Specified by:
        setParent in interface TreeNode<T>
        Parameters:
        parent - the parent, or null to remove existing parent
        Returns:
        the old parent, or null if no parent had been set
      • addChild

        public ListTreeNode<T> addChild​(TreeNode<T> child)
        Description copied from interface: TreeNode
        Adds a child to this node's children. Returns this instance (to facilitate chaining).
        Specified by:
        addChild in interface TreeNode<T>
        Parameters:
        child - the child to add
        Returns:
        this instance
      • isRoot

        public boolean isRoot()
        Description copied from interface: TreeNode
        Checks whether this node is the root node of a tree.
        Specified by:
        isRoot in interface TreeNode<T>
        Returns:
        true iff this node is the root node, meaning it has no parent
      • breadthFirstTraversal

        public TreeNode.NodeTraversal<T> breadthFirstTraversal()
        Description copied from interface: TreeNode
        Gets an iterable that provides a breadth-first iteration of nodes in the tree rooted at this node. The iteration includes this node.
        Specified by:
        breadthFirstTraversal in interface TreeNode<T>
        Returns:
        an iterable
      • isLeaf

        public boolean isLeaf()
        Description copied from interface: TreeNode
        Checks whether this node is a leaf node. Leaf nodes have no children.
        Specified by:
        isLeaf in interface TreeNode<T>
        Returns:
        true iff this node is a leaf node