Package org.parboiled.trees
Class TreeUtils
java.lang.Object
org.parboiled.trees.TreeUtils
General utility methods for operating on tree, i.e. graphs consisting of
TreeNode
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends MutableTreeNode<T>>
voidaddChild
(T parent, T child) Adds a new child node to a given MutableTreeNode parent.static <T extends TreeNode<T>>
TgetRoot
(T node) Returns the root of the tree the given node is part of.static <T extends MutableTreeNode<T>>
voidremoveChild
(T parent, T child) Removes the given child from the given parent node.static <N extends MutableBinaryTreeNode<N>>
NtoLeftAssociativity
(N node) Performs the following transformation on the given MutableBinaryTreeNode:
-
Method Details
-
getRoot
Returns the root of the tree the given node is part of.- Parameters:
node
- the node to get the root of- Returns:
- the root or null if the given node is null
-
addChild
Adds a new child node to a given MutableTreeNode parent.- Parameters:
parent
- the parent nodechild
- the child node to add
-
removeChild
Removes the given child from the given parent node.- Parameters:
parent
- the parent nodechild
- the child node
-
toLeftAssociativity
Performs the following transformation on the given MutableBinaryTreeNode:o1 o2 / \ / \ A o2 ====> o1 C / \ / \ B C A B
- Parameters:
node
- the node to transform- Returns:
- the new root after the transformation, which is either the right sub node of the original root or the original root, if the right sub node is null
-