Package chemaxon.jep

Class 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int FALSE
      Logical result value: FALSE.
      static int TRUE
      Logical result value: TRUE.
      static int UNDECIDED
      Logical result value: UNDECIDED.
      • Fields inherited from class chemaxon.nfunk.jep.JEP

        allowUndeclared, COMPILE_ERROR, errorList, EVALUATION_ERROR, funTab, implicitMul, symTab
    • Constructor Summary

      Constructors 
      Constructor Description
      ChemJEP()
      Constructor.
      ChemJEP​(Class contextClass)
      Constructor.
    • 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 class chemaxon.nfunk.jep.JEP
        Parameters:
        name - is the name of the function
        function - 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)
        Delegates CallbackIface.callback(String, Object) to the context.
        Specified by:
        callback in interface chemaxon.marvin.util.CallbackIface
        Parameters:
        method - is the method name
        arg - 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 by compile(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 to double. The expression string must have been given and compiled beforehand by compile(String expression).
        Parameters:
        context - is the evaluation context
        Returns:
        the evaluation result
        Throws:
        EvaluationException - on evaluation error
        chemaxon.nfunk.jep.ParseException
      • evaluate_doubles

        public double[] evaluate_doubles​(ChemContext context)
                                  throws chemaxon.nfunk.jep.ParseException
        Evaluates the expression and converts the result to double[]. This is useful if the result is an object array in which case each element is converted to double. The expression string must have been given and compiled beforehand by compile(String expression).
        Parameters:
        context - is the evaluation context
        Returns:
        the evaluation result
        Throws:
        EvaluationException - on evaluation error
        chemaxon.nfunk.jep.ParseException
      • evaluate_boolean

        public boolean evaluate_boolean​(ChemContext context)
                                 throws chemaxon.nfunk.jep.ParseException
        Evaluates the expression and converts the result boolean. 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 by compile(String expression).
        Parameters:
        context - is the evaluation context
        Returns:
        the evaluation result
        Throws:
        EvaluationException - on evaluation error
        chemaxon.nfunk.jep.ParseException
      • evaluate_booleans

        public boolean[] evaluate_booleans​(ChemContext context)
                                    throws chemaxon.nfunk.jep.ParseException
        Evaluates the expression and converts the result to boolean[]. This is useful if the result is an object array in which case each element is converted to boolean. The expression string must have been given and compiled beforehand by compile(String expression).
        Parameters:
        context - is the evaluation context
        Returns:
        the evaluation result
        Throws:
        EvaluationException - on evaluation error
        chemaxon.nfunk.jep.ParseException
      • getLogicalValue

        public static int getLogicalValue​(Object result)
        Returns the logical correspondent of the specified result object: TRUE, FALSE or UNDECIDED.
        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