Class MutableTreeNode<T>

java.lang.Object
io.openml.gearbox.algorithms.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 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
    • valueWithLeft

      public static <T> TreeNode<T> valueWithLeft(T value, TreeNode<T> left)
      Creates a new TreeNode with the specified node value and a left subtree.

      The right subtree of this node is default to null

      Type Parameters:
      T - The type of value store in the node
      Parameters:
      value - The provided node value
      left - The provided left subtree
      Returns:
      a new TreeNode instance
      Throws:
      NullPointerException - if the value or left is null
    • valueWithRight

      public static <T> TreeNode<T> valueWithRight(T value, TreeNode<T> right)
      Creates a new TreeNode with the specified node value and a right subtree.

      The left subtree of this node is default to null

      Type Parameters:
      T - The type of value store in the node
      Parameters:
      value - The provided node value
      right - The provided right subtree
      Returns:
      a new TreeNode instance
      Throws:
      NullPointerException - if the value or right is null
    • valueWithLeftAndRight

      public static <T> TreeNode<T> valueWithLeftAndRight(T value, TreeNode<T> left, TreeNode<T> right)
      Creates a new TreeNode with the specified node value, a left subtree, and a right subtree.
      Type Parameters:
      T - The type of value store in the node
      Parameters:
      value - The value stored in this TreeNode
      left - A reference to the root of left subtree
      right - A reference to the root of the right subtree
      Returns:
      a new TreeNode instance
    • 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