Package com.singularsys.extensions.xjep
Class TreeUtils
java.lang.Object
com.singularsys.extensions.xjep.TreeUtils
- All Implemented Interfaces:
JepComponent,Serializable
- Direct Known Subclasses:
FieldTreeUtils
A set of Utility functions for working with Jep expression trees.
Main methods are
-
isConstanttest if its a constant. Many other is... methods.
- Author:
- rich
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomplexValue(Object val) static Node[]getChildrenAsArray(Node node) returns the children of a node as an array of nodes.getCI()Complex imaginary unitComplex minus iComplex minus onegetCOne()Complex onegetCZero()Complex zerogetFalse()The value used to represent a False ASTconstant value.intgetIntValue(Object val) Value of an ASTConstant node cast to an Integer should only be used ifisIntegerVal(Object)returns true.Gets a light-weight instance suitable for using in multiple threads.Number representing -1getNAN()Number representing NaNNumber representing +InftygetOne()Number representing oneNumber representing +InftygetTrue()The value used to represent a True ASTconstant value.getTwo()Number representing twogetZero()Number representing zerobooleanWhether we have a working value for +/- InfinitybooleanhasNaN()Whether we have a working value for NaNvoidInitialize the component.intValue of an ASTConstant node cast to an Integer should only be used if isInteger returns true.booleanisBinaryOperator(Node node) Returns true if node represents a binary operatorbooleanreturns true if node is an ASTConstant of type ComplexbooleanisComplexVal(Object val) Test a value for being complex.booleanisConstant(Node node) returns true if node is an ASTConstantbooleanisConstantVariable(Node node) returns true if node is an ASTVarNode with a constant variablebooleanisFunction(Node node) returns true if node is an ASTFunNodebooleanisInfinity(Node node) returns true if node is a ASTConstant with a Infinite componentbooleanisInfinityVal(Object val) Test a value for being infinite.booleanreturn true is the node is an ASTConstant with a value which is integral like 1.0.booleanisIntegerVal(Object val) Test a value for being an integer.booleanisMinusOne(Node node) returns true if node is a ASTConstant with value Double(-1) or Complex(-1,0)booleanisMinusOneVal(Object val) Test a value for being minus one.booleanreturns true if node is a ASTConstant with a NaN componentbooleanTest a value for being NaN.booleanisNegative(Node node) returns true if node is an ASTConstant with a negative valueisNegativeVal(Object)booleanisNegativeVal(Object val) Test a value for being negative.booleanreturns true if node is a ASTConstant with value Double(1) or Complex(1,0)booleanTest a value for being one.booleanisOperator(Node node) returns true if node is an ASTOpNodebooleanisPositive(Node node) returns true if node is an ASTConstant with a positive Number valuebooleanisPositiveVal(Object val) Test a value for being positive.booleanreturns true if node is a ASTConstant with Number valuebooleanbooleanisUnaryOperator(Node node) Returns true if node represents a unary operatorbooleanisVariable(Node node) returns true if node is an ASTVarNodebooleanreturns true if node is a ASTConstant with value Double(0) or Complex(0,0)booleanTest a value for being zero.static NodesetChildrenIfNeeded(Node node, Node[] children) Sets the children of a node if they have changed for its current children.
-
Constructor Details
-
TreeUtils
Standalone constructor with supplied NumberFactory- Parameters:
nf-
-
TreeUtils
public TreeUtils()Constructor when used as a Jep component. The NumberFactory is set using theinit(Jep)method -
TreeUtils
-
-
Method Details
-
isReal
returns true if node is a ASTConstant with Number value -
isRealVal
-
isZero
returns true if node is a ASTConstant with value Double(0) or Complex(0,0) -
isZeroVal
Test a value for being zero. This implementation test for Double 0 using ==, or Complex 0.- Parameters:
val- value to test- Returns:
- true in value is zero false otherwise
-
isOne
returns true if node is a ASTConstant with value Double(1) or Complex(1,0) -
isOneVal
Test a value for being one. This implementation test for Double 1 or Complex 1.- Parameters:
val- value to test- Returns:
- true in value is one false otherwise
-
isMinusOne
returns true if node is a ASTConstant with value Double(-1) or Complex(-1,0) -
isMinusOneVal
Test a value for being minus one. This implementation test for Double -1 or Complex -1.- Parameters:
val- value to test- Returns:
- true in value is -1 false otherwise
-
isInfinity
returns true if node is a ASTConstant with a Infinite component -
isInfinityVal
Test a value for being infinite. This implementation test for Double infinite or Complex infinite- Parameters:
val- value to test- Returns:
- true in value is infinite false otherwise
-
isNaN
returns true if node is a ASTConstant with a NaN component -
isNaNVal
Test a value for being NaN. This implementation test for Double NaN or Complex NaN.- Parameters:
val- value to test- Returns:
- true in value is zero false otherwise
-
isNegative
returns true if node is an ASTConstant with a negative valueisNegativeVal(Object) -
isNegativeVal
Test a value for being negative. This implementation test for Numbers. Complex values of the form(x + i0)withx<0are considered negative- Parameters:
val- value to test- Returns:
- true in value is negative false otherwise
-
isPositive
returns true if node is an ASTConstant with a positive Number value -
isPositiveVal
Test a value for being positive. This implementation test for Numbers. Complex numbers of the form(x + i0)wherex>0are considered positive.- Parameters:
val- value to test- Returns:
- true in value is positive false otherwise
-
isComplex
returns true if node is an ASTConstant of type Complex -
isComplexVal
Test a value for being complex. This implementation test for value being of type Complex.- Parameters:
val- value to test- Returns:
- true in value is positive false otherwise
-
complexValue
- Throws:
EvaluationException
-
isInteger
return true is the node is an ASTConstant with a value which is integral like 1.0. -
isIntegerVal
Test a value for being an integer. This implementation test for Numbers whose double value and int value are equal. Complex values of the form (n + i 0) are considered to be integers.- Parameters:
val- value to test- Returns:
- true in value is positive false otherwise
-
intValue
Value of an ASTConstant node cast to an Integer should only be used if isInteger returns true.- Parameters:
node-- Returns:
- an integer value identical to the nodes constant
- Throws:
EvaluationException- if the number cannot be converted exactly to an integer
-
getIntValue
Value of an ASTConstant node cast to an Integer should only be used ifisIntegerVal(Object)returns true.- Throws:
EvaluationException- if the number cannot be converted exactly to an integer
-
getTrue
The value used to represent a True ASTconstant value.- Returns:
- Boolean.True
-
getFalse
The value used to represent a False ASTconstant value.- Returns:
- Boolean.False
-
isConstant
returns true if node is an ASTConstant -
isVariable
returns true if node is an ASTVarNode -
isConstantVariable
returns true if node is an ASTVarNode with a constant variable -
isOperator
returns true if node is an ASTOpNode -
isBinaryOperator
Returns true if node represents a binary operator -
isUnaryOperator
Returns true if node represents a unary operator -
isFunction
returns true if node is an ASTFunNode -
setChildrenIfNeeded
Sets the children of a node if they have changed for its current children.- Throws:
ParseException
-
getChildrenAsArray
returns the children of a node as an array of nodes. -
getCI
Complex imaginary unit- Returns:
- Complex(0,1)
-
getCMinusI
Complex minus i- Returns:
- Complex(0,-1)
-
getCMinusOne
Complex minus one- Returns:
- Complex(-1,0)
-
getCOne
Complex one- Returns:
- Complex(1,0)
-
getCZero
Complex zero- Returns:
- Complex(0,0)
-
getZero
Number representing zero- Returns:
- 0.0d
-
getOne
Number representing one- Returns:
- 1.0d
-
getMinusOne
Number representing -1- Returns:
- -1.0d
-
getTwo
Number representing two- Returns:
- 2.0d
-
hasNaN
public boolean hasNaN()Whether we have a working value for NaN- Returns:
-
hasInfinity
public boolean hasInfinity()Whether we have a working value for +/- Infinity- Returns:
-
getNAN
Number representing NaN- Returns:
- Double.NaN or null if
hasNaN()returns false
-
getPositiveInfinity
Number representing +Infty- Returns:
- Double.POSITIVE_INFINITY or null if
hasNaN()returns false
-
getNegativeInfinity
Number representing +Infty- Returns:
- Double.NEGATIVE_INFINITY or null if
hasNaN()returns false
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-