Package io.openml.gearbox.binarytree
Class ImmutableTreeNode<T>
java.lang.Object
io.openml.gearbox.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 TypeMethodDescriptionvoid
The entry point for the visitor to perform its operations on this object.static <T> TreeNode<T>
Creates a dummy node withnull
value,null
left subtree, andnull
right subtree.boolean
getLeft()
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.int
hashCode()
toString()
Returns a string representation of thisTreeNode
.static <T> TreeNode<T>
value
(T value) Creates a newTreeNode
with the specified node value.static <T> TreeNode<T>
valueWithLeft
(T value, TreeNode<T> left) Creates a newTreeNode
with the specified node value and a left subtree.static <T> TreeNode<T>
valueWithLeftAndRight
(T value, TreeNode<T> left, TreeNode<T> right) Private all-args constructor that is to be shared across all static factor methods.static <T> TreeNode<T>
valueWithRight
(T value, TreeNode<T> right) Creates a newTreeNode
with 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 withnull
value,null
left subtree, andnull
right subtree.This would be a useful method for implementing algorithm that makes use of some auxiliary
TreeNode
. -
value
Creates a newTreeNode
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 benull
- Returns:
- a new
TreeNode
instance - Throws:
NullPointerException
- if thevalue
isnull
-
valueWithLeft
Creates a newTreeNode
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 valueleft
- The provided left subtree- Returns:
- a new
TreeNode
instance - Throws:
NullPointerException
- if thevalue
orleft
isnull
-
valueWithRight
Creates a newTreeNode
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 valueright
- The provided right subtree- Returns:
- a new
TreeNode
instance - Throws:
NullPointerException
- if thevalue
orright
isnull
-
valueWithLeftAndRight
Private all-args constructor that is to be shared across all static factor methods. -
accept
Description copied from interface:Visitable
The entry point for the visitor to perform its operations on this object. -
withLeft
Returns a same instance with a specified new left child. -
withRight
Returns a same instance with a specified new right child. -
getValue
Description copied from interface:TreeNode
Returns the object stored in this tree node. -
getLeft
Description copied from interface:TreeNode
Returns the reference to the left child of this tree node. -
getRight
Description copied from interface:TreeNode
Returns the reference to the right child of this tree node. -
equals
-
hashCode
public int hashCode() -
toString
Returns a string representation of thisTreeNode
.The string is the same thing as
getValue()
for simplicity.- Overrides:
toString
in classObject
- Returns:
- node value's
Object.toString()
-