|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.jep.Jep
public class Jep
Utility class for parsing mathematical expressions. This class uses the Java Mathematical Expression Parser package from Singular Systems to parse mathematical expressions.
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.
Field Summary | |
---|---|
private static Enumeration<String,String> |
functions
|
private static Field |
jepErrorList
|
private static Enumeration<String,String> |
operators
|
Constructor Summary | |
---|---|
Jep()
|
Method Summary | |
---|---|
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(String formula,
JepFunction... functions)
Convert JEP expression to a Query API Expression . |
static Restriction |
formulaToRestriction(String formula,
JepFunction... functions)
Convert JEP expression to a Query API Restriction . |
static Enumeration<String,String> |
getFunctions()
Get a list of built-in functions supported by the jepToExpression(JEP)
converter. |
static Enumeration<String,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(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 String |
nodeToString(Node node)
Convert a node to a string value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static volatile Enumeration<String,String> functions
private static volatile Enumeration<String,String> operators
private static Field jepErrorList
Constructor Detail |
---|
public Jep()
Method Detail |
---|
public static JEP newJep(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
expression
JEP
object
BaseException
- If the expression couldn't be parsedprivate static void addFunctions(JEP jep, JepFunction... functions)
public static Enumeration<String,String> getFunctions()
jepToExpression(JEP)
converter. More functions can be registered when creating the JEP
expression (see newJep(String, JepFunction[])
).
public static Enumeration<String,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 object
Expression
object
BaseException
- If the JEP expression can't be convertednewJep(String, JepFunction[])
,
getFunctions()
public static Expression formulaToExpression(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 object
Restriction
object
BaseException
- If the JEP expression can't be convertednewJep(String, JepFunction[])
public static Restriction formulaToRestriction(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 expression
Expression
object
BaseException
- If the JEP function in node not is supported.public static Restriction nodeToRestriction(Node node) throws BaseException
node
- JEP node to convert.
Restriction
object
BaseException
- If the JEP function in node is not supported by the converter.public static 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.
jep
-
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |