public class Jep
extends java.lang.Object
Create a new JEP
expression with the newJep(String, JepFunction[])
method. If the expression contains variables set values for those with the
JEP.setVarValue(String, Object)
method. Then, evaluate the expression
using the JEP.getValue()
method.
You can also convert the expression to a Query API Expression
object with the jepToExpression(JEP)
method. The conversion
doesn't support all methods since the Query API doesn't have support for
them.
See the JEP homepage for more
information about JEP and all supported functions/operators.
See jepToExpression(JEP)
and jepToRestriction(JEP)
for functions/operators supported by the conversion methods.
Modifier and Type | Field and Description |
---|---|
private static Enumeration<java.lang.String,java.lang.String> |
functions |
private static java.lang.reflect.Field |
jepErrorList |
private static Enumeration<java.lang.String,java.lang.String> |
operators |
Constructor and Description |
---|
Jep() |
Modifier and Type | Method and Description |
---|---|
private static void |
addFunctions(JEP jep,
JepFunction... functions) |
static void |
clearErrorList(JEP jep)
This is a workaround for a bug in the JEP error handling.
|
static Expression |
formulaToExpression(java.lang.String formula,
JepFunction... functions)
Convert JEP expression to a Query API
Expression . |
static Restriction |
formulaToRestriction(java.lang.String formula,
JepFunction... functions)
Convert JEP expression to a Query API
Restriction . |
static Enumeration<java.lang.String,java.lang.String> |
getFunctions()
Get a list of built-in functions supported by the
jepToExpression(JEP)
converter. |
static Enumeration<java.lang.String,java.lang.String> |
getOperators()
Get a list of built-in operators supported by the
jepToExpression(JEP)
and jepToRestriction(JEP) converter. |
static Expression |
jepToExpression(JEP jep)
Convert a JEP expression to a Query API
Expression . |
static Restriction |
jepToRestriction(JEP jep)
Convert a JEP expression to a Query API
Restriction . |
static JEP |
newJep(java.lang.String formula,
JepFunction... functions)
Create a new JEP expression.
|
static Expression |
nodeToExpression(Node node)
Convert a node with it's children to an expression.
|
static int |
nodeToInt(Node node)
Convert a node to an integer value.
|
static Restriction |
nodeToRestriction(Node node)
Convert a node with it's children to a restriction.
|
static java.lang.String |
nodeToString(Node node)
Convert a node to a string value.
|
private static volatile Enumeration<java.lang.String,java.lang.String> functions
private static volatile Enumeration<java.lang.String,java.lang.String> operators
private static java.lang.reflect.Field jepErrorList
public static JEP newJep(java.lang.String formula, JepFunction... functions) throws BaseException
JEP.getValue()
method. Set values for variables
with the JEP.setVarValue(String, Object)
.formula
- The expression to parsefunctions
- Extra functions that are required to parse the
expressionJEP
objectBaseException
- If the expression couldn't be parsedprivate static void addFunctions(JEP jep, JepFunction... functions)
public static Enumeration<java.lang.String,java.lang.String> getFunctions()
jepToExpression(JEP)
converter. More functions can be registered when creating the JEP
expression (see newJep(String, JepFunction[])
).public static Enumeration<java.lang.String,java.lang.String> getOperators()
jepToExpression(JEP)
and jepToRestriction(JEP)
converter. It is not possible to
register more operators.public static Expression jepToExpression(JEP jep) throws BaseException
Expression
. The Query API
only supports a subset of the functions/operators that JEP supports.
Supported operators are:
+= This is a optional function that must be registered when creating the JEP object.Expressions.add(Expression, Expression)
-Expressions.subtract(Expression, Expression)
Expressions.multiply(Expression, Expression)
/Expressions.divide(Expression, Expression)
-Expressions.negate(Expression)
logExpressions.log10(Expression)
log2Expressions.log2(Expression)
lnExpressions.ln(Expression)
sqrtExpressions.sqrt(Expression)
absExpressions.abs(Expression)
expExpressions.exp(Expression)
rawDynamic.rawData(String)
* chDynamic.column(VirtualColumn)
* rawChDynamic.column(VirtualColumn)
* numberExpressions.integer(int)
orExpressions.aFloat(float)
stringExpressions.parameter(String, Object)
variableExpressions.parameter(String)
**
jep
- The JEP objectExpression
objectBaseException
- If the JEP expression can't be convertednewJep(String, JepFunction[])
,
getFunctions()
public static Expression formulaToExpression(java.lang.String formula, JepFunction... functions) throws BaseException
Expression
. This method
is equivalent to: jepToExpression(newJep(formula, functions))
.BaseException
jepToExpression(JEP)
public static Restriction jepToRestriction(JEP jep) throws BaseException
Restriction
. The
Query API only supports a subset of the functions/operators that
JEP supports.
Supported functions/operators are:
=== This is a optional function that must be registered when creating the JEP object.Restrictions.eq(Expression, Expression)
!=Restrictions.neq(Expression, Expression)
>Restrictions.gt(Expression, Expression)
>=Restrictions.gteq(Expression, Expression)
<Restrictions.lt(Expression, Expression)
<=Restrictions.lteq(Expression, Expression)
>Restrictions.gt(Expression, Expression)
&&Restrictions.and(Restriction[])
||Restrictions.or(Restriction[])
!Restrictions.not(Restriction)
All operators supported by the jepToExpression(JEP)
are of
course also supported in the appropriate places.
jep
- The JEP objectRestriction
objectBaseException
- If the JEP expression can't be convertednewJep(String, JepFunction[])
public static Restriction formulaToRestriction(java.lang.String formula, JepFunction... functions) throws BaseException
Restriction
. This method
is equivalent to: jepToRestriction(newJep(formula, functions))
.BaseException
jepToRestriction(JEP)
public static Expression nodeToExpression(Node node) throws BaseException
node
- Node to convert to an expressionExpression
objectBaseException
- If the JEP function in node not is supported.public static Restriction nodeToRestriction(Node node) throws BaseException
node
- JEP node to convert.Restriction
objectBaseException
- If the JEP function in node is not supported by the converter.public static java.lang.String nodeToString(Node node) throws BaseException
node
- JEP node to convert.BaseException
- If the node could not be converted in some way.public static int nodeToInt(Node node) throws BaseException
node
- JEP node to convert.BaseException
- If the node could not be converted.public static void clearErrorList(JEP jep)
JEP.getValueAsObject()
the error list should be cleared.