Class JEPParser

java.lang.Object
noaa.coastwatch.util.expression.JEPParser
All Implemented Interfaces:
ExpressionParser

public class JEPParser extends Object implements ExpressionParser

The JEPParser class parses expressions using the syntax of the Java Math Expression Parser (JEP) from http://singularsys.com/jep (we use version 2.24 which is no longer supported since the product is now commercial). This is the syntax that has been used by the CoastWatch Utilities since 2003 and documented in the cwmath tool. Previous to this class existing, code would create a JEP instance and use it directly for expression parsing.

Note that this class is not thread-safe.

Since:
3.4.0
Author:
Peter Hollemans
  • Constructor Details

    • JEPParser

      public JEPParser()
  • Method Details

    • getJEPObject

      public org.nfunk.jep.JEP getJEPObject()
      Gets the JEP object used for parsing. This may be useful for classes that need direct access to the parser. The parser is only available after the call to init(noaa.coastwatch.util.expression.ParseImp).
      Returns:
      the JEP parser.
    • isThreadSafe

      public boolean isThreadSafe()
      Description copied from interface: ExpressionParser
      Determines if this parser instance is thread-safe.
      Specified by:
      isThreadSafe in interface ExpressionParser
      Returns:
      true is this parser instance is thread-safe, or false if not.
    • init

      public void init(ParseImp parseImp)
      Description copied from interface: ExpressionParser
      Initializes this parser with the specified implementation.
      Specified by:
      init in interface ExpressionParser
      Parameters:
      parseImp - the parser implementation to use for variable information during parsing.
    • parse

      public void parse(String expr)
      Description copied from interface: ExpressionParser
      Parses the specified expression.
      Specified by:
      parse in interface ExpressionParser
      Parameters:
      expr - the expression to parse.
    • getParseTree

      public Document getParseTree()
      Description copied from interface: ExpressionParser
      Gets a document tree corresponding to the parsed expression.
      Specified by:
      getParseTree in interface ExpressionParser
      Returns:
      the document tree.
    • getResultType

      public ExpressionParser.ResultType getResultType()
      Description copied from interface: ExpressionParser
      Gets the result data type.
      Specified by:
      getResultType in interface ExpressionParser
      Returns:
      the result data type.
    • getVariables

      public List<String> getVariables()
      Description copied from interface: ExpressionParser
      Gets the list of variables used in the expression.
      Specified by:
      getVariables in interface ExpressionParser
      Returns:
      the list of variable names.
    • evaluate

      public Object evaluate(EvaluateImp evalImp)
      Description copied from interface: ExpressionParser
      Evaluates the expression to a primitive wrapper object.
      Specified by:
      evaluate in interface ExpressionParser
      Parameters:
      evalImp - the evalutation implementation that provides variable values.
      Returns:
      the result value in a wrapper.
    • evaluateToDouble

      public double evaluateToDouble(EvaluateImp evalImp)
      Description copied from interface: ExpressionParser
      Evaluates the expression to a double value.
      Specified by:
      evaluateToDouble in interface ExpressionParser
      Parameters:
      evalImp - the evalutation implementation that provides variable values.
      Returns:
      the double valued result, or zero if the result is not a double.
    • main

      public static void main(String[] argv) throws Exception
      Tests this class.
      Parameters:
      argv - the array of command line parameters.
      Throws:
      Exception