Package com.igormaznitsa.jcp.expression
Class ExpressionTreeElement
- java.lang.Object
-
- com.igormaznitsa.jcp.expression.ExpressionTreeElement
-
public class ExpressionTreeElement extends java.lang.Object
The class describes a wrapper around an expression item to be saved into an expression tree
-
-
Field Summary
Fields Modifier and Type Field Description private ExpressionTreeElement[]
childElements
The array contains links to the tree element childrenprivate static ExpressionTreeElement[]
EMPTY
Empty array to avoid unnecessary operationsstatic ExpressionTreeElement
EMPTY_SLOT
private FilePositionInfo[]
includeStack
Current include stack of the preprocessor to the source string.private int
nextChildSlot
Because I fill children sequentially, the variable contains the index of the first empty child slotprivate static OperatorSUB
OPERATOR_SUB
Inside constant to be used for speed up some operationsprivate ExpressionTreeElement
parentTreeElement
The link to the parent element, if it is the tree root then it contains nullprivate int
priority
The priority of the tree element, it is very strongly used during tree sortingprivate ExpressionItem
savedItem
The variable contains the wrapped expression itemprivate java.lang.String
sourceString
Contains the source string for the expression.
-
Constructor Summary
Constructors Modifier Constructor Description private
ExpressionTreeElement()
(package private)
ExpressionTreeElement(ExpressionItem item, FilePositionInfo[] callStack, java.lang.String sourceString)
The constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addElementToNextFreeSlot(ExpressionTreeElement element)
Add an expression element into the next free child slotExpressionTreeElement
addSubTree(ExpressionTree tree)
Add a tree as new child and make the maximum priority for itExpressionTreeElement
addTreeElement(ExpressionTreeElement element)
Add tree element with sorting operation depends on priority of the elementsprivate void
assertNotEmptySlot()
void
fillArguments(java.util.List<ExpressionTree> arguments)
It fills children slots from a list containing expression treesint
getArity()
Get arity for the element (I mean possible children number)ExpressionTreeElement
getChildForIndex(int index)
Get the child element for its index (the first is 0)ExpressionItem
getItem()
Get the wrapped itemExpressionTreeElement
getParent()
Get the parent for the elementint
getPriority()
Get the current priority of the elementboolean
isEmptySlot()
Allows to check that the element is EMPTY_SLOTboolean
isFull()
It allows to check that all children slots have been filled(package private) void
makeMaxPriority()
Inside auxiliary function to set the maximum priority the the elementvoid
postProcess()
Post-processing after the tree is formed, the unary minus operation will be optimizedboolean
replaceElement(ExpressionTreeElement oldOne, ExpressionTreeElement newOne)
It replaces a child element
-
-
-
Field Detail
-
OPERATOR_SUB
private static final OperatorSUB OPERATOR_SUB
Inside constant to be used for speed up some operations
-
EMPTY_SLOT
public static final ExpressionTreeElement EMPTY_SLOT
-
EMPTY
private static final ExpressionTreeElement[] EMPTY
Empty array to avoid unnecessary operations
-
savedItem
private ExpressionItem savedItem
The variable contains the wrapped expression item
-
childElements
private ExpressionTreeElement[] childElements
The array contains links to the tree element children
-
parentTreeElement
private ExpressionTreeElement parentTreeElement
The link to the parent element, if it is the tree root then it contains null
-
priority
private int priority
The priority of the tree element, it is very strongly used during tree sorting
-
nextChildSlot
private int nextChildSlot
Because I fill children sequentially, the variable contains the index of the first empty child slot
-
sourceString
private final java.lang.String sourceString
Contains the source string for the expression.
-
includeStack
private final FilePositionInfo[] includeStack
Current include stack of the preprocessor to the source string.
-
-
Constructor Detail
-
ExpressionTreeElement
private ExpressionTreeElement()
-
ExpressionTreeElement
ExpressionTreeElement(ExpressionItem item, @MustNotContainNull FilePositionInfo[] callStack, java.lang.String sourceString)
The constructor- Parameters:
item
- an expression item to be wrappedcallStack
- current call stacksourceString
- source string for the expression
-
-
Method Detail
-
isEmptySlot
public boolean isEmptySlot()
Allows to check that the element is EMPTY_SLOT- Returns:
- true if the element is empty slot, false otherwise
-
assertNotEmptySlot
private void assertNotEmptySlot()
-
makeMaxPriority
void makeMaxPriority()
Inside auxiliary function to set the maximum priority the the element
-
getItem
public ExpressionItem getItem()
Get the wrapped item- Returns:
- the item to be wrapped by the object
-
getArity
public int getArity()
Get arity for the element (I mean possible children number)- Returns:
- the arity, zero for elements without children
-
getParent
public ExpressionTreeElement getParent()
Get the parent for the element- Returns:
- the parent for the element or null if the element is the tree root
-
getPriority
public int getPriority()
Get the current priority of the element- Returns:
- the priority
-
addSubTree
public ExpressionTreeElement addSubTree(ExpressionTree tree)
Add a tree as new child and make the maximum priority for it- Parameters:
tree
- a tree to be added as a child, must not be null- Returns:
- it returns this
-
replaceElement
public boolean replaceElement(ExpressionTreeElement oldOne, ExpressionTreeElement newOne)
It replaces a child element- Parameters:
oldOne
- the old expression element to be replaced (must not be null)newOne
- the new expression element to be used instead the old one (must not be null)- Returns:
- true if the element was found and replaced, else false
-
getChildForIndex
public ExpressionTreeElement getChildForIndex(int index)
Get the child element for its index (the first is 0)- Parameters:
index
- the index of the needed child- Returns:
- the child or EMPTY_SLOT
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- it will be thrown if an impossible index is being used- See Also:
EMPTY_SLOT
-
addTreeElement
public ExpressionTreeElement addTreeElement(ExpressionTreeElement element)
Add tree element with sorting operation depends on priority of the elements- Parameters:
element
- the element to be added, must not be null- Returns:
- the element which should be used as the last for the current tree
-
isFull
public boolean isFull()
It allows to check that all children slots have been filled- Returns:
- true if there is not any free child slot else false
-
fillArguments
public void fillArguments(@MustNotContainNull java.util.List<ExpressionTree> arguments)
It fills children slots from a list containing expression trees- Parameters:
arguments
- the list containing trees to be used as children
-
addElementToNextFreeSlot
private void addElementToNextFreeSlot(ExpressionTreeElement element)
Add an expression element into the next free child slot- Parameters:
element
- an element to be added, must not be null
-
postProcess
public void postProcess()
Post-processing after the tree is formed, the unary minus operation will be optimized
-
-