Package chemaxon.jep
Class ChemJEP<C extends ChemContext>
java.lang.Object
chemaxon.jep.ChemJEP<C>
- All Implemented Interfaces:
chemaxon.marvin.util.CallbackIface
,Serializable
@PublicApi
public class ChemJEP<C extends ChemContext>
extends Object
implements chemaxon.marvin.util.CallbackIface, Serializable
Expression parser and evaluator for chemical expressions.
- Since:
- JChem 2.2, Marvin 5.1
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The compilation error message.Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered.static final String
The evaluation error message.static final int
Logical result value: FALSE.static final int
Logical result value: TRUE.static final int
Logical result value: UNDECIDED. -
Constructor Summary
ConstructorDescriptionChemJEP()
Deprecated, for removal: This API element is subject to removal in a future version.Direct creation of aChemJEP
object will no longer be supported, use theEvaluator.compile(java.lang.String)
methods instead.Deprecated, for removal: This API element is subject to removal in a future version.Direct creation of aChemJEP
object will no longer be supported, use theEvaluator.compile(java.lang.String)
methods instead. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated, for removal: This API element is subject to removal in a future version.Complex number support will be removed without replacement.chemaxon.nfunk.jep.type.Complex
addComplexVariable
(String name, double re, double im) Deprecated, for removal: This API element is subject to removal in a future version.Complex number support will be removed without replacement.protected void
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered.void
addFunction
(String name, PostfixMathCommandI function) Deprecated, for removal: This API element is subject to removal in a future version.The function table will not be modifiable anymore.void
Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable.void
Deprecated, for removal: This API element is subject to removal in a future version.These functions will be removed without replacement.addVariable
(String name, double value) Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable.void
addVariableAsObject
(String name, Object object) Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable.Deprecated, for removal: This API element is subject to removal in a future version.No longer used for accessing the context, will be removed without replacement.void
Compiles the expression string to an inner structure.Returns the constant table used by this parser.Evaluates the expression.boolean
evaluate_boolean
(C context) Evaluates the expression and converts the resultboolean
.boolean[]
evaluate_booleans
(C context) Evaluates the expression and converts the result toboolean[]
.double
evaluate_double
(C context) Evaluates the expression and converts the result todouble
.double[]
evaluate_doubles
(C context) Evaluates the expression and converts the result todouble[]
.chemaxon.nfunk.jep.type.Complex
Deprecated, for removal: This API element is subject to removal in a future version.Complex number support will be removed without replacement.getError
(int i) Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered.int
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered.Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered.Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered.getFunction
(String name) Deprecated, for removal: This API element is subject to removal in a future version.The function table will become an internal API.static int
getLogicalValue
(Object result) chemaxon.nfunk.jep.type.NumberFactory
Deprecated, for removal: This API element is subject to removal in a future version.This feature will be removed without replacement.chemaxon.nfunk.jep.SymbolTable
Deprecated, for removal: This API element is subject to removal in a future version.UseconstantTable()
instead.chemaxon.nfunk.jep.Node
Deprecated, for removal: This API element is subject to removal in a future version.This method returns an internal representation which will be hidden in the future.double
getValue()
Deprecated, for removal: This API element is subject to removal in a future version.Useevaluate_double(ChemContext)
instead.Deprecated, for removal: This API element is subject to removal in a future version.Useevaluate(ChemContext)
instead.boolean
hasError()
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered.void
Deprecated, for removal: This API element is subject to removal in a future version.The function table will become unmodifiable.void
Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable.static boolean
isUndecided
(Object result) Returns whether the result object is undecided.void
parseExpression
(String expression_in) Deprecated, for removal: This API element is subject to removal in a future version.Usecompile(String)
instead.removeFunction
(String name) Deprecated, for removal: This API element is subject to removal in a future version.The function table will become unmodifiable.removeVariable
(String name) Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable.void
setAllowUndeclared
(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.Undeclared variables will always be allowed in the future, changing this will no longer be supported.void
setImplicitMul
(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.This option will be removed without replacement.protected void
setSymbolTable
(chemaxon.nfunk.jep.SymbolTable symTab) Deprecated, for removal: This API element is subject to removal in a future version.UseEvaluator.compile(String, Class, ConstantTable)
instead.void
setTraverse
(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.UseEvaluator.setVerbose(boolean)
instead before creating theChemJEP
.
-
Field Details
-
FALSE
public static final int FALSELogical result value: FALSE.- See Also:
-
TRUE
public static final int TRUELogical result value: TRUE.- See Also:
-
UNDECIDED
public static final int UNDECIDEDLogical result value: UNDECIDED.- See Also:
-
COMPILE_ERROR
The compilation error message.- See Also:
-
EVALUATION_ERROR
The evaluation error message.- See Also:
-
errorList
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) protected Vector<Throwable> errorListDeprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.The error list of this parser.
-
-
Constructor Details
-
ChemJEP
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public ChemJEP() throws chemaxon.nfunk.jep.ParseExceptionDeprecated, for removal: This API element is subject to removal in a future version.Direct creation of aChemJEP
object will no longer be supported, use theEvaluator.compile(java.lang.String)
methods instead.Constructor. Initiates the this JEP with no context.- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
ChemJEP
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public ChemJEP(Class<? extends C> contextClass) throws chemaxon.nfunk.jep.ParseException Deprecated, for removal: This API element is subject to removal in a future version.Direct creation of aChemJEP
object will no longer be supported, use theEvaluator.compile(java.lang.String)
methods instead.Constructor. Sets the context class, adds context functions.- Parameters:
contextClass
- is the context class- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
-
Method Details
-
constantTable
Returns the constant table used by this parser. -
addFunction
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addFunction(String name, PostfixMathCommandI function) throws chemaxon.nfunk.jep.ParseException Deprecated, for removal: This API element is subject to removal in a future version.The function table will not be modifiable anymore. No replacement.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.- 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
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) protected void setSymbolTable(chemaxon.nfunk.jep.SymbolTable symTab) Deprecated, for removal: This API element is subject to removal in a future version.UseEvaluator.compile(String, Class, ConstantTable)
instead.Sets the SymbolTable object.- Parameters:
symTab
- is the SymbolTable object
-
compile
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
-
parseExpression
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void parseExpression(String expression_in) throws chemaxon.nfunk.jep.ParseException Deprecated, for removal: This API element is subject to removal in a future version.Usecompile(String)
instead.Parses the expression. If there are errors in the expression, they are added to theerrorList
member.- Parameters:
expression_in
- The input expression string- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
callback
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Object callback(String method, Object arg) Deprecated, for removal: This API element is subject to removal in a future version.No longer used for accessing the context, will be removed without replacement.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
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
-
getValueAsObject
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Object getValueAsObject() throws chemaxon.nfunk.jep.ParseExceptionDeprecated, for removal: This API element is subject to removal in a future version.Useevaluate(ChemContext)
instead.Evaluates and returns the value of the expression as an object. This method is useful when the type of the value is unknown, or not important.- Returns:
- The calculated value of the expression if no errors occur. Returns null otherwise.
- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
evaluate_double
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:
chemaxon.nfunk.jep.ParseException
- on evaluation error
-
getValue
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public double getValue() throws chemaxon.nfunk.jep.ParseExceptionDeprecated, for removal: This API element is subject to removal in a future version.Useevaluate_double(ChemContext)
instead.Evaluates and returns the value of the expression. If the value is complex, the real component of the complex number is returned. To get the complex value, use getComplexValue().- Returns:
- The calculated value of the expression. If the value is complex, the real component is returned. If an error occurs during evaluation, 0 is returned.
- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
evaluate_doubles
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:
chemaxon.nfunk.jep.ParseException
- on evaluation error
-
evaluate_boolean
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:
chemaxon.nfunk.jep.ParseException
- on evaluation error
-
evaluate_booleans
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
-
getComplexValue
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.type.Complex getComplexValue() throws chemaxon.nfunk.jep.ParseExceptionDeprecated, for removal: This API element is subject to removal in a future version.Complex number support will be removed without replacement.Evaluates and returns the value of the expression as a complex number.- Returns:
- The calculated value of the expression as a complex number if no errors occur. Returns null otherwise.
- Throws:
chemaxon.nfunk.jep.ParseException
- on error
-
getLogicalValue
- Parameters:
result
- is the result object- Returns:
- the corresponding logical value
- Since:
- JChem 3.2
-
isUndecided
Returns whether the result object is undecided.- Returns:
true
if the result is undecided
-
initSymTab
Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable. UseEvaluator.compile(String, Class, ConstantTable)
instead.Creates a new SymbolTable object as symTab. -
addStandardConstants
Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable. UseEvaluator.compile(String, Class, ConstantTable)
instead.Adds the constants pi and e to the parser. As addStandardFunctions(), this method should be called immediatly after the JEP object is created. -
addComplex
Deprecated, for removal: This API element is subject to removal in a future version.Complex number support will be removed without replacement.Call this function if you want to parse expressions which involve complex numbers. This method specifies "i" as the imaginary unit (0,1). Two functions re() and im() are also added for extracting the real or imaginary components of a complex number respectively. -
addVariable
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Double addVariable(String name, double value) Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable. UseEvaluator.compile(String, Class, ConstantTable)
instead.Adds a new variable to the parser, or updates the value of an existing variable. This must be done before parsing an expression so the parser is aware that the new variable may be contained in the expression.- Parameters:
name
- Name of the variable to be addedvalue
- Initial value or new value for the variable- Returns:
- Double object of the variable
-
addComplexVariable
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.type.Complex addComplexVariable(String name, double re, double im) Deprecated, for removal: This API element is subject to removal in a future version.Complex number support will be removed without replacement.Adds a new complex variable to the parser, or updates the value of an existing variable. This must be done before parsing an expression so the parser is aware that the new variable may be contained in the expression.- Parameters:
name
- Name of the variable to be addedre
- Initial real value or new real value for the variablere
- Initial imaginary value or new imaginary value for the variable- Returns:
- Complex object of the variable
-
addVariableAsObject
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addVariableAsObject(String name, Object object) Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable. UseEvaluator.compile(String, Class, ConstantTable)
instead.Adds a new variable to the parser as an object, or updates the value of an existing variable. This must be done before parsing an expression so the parser is aware that the new variable may be contained in the expression.- Parameters:
name
- Name of the variable to be addedobject
- Initial value or new value for the variable
-
removeVariable
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Object removeVariable(String name) Deprecated, for removal: This API element is subject to removal in a future version.The symbol table has been replaced with the constant table, and it will become unmodifiable. UseEvaluator.compile(String, Class, ConstantTable)
instead.Removes a variable from the parser. For example after calling addStandardConstants(), removeVariable("e") might be called to remove the euler constant from the set of variables.- Returns:
- The value of the variable if it was added earlier. If
the variable is not in the table of variables,
null
is returned.
-
initFunTab
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new FunctionTable object as funTab. -
addStandardFunctions
Deprecated, for removal: This API element is subject to removal in a future version.These functions will be removed without replacement.Adds the standard functions to the parser. If this function is not called before parsing an expression, functions such as sin() or cos() would produce an "Unrecognized function..." error. In most cases, this method should be called immediately after the JEP object is created. -
getFunction
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public PostfixMathCommandI getFunction(String name) Deprecated, for removal: This API element is subject to removal in a future version.The function table will become an internal API. No replacement.Returns a function from the function table.- Parameters:
name
- is the function name- Returns:
- the stored function or its clone, or null if no such function
-
removeFunction
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Object removeFunction(String name) Deprecated, for removal: This API element is subject to removal in a future version.Removes a function from the parser.- Returns:
- If the function was added earlier, the function class instance
is returned. If the function was not present,
null
is returned.
-
setTraverse
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setTraverse(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.UseEvaluator.setVerbose(boolean)
instead before creating theChemJEP
.Sets the value of the traverse option. setTraverse is useful for debugging purposes. When traverse is set to true, the parse-tree will be dumped to the standard ouput device.The default value is false.
- Parameters:
value
- The boolean traversal option.
-
setImplicitMul
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setImplicitMul(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.This option will be removed without replacement.Sets the value of the implicit multiplication option. If this option is set to true before parsing, implicit multiplication will be allowed. That means that an expression such as"1 2"
is valid and is interpreted as"1*2"
.The default value is false.
- Parameters:
value
- The boolean implicit multiplication option.
-
setAllowUndeclared
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setAllowUndeclared(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.Undeclared variables will always be allowed in the future, changing this will no longer be supported.Sets the value for the undeclared variables option. If this option is set to true, expressions containing variables that were not previously added to ChemJEP will not produce an "Unrecognized Symbol" error. Sets the value for the undeclared variables option.If this option is set to false, variables that were not previously added to ChemJEP will produce an error while parsing.
The default value is true.
- Parameters:
value
- The boolean option for allowing undeclared variables.
-
getTopNode
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.Node getTopNode()Deprecated, for removal: This API element is subject to removal in a future version.This method returns an internal representation which will be hidden in the future. No replacement.Returns the top node of the expression tree. Because all nodes are pointed to either directly or indirectly, the entire expression tree can be accessed through this node. It may be used to manipulate the expression, and subsequently evaluate it manually.- Returns:
- The top node of the expression tree
-
getSymbolTable
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.SymbolTable getSymbolTable()Deprecated, for removal: This API element is subject to removal in a future version.UseconstantTable()
instead.Returns the symbol table (the list of all variables that the parser recognises).- Returns:
- The symbol table
-
getNumberFactory
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.type.NumberFactory getNumberFactory()Deprecated, for removal: This API element is subject to removal in a future version.This feature will be removed without replacement.Returns the number factory. -
hasError
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.Returns whether the error list has at least one element. -
getErrors
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.Returns all exceptions in the error list. -
getErrorInfo
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.Returns a string describing all exceptions in the error list. -
addError
@Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) protected void addError(Exception ex) Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.Adds an exception to the error list. -
getError
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.Returns an exception from the error list by its index. -
getErrorCount
Deprecated, for removal: This API element is subject to removal in a future version.This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.Returns the number of exceptions in the error list.
-