Package org.parboiled.trees
Class TreeUtils
- java.lang.Object
-
- org.parboiled.trees.TreeUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 Detail
-
getRoot
public static <T extends TreeNode<T>> T getRoot(T node)
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
public static <T extends MutableTreeNode<T>> void addChild(T parent, T child)
Adds a new child node to a given MutableTreeNode parent.- Parameters:
parent
- the parent nodechild
- the child node to add
-
removeChild
public static <T extends MutableTreeNode<T>> void removeChild(T parent, T child)
Removes the given child from the given parent node.- Parameters:
parent
- the parent nodechild
- the child node
-
toLeftAssociativity
public static <N extends MutableBinaryTreeNode<N>> N toLeftAssociativity(N node)
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
-
-