Class Jep
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.
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2015-05-12 11:27:08 +0200 (ti, 12 maj 2015) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate static Enumeration<String,
String> private static Field
private static Enumeration<String,
String> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate 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
(String formula, JepFunction... functions) Convert JEP expression to a Query APIExpression
.static Restriction
formulaToRestriction
(String formula, JepFunction... functions) Convert JEP expression to a Query APIRestriction
.static Enumeration<String,
String> Get a list of built-in functions supported by thejepToExpression(JEP)
converter.static Enumeration<String,
String> Get a list of built-in operators supported by thejepToExpression(JEP)
andjepToRestriction(JEP)
converter.static Expression
jepToExpression
(JEP jep) Convert a JEP expression to a Query APIExpression
.static Restriction
jepToRestriction
(JEP jep) Convert a JEP expression to a Query APIRestriction
.static JEP
newJep
(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
Convert a node to an integer value.static Restriction
nodeToRestriction
(Node node) Convert a node with it's children to a restriction.static String
nodeToString
(Node node) Convert a node to a string value.
-
Field Details
-
functions
-
operators
-
jepErrorList
-
-
Constructor Details
-
Jep
public Jep()
-
-
Method Details
-
newJep
Create a new JEP expression. Evaluate the expression using theJEP.getValue()
method. Set values for variables with theJEP.setVarValue(String, Object)
.- Parameters:
formula
- The expression to parsefunctions
- Extra functions that are required to parse the expression- Returns:
- A
JEP
object - Throws:
BaseException
- If the expression couldn't be parsed
-
addFunctions
-
getFunctions
Get a list of built-in functions supported by thejepToExpression(JEP)
converter. More functions can be registered when creating the JEP expression (seenewJep(String, JepFunction[])
).- Returns:
- An enumeration with the name of the function in the key and a description in the value part
-
getOperators
Get a list of built-in operators supported by thejepToExpression(JEP)
andjepToRestriction(JEP)
converter. It is not possible to register more operators.- Returns:
- An enumeration with the symbol of the operator in the key and a description in the value part
- Since:
- 2.4
-
jepToExpression
Convert a JEP expression to a Query APIExpression
. 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)
**
= The NULL string is converted to a NULL value- Parameters:
jep
- The JEP object- Returns:
- An
Expression
object - Throws:
BaseException
- If the JEP expression can't be converted- See Also:
-
formulaToExpression
public static Expression formulaToExpression(String formula, JepFunction... functions) throws BaseException Convert JEP expression to a Query APIExpression
. This method is equivalent to:jepToExpression(newJep(formula, functions))
.- Throws:
BaseException
- See Also:
-
jepToRestriction
Convert a JEP expression to a Query APIRestriction
. 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.- Parameters:
jep
- The JEP object- Returns:
- A
Restriction
object - Throws:
BaseException
- If the JEP expression can't be converted- See Also:
-
formulaToRestriction
public static Restriction formulaToRestriction(String formula, JepFunction... functions) throws BaseException Convert JEP expression to a Query APIRestriction
. This method is equivalent to:jepToRestriction(newJep(formula, functions))
.- Throws:
BaseException
- See Also:
-
nodeToExpression
Convert a node with it's children to an expression.- Parameters:
node
- Node to convert to an expression- Returns:
- A
Expression
object - Throws:
BaseException
- If the JEP function in node not is supported.
-
nodeToRestriction
Convert a node with it's children to a restriction.- Parameters:
node
- JEP node to convert.- Returns:
- A
Restriction
object - Throws:
BaseException
- If the JEP function in node is not supported by the converter.- Since:
- 2.4
-
nodeToString
Convert a node to a string value. Supported node types are constants or variables. Constants will be converted to strings with the toString() method. For variables the name is returned as the string. This allows for unquoted strings in expressions. The NULL string is converted to a NULL value.- Parameters:
node
- JEP node to convert.- Returns:
- A String object or null if the node does not have any value.
- Throws:
BaseException
- If the node could not be converted in some way.
-
nodeToInt
Convert a node to an integer value. Supported node types are constants.- Parameters:
node
- JEP node to convert.- Returns:
- an int object
- Throws:
BaseException
- If the node could not be converted.
-
clearErrorList
This is a workaround for a bug in the JEP error handling. Before callingJEP.getValueAsObject()
the error list should be cleared.
-