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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionevaluate(EvaluateImp evalImp) Evaluates the expression to a primitive wrapper object.doubleevaluateToDouble(EvaluateImp evalImp) Evaluates the expression to a double value.org.nfunk.jep.JEPGets 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.voidInitializes this parser with the specified implementation.booleanDetermines if this parser instance is thread-safe.static voidTests this class.voidParses the specified expression.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:ExpressionParserDetermines if this parser instance is thread-safe.- Specified by:
isThreadSafein interfaceExpressionParser- Returns:
- true is this parser instance is thread-safe, or false if not.
-
init
Description copied from interface:ExpressionParserInitializes this parser with the specified implementation.- Specified by:
initin interfaceExpressionParser- Parameters:
parseImp- the parser implementation to use for variable information during parsing.
-
parse
Description copied from interface:ExpressionParserParses the specified expression.- Specified by:
parsein interfaceExpressionParser- Parameters:
expr- the expression to parse.
-
getParseTree
Description copied from interface:ExpressionParserGets a document tree corresponding to the parsed expression.- Specified by:
getParseTreein interfaceExpressionParser- Returns:
- the document tree.
-
getResultType
Description copied from interface:ExpressionParserGets the result data type.- Specified by:
getResultTypein interfaceExpressionParser- Returns:
- the result data type.
-
getVariables
Description copied from interface:ExpressionParserGets the list of variables used in the expression.- Specified by:
getVariablesin interfaceExpressionParser- Returns:
- the list of variable names.
-
getVariableType
Description copied from interface:ExpressionParserGets the variable type used in the expression.- Specified by:
getVariableTypein 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:ExpressionParserEvaluates the expression to a primitive wrapper object.- Specified by:
evaluatein interfaceExpressionParser- Parameters:
evalImp- the evalutation implementation that provides variable values.- Returns:
- the result value in a wrapper.
-
evaluateToDouble
Description copied from interface:ExpressionParserEvaluates the expression to a double value.- Specified by:
evaluateToDoublein 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
-