Class MutableTreeNode<T>

java.lang.Object
io.openml.gearbox.binarytree.MutableTreeNode<T>
Type Parameters:
T - The type of value stored in this tree node
All Implemented Interfaces:
TreeNode<T>, Visitable<T>

public final class MutableTreeNode<T> extends Object implements TreeNode<T>
MutableTreeNode saves the memory footprint of TreeNode and is suitable for the performance intensive application. It also represents a concrete 'Element', i.e. Visitable.

As a mutable implementation of a TreeNode. Its value and children can be modified after creation.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(Visitor<T> visitor)
    The entry point for the visitor to perform its operations on this object.
    static <T> TreeNode<T>
    Creates a dummy node with null value, null left subtree, and null right subtree.
    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.
    void
    Mutates the left child of this node with a specified left subtree.
    void
    Mutates the right child of this node with a specified lrighteft subtree.
    void
    setValue(T value)
    Mutates the value this node with a specified new one.
    static <T> TreeNode<T>
    value(T value)
    Creates a new TreeNode with the specified node value.
    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 class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

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

    isLeaf
  • Method Details

    • emptyNode

      public static <T> TreeNode<T> emptyNode()
      Creates a dummy node with null value, null left subtree, and null right subtree.

      This would be a useful method for implementing algorithm that makes use of some auxiliary TreeNode.

      Type Parameters:
      T - Not used
      Returns:
      a new TreeNode instance that is assignable to any instantiated generic TreeNode
    • value

      public static <T> TreeNode<T> value(T value)
      Creates a new TreeNode with the specified node value.

      The left and right subtrees of this node are default to null.

      Type Parameters:
      T - The type of value store in the node
      Parameters:
      value - The provided node value, can be null
      Returns:
      a new TreeNode instance
      Throws:
      NullPointerException - if the value is null
    • setLeft

      public void setLeft(TreeNode<T> left)
      Mutates the left child of this node with a specified left subtree.
      Parameters:
      left - The provided left subtree; can be null
    • setRight

      public void setRight(TreeNode<T> right)
      Mutates the right child of this node with a specified lrighteft subtree.
      Parameters:
      right - The provided right subtree; can be null
    • setValue

      public void setValue(T value)
      Mutates the value this node with a specified new one.
      Parameters:
      value - The provided new value; can be null
    • accept

      public void accept(Visitor<T> visitor)
      Description copied from interface: Visitable
      The entry point for the visitor to perform its operations on this object.
      Specified by:
      accept in interface Visitable<T>
      Parameters:
      visitor - The visitor that will process this visitable object.
    • withLeft

      public TreeNode<T> withLeft(TreeNode<T> newLeft)
      Description copied from interface: TreeNode
      Returns a same instance with a specified new left child.
      Specified by:
      withLeft in interface TreeNode<T>
      Parameters:
      newLeft - The provided new left child
      Returns:
      a new TreeNode instance
    • withRight

      public TreeNode<T> withRight(TreeNode<T> newRight)
      Description copied from interface: TreeNode
      Returns a same instance with a specified new right child.
      Specified by:
      withRight in interface TreeNode<T>
      Parameters:
      newRight - The provided new right child
      Returns:
      a new TreeNode instance
    • getValue

      public T getValue()
      Description copied from interface: TreeNode
      Returns the object stored in this tree node.
      Specified by:
      getValue in interface TreeNode<T>
      Returns:
      an object stored in this tree node
    • getLeft

      public TreeNode<T> getLeft()
      Description copied from interface: TreeNode
      Returns the reference to the left child of this tree node.
      Specified by:
      getLeft in interface TreeNode<T>
      Returns:
      the left child of this tree node, or null if there is no left child
    • getRight

      public TreeNode<T> getRight()
      Description copied from interface: TreeNode
      Returns the reference to the right child of this tree node.
      Specified by:
      getRight in interface TreeNode<T>
      Returns:
      the right child of this tree node, or null if there is no right child