Package chemaxon.jep
Class ChemJEP
- java.lang.Object
-
- chemaxon.nfunk.jep.JEP
-
- chemaxon.jep.ChemJEP
-
- All Implemented Interfaces:
chemaxon.marvin.util.CallbackIface
,Serializable
@PublicAPI public class ChemJEP extends chemaxon.nfunk.jep.JEP implements chemaxon.marvin.util.CallbackIface
Expression parser and evaluator for chemical expressions.- Since:
- JChem 2.2, Marvin 5.1
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFunction(String name, chemaxon.nfunk.jep.function.PostfixMathCommandI function)
Adds a new function to the parser.Object
callback(String method, Object arg)
DelegatesCallbackIface.callback(String, Object)
to the context.void
compile(String expression)
Compiles the expression string to an inner structure.Object
evaluate(ChemContext context)
Evaluates the expression.boolean
evaluate_boolean(ChemContext context)
Evaluates the expression and converts the resultboolean
.boolean[]
evaluate_booleans(ChemContext context)
Evaluates the expression and converts the result toboolean[]
.double
evaluate_double(ChemContext context)
Evaluates the expression and converts the result todouble
.double[]
evaluate_doubles(ChemContext context)
Evaluates the expression and converts the result todouble[]
.static int
getLogicalValue(Object result)
static boolean
isUndecided(Object result)
Returns whether the result object is undecided.protected void
setSymbolTable(chemaxon.nfunk.jep.SymbolTable symTab)
Sets the SymbolTable object.-
Methods inherited from class chemaxon.nfunk.jep.JEP
addComplex, addComplexVariable, addError, addStandardConstants, addStandardFunctions, addVariable, addVariableAsObject, getComplexValue, getError, getErrorCount, getErrorInfo, getErrors, getFunction, getNumberFactory, getSymbolTable, getTopNode, getValue, getValueAsObject, hasError, initFunTab, initSymTab, parseExpression, removeFunction, removeVariable, setAllowUndeclared, setImplicitMul, setTraverse
-
-
-
-
Field Detail
-
FALSE
public static final int FALSE
Logical result value: FALSE.- See Also:
- Constant Field Values
-
TRUE
public static final int TRUE
Logical result value: TRUE.- See Also:
- Constant Field Values
-
UNDECIDED
public static final int UNDECIDED
Logical result value: UNDECIDED.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ChemJEP
public ChemJEP() throws chemaxon.nfunk.jep.ParseException
Constructor. Initiates the this JEP with no context.- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
ChemJEP
public ChemJEP(Class contextClass) throws chemaxon.nfunk.jep.ParseException
Constructor. Sets the context class, adds context functions.- Parameters:
contextClass
- is the context class- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
-
Method Detail
-
addFunction
public void addFunction(String name, chemaxon.nfunk.jep.function.PostfixMathCommandI function) throws chemaxon.nfunk.jep.ParseException
Adds a new function to the parser. This must be done before parsing an expression so the parser is aware that the new function may be contained in the expression.- Overrides:
addFunction
in classchemaxon.nfunk.jep.JEP
- Parameters:
name
- is the name of the functionfunction
- is the function object that is used for evaluating the function- Throws:
chemaxon.nfunk.jep.ParseException
- if there exists a function with the same name
-
setSymbolTable
protected void setSymbolTable(chemaxon.nfunk.jep.SymbolTable symTab)
Sets the SymbolTable object.- Parameters:
symTab
- is the SymbolTable object
-
compile
public void compile(String expression) throws chemaxon.nfunk.jep.ParseException
Compiles the expression string to an inner structure. This speeds-up evaluation.- Parameters:
expression
- is the expression string- Throws:
chemaxon.nfunk.jep.ParseException
- on compile error
-
callback
public Object callback(String method, Object arg)
DelegatesCallbackIface.callback(String, Object)
to the context.- Specified by:
callback
in interfacechemaxon.marvin.util.CallbackIface
- Parameters:
method
- is the method namearg
- is the method argument
-
evaluate
public Object evaluate(ChemContext context) throws chemaxon.nfunk.jep.ParseException
Evaluates the expression. The expression string must have been given and compiled beforehand bycompile(String expression)
.- Parameters:
context
- is the evaluation context- Returns:
- the evaluation result
- Throws:
chemaxon.nfunk.jep.ParseException
- on evaluation error
-
evaluate_double
public double evaluate_double(ChemContext context) throws chemaxon.nfunk.jep.ParseException
Evaluates the expression and converts the result todouble
. The expression string must have been given and compiled beforehand bycompile(String expression)
.- Parameters:
context
- is the evaluation context- Returns:
- the evaluation result
- Throws:
EvaluationException
- on evaluation errorchemaxon.nfunk.jep.ParseException
-
evaluate_doubles
public double[] evaluate_doubles(ChemContext context) throws chemaxon.nfunk.jep.ParseException
Evaluates the expression and converts the result todouble[]
. This is useful if the result is an object array in which case each element is converted todouble
. The expression string must have been given and compiled beforehand bycompile(String expression)
.- Parameters:
context
- is the evaluation context- Returns:
- the evaluation result
- Throws:
EvaluationException
- on evaluation errorchemaxon.nfunk.jep.ParseException
-
evaluate_boolean
public boolean evaluate_boolean(ChemContext context) throws chemaxon.nfunk.jep.ParseException
Evaluates the expression and converts the resultboolean
. Boolean return values are returned as double: 1.0 for true and 0.0 for false. This function returns true for a value greater than 0.5, false otherwise. This means that for boolean expressions the return value will be OK (and we also eliminated floating-point comparison inaccuracy :-). The expression string must have been given and compiled beforehand bycompile(String expression)
.- Parameters:
context
- is the evaluation context- Returns:
- the evaluation result
- Throws:
EvaluationException
- on evaluation errorchemaxon.nfunk.jep.ParseException
-
evaluate_booleans
public boolean[] evaluate_booleans(ChemContext context) throws chemaxon.nfunk.jep.ParseException
Evaluates the expression and converts the result toboolean[]
. This is useful if the result is an object array in which case each element is converted toboolean
. The expression string must have been given and compiled beforehand bycompile(String expression)
.- Parameters:
context
- is the evaluation context- Returns:
- the evaluation result
- Throws:
EvaluationException
- on evaluation errorchemaxon.nfunk.jep.ParseException
-
getLogicalValue
public static int getLogicalValue(Object result)
- Parameters:
result
- is the result object- Returns:
- the corresponding logical value
- Since:
- JChem 3.2
-
isUndecided
public static boolean isUndecided(Object result)
Returns whether the result object is undecided.- Returns:
true
if the result is undecided
-
-