Package examples

Interface TreeNode<E,​T extends TreeNode<E,​?>>

Type Parameters:
E - type of stored elements
T - TreeNode type that is valid to link to

public interface TreeNode<E,​T extends TreeNode<E,​?>>
A node in a binary tree. Each non-leaf ("internal") node stores a single element and links to left, right, and parent nodes. Leaf nodes do not store content or have left or right links. Implementers may choose to represent leaf nodes using null references, or as normal TreeNode instances.
  • Method Summary

    Modifier and Type Method Description
    E getContent()
    Get the value stored in this node.
    T getLeft()
    Get the left child node.
    T getParent()
    Get the parent of this node.
    T getRight()
    Get the right child node.
    boolean isLeaf()
    Returns true if this is a leaf node.
    void setContent​(E value)
    Change the value stored in this node.
    void setLeft​(T child)
    Change the left child to the given node.
    void setParent​(T parent)
    Change the parent of this node.
    void setRight​(T child)
    Change the right child to the given node.
  • Method Details

    • getContent

      E getContent()
      Get the value stored in this node.
      Returns:
      the stored content
      Throws:
      java.lang.UnsupportedOperationException - (optional) if this is a leaf node
    • setContent

      void setContent​(E value)
      Change the value stored in this node.
      Parameters:
      value - new content to store
      Throws:
      java.lang.UnsupportedOperationException - if this is a leaf node
    • getLeft

      T getLeft()
      Get the left child node.
      Returns:
      the left child, or null
      Throws:
      java.lang.UnsupportedOperationException - (optional) if this is a leaf node
    • setLeft

      void setLeft​(T child)
      Change the left child to the given node.
      Parameters:
      child - new left child
      Throws:
      java.lang.UnsupportedOperationException - if this is a leaf node
    • getRight

      T getRight()
      Get the right child node.
      Returns:
      the right child, or null
      Throws:
      java.lang.UnsupportedOperationException - (optional) if this is a leaf node
    • setRight

      void setRight​(T child)
      Change the right child to the given node.
      Parameters:
      child - new right node
      Throws:
      java.lang.UnsupportedOperationException - if this is a leaf node
    • getParent

      T getParent()
      Get the parent of this node. The parent of a leaf node is always a non-leaf node.
      Returns:
      the parent node
    • setParent

      void setParent​(T parent)
      Change the parent of this node.
      Parameters:
      parent - the new parent node
      Throws:
      java.lang.UnsupportedOperationException - if this is a leaf node
    • isLeaf

      boolean isLeaf()
      Returns true if this is a leaf node. Leaf nodes do not hold content and cannot have children. Implementers may choose to represent leaf nodes as null references, in which case this method will always return false.
      Returns:
      true if this is a leaf node; false otherwise