Class ImmutableTreeNode<T>
java.lang.Object
io.openml.gearbox.algorithms.binarytree.ImmutableTreeNode<T>
- Type Parameters:
T- The type of value stored in this tree node
ImmutableTreeNode encapsulates the value, left tree reference, and right tree reference in an immutable
state; it also represents a concrete 'Element', i.e. Visitable.
This is an immutable implementation of a TreeNode. Its value and children are set at creation and cannot be
changed.
-
Method Summary
Modifier and TypeMethodDescriptionvoidThe entry point for the visitor to perform its operations on this object.static <T> TreeNode<T> Creates a dummy node withnullvalue,nullleft subtree, andnullright subtree.booleangetLeft()Returns the reference to the left child of this tree node.getRight()Returns the reference to the right child of this tree node.getValue()Returns the object stored in this tree node.inthashCode()toString()Returns a string representation of thisTreeNode.static <T> TreeNode<T> value(T value) Creates a newTreeNodewith the specified node value.static <T> TreeNode<T> valueWithLeft(T value, TreeNode<T> left) Creates a newTreeNodewith the specified node value and a left subtree.static <T> TreeNode<T> valueWithLeftAndRight(T value, TreeNode<T> left, TreeNode<T> right) Creates a newTreeNodewith the specified node value, a left subtree, and a right subtree.static <T> TreeNode<T> valueWithRight(T value, TreeNode<T> right) Creates a newTreeNodewith the specified node value and a right subtree.Returns a same instance with a specified new left child.Returns a same instance with a specified new right child.
-
Method Details
-
emptyNode
Creates a dummy node withnullvalue,nullleft subtree, andnullright subtree.This would be a useful method for implementing algorithm that makes use of some auxiliary
TreeNode. -
value
Creates a newTreeNodewith 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 benull- Returns:
- a new
TreeNodeinstance - Throws:
NullPointerException- if thevalueisnull
-
valueWithLeft
Creates a newTreeNodewith 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 valueleft- The provided left subtree- Returns:
- a new
TreeNodeinstance - Throws:
NullPointerException- if thevalueorleftisnull
-
valueWithRight
Creates a newTreeNodewith 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 valueright- The provided right subtree- Returns:
- a new
TreeNodeinstance - Throws:
NullPointerException- if thevalueorrightisnull
-
valueWithLeftAndRight
Creates a newTreeNodewith the specified node value, a left subtree, and a right subtree. -
accept
-
withLeft
-
withRight
-
getValue
-
getLeft
-
getRight
-
equals
-
hashCode
-
toString
Returns a string representation of thisTreeNode.The string is the same thing as
getValue()for simplicity.- Overrides:
toStringin classObject- Returns:
- node value's
Object.toString()
-