Interface TreeNode<T>

Type Parameters:
T - The type of value stored in this tree node
All Superinterfaces:
Visitable<T>
All Known Implementing Classes:
ImmutableTreeNode, MutableTreeNode

public interface TreeNode<T> extends Visitable<T>
An interface representing a node in a binary tree.

It extends the Visitable interface, ensuring that all tree nodes can accept a visitor. A TreeNode can be implemented to be either mutable or immutable.

  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the reference to the left child of this tree node.
    Returns the reference to the right child of this tree node.
    Returns the object stored in this tree node.
    default boolean
    Returns whether this TreeNode is a leaf node, i.e.
    withLeft(TreeNode<T> newLeft)
    Returns a same instance with a specified new left child.
    withRight(TreeNode<T> newRight)
    Returns a same instance with a specified new right child.

    Methods inherited from interface io.openml.gearbox.binarytree.Visitable

    accept
  • Method Details

    • getValue

      T getValue()
      Returns the object stored in this tree node.
      Returns:
      an object stored in this tree node
    • getLeft

      TreeNode<T> getLeft()
      Returns the reference to the left child of this tree node.
      Returns:
      the left child of this tree node, or null if there is no left child
    • getRight

      TreeNode<T> getRight()
      Returns the reference to the right child of this tree node.
      Returns:
      the right child of this tree node, or null if there is no right child
    • withLeft

      TreeNode<T> withLeft(TreeNode<T> newLeft)
      Returns a same instance with a specified new left child.
      Parameters:
      newLeft - The provided new left child
      Returns:
      a new TreeNode instance
    • withRight

      TreeNode<T> withRight(TreeNode<T> newRight)
      Returns a same instance with a specified new right child.
      Parameters:
      newRight - The provided new right child
      Returns:
      a new TreeNode instance
    • isLeaf

      default boolean isLeaf()
      Returns whether this TreeNode is a leaf node, i.e. both left and right subtrees are null
      Returns:
      true if the node is a leaf