Package noaa.coastwatch.util.expression
Class JEPParser
java.lang.Object
noaa.coastwatch.util.expression.JEPParser
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface noaa.coastwatch.util.expression.ExpressionParser
ExpressionParser.ResultType
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionevaluate
(EvaluateImp evalImp) Evaluates the expression to a primitive wrapper object.double
evaluateToDouble
(EvaluateImp evalImp) Evaluates the expression to a double value.org.nfunk.jep.JEP
Gets the JEP object used for parsing.Gets a document tree corresponding to the parsed expression.Gets the result data type.Gets the list of variables used in the expression.getVariableType
(String name) Gets the variable type used in the expression.void
Initializes this parser with the specified implementation.boolean
Determines if this parser instance is thread-safe.static void
Tests this class.void
Parses the specified expression.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface noaa.coastwatch.util.expression.ExpressionParser
adapt, evaluateToBoolean, evaluateToByte, evaluateToFloat, evaluateToInt, evaluateToLong, evaluateToShort, translate
-
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 toinit(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 interfaceExpressionParser
- Returns:
- true is this parser instance is thread-safe, or false if not.
-
init
Description copied from interface:ExpressionParser
Initializes this parser with the specified implementation.- Specified by:
init
in interfaceExpressionParser
- Parameters:
parseImp
- the parser implementation to use for variable information during parsing.
-
parse
Description copied from interface:ExpressionParser
Parses the specified expression.- Specified by:
parse
in interfaceExpressionParser
- Parameters:
expr
- the expression to parse.
-
getParseTree
Description copied from interface:ExpressionParser
Gets a document tree corresponding to the parsed expression.- Specified by:
getParseTree
in interfaceExpressionParser
- Returns:
- the document tree.
-
getResultType
Description copied from interface:ExpressionParser
Gets the result data type.- Specified by:
getResultType
in interfaceExpressionParser
- Returns:
- the result data type.
-
getVariables
Description copied from interface:ExpressionParser
Gets the list of variables used in the expression.- Specified by:
getVariables
in interfaceExpressionParser
- Returns:
- the list of variable names.
-
getVariableType
Description copied from interface:ExpressionParser
Gets the variable type used in the expression.- Specified by:
getVariableType
in interfaceExpressionParser
- Parameters:
name
- the variable name from the list returned byExpressionParser.getVariables()
.- Returns:
- the variable class name: Byte, Short, Integer, Long, Float, or Double. The returned value is null if the variable type is unknown.
-
evaluate
Description copied from interface:ExpressionParser
Evaluates the expression to a primitive wrapper object.- Specified by:
evaluate
in interfaceExpressionParser
- Parameters:
evalImp
- the evalutation implementation that provides variable values.- Returns:
- the result value in a wrapper.
-
evaluateToDouble
Description copied from interface:ExpressionParser
Evaluates the expression to a double value.- Specified by:
evaluateToDouble
in interfaceExpressionParser
- Parameters:
evalImp
- the evalutation implementation that provides variable values.- Returns:
- the double valued result, or zero if the result is not a double.
-
main
Tests this class.- Parameters:
argv
- the array of command line parameters.- Throws:
Exception
-