public interface ExpressionParser
ExpressionParser
class defines an interface for all
classes that parse and evaluate mathematical expressions. The expression
parser must initialize, parse, and then evaluate in that order. The list
of variables is only available via getVariables()
after parsing
is complete.
Expressions evaluate to a primitive type given by the getResultType()
method. The result can be retrieved using the evaluate(noaa.coastwatch.util.expression.EvaluateImp)
method
to a primitive wrapper, or the extra overhead of creating a wrapped
primitive can be avoided by using one of the special primitive evaluate
methods to directly retrieve the result. If the result type does not match
the method called, zero is returned (or false for a boolean).
Modifier and Type | Interface and Description |
---|---|
static class |
ExpressionParser.ResultType
The enumeration of the possible expression result types.
|
Modifier and Type | Method and Description |
---|---|
default void |
adapt(ExpressionParser.ResultType type)
Adapts the parsed expression to a specific result type.
|
java.lang.Object |
evaluate(EvaluateImp evalImp)
Evaluates the expression to a primitive wrapper object.
|
default boolean |
evaluateToBoolean(EvaluateImp evalImp)
Evaluates the expression to a boolean value.
|
default byte |
evaluateToByte(EvaluateImp evalImp)
Evaluates the expression to a byte value.
|
default double |
evaluateToDouble(EvaluateImp evalImp)
Evaluates the expression to a double value.
|
default float |
evaluateToFloat(EvaluateImp evalImp)
Evaluates the expression to a float value.
|
default int |
evaluateToInt(EvaluateImp evalImp)
Evaluates the expression to an int value.
|
default long |
evaluateToLong(EvaluateImp evalImp)
Evaluates the expression to a long value.
|
default short |
evaluateToShort(EvaluateImp evalImp)
Evaluates the expression to a short value.
|
default org.w3c.dom.Document |
getParseTree()
Gets a document tree corresponding to the parsed expression.
|
ExpressionParser.ResultType |
getResultType()
Gets the result data type.
|
java.util.List<java.lang.String> |
getVariables()
Gets the list of variables used in the expression.
|
void |
init(ParseImp parseImp)
Initializes this parser with the specified implementation.
|
default boolean |
isThreadSafe()
Determines if this parser instance is thread-safe.
|
void |
parse(java.lang.String expr)
Parses the specified expression.
|
default java.lang.String |
translate(java.lang.String expr)
Translates the specified expression to Java Language syntax if possible.
|
default boolean isThreadSafe()
void init(ParseImp parseImp)
parseImp
- the parser implementation to use for variable information
during parsing.void parse(java.lang.String expr)
expr
- the expression to parse.java.lang.RuntimeException
- if an error occurred parsing the expression.default void adapt(ExpressionParser.ResultType type)
type
- the result type to adapt the expression. The result
type of the parser is set to the specified type.java.lang.UnsupportedOperationException
- if the result type of the parser
cannot be adapted.default java.lang.String translate(java.lang.String expr)
expr
- the expression to translate.java.lang.UnsupportedOperationException
- if the expression cannot be
translated, or expression translation is not supported.default org.w3c.dom.Document getParseTree()
ExpressionParser.ResultType getResultType()
java.util.List<java.lang.String> getVariables()
java.lang.Object evaluate(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.default boolean evaluateToBoolean(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.default byte evaluateToByte(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.default short evaluateToShort(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.default int evaluateToInt(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.default long evaluateToLong(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.default float evaluateToFloat(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.default double evaluateToDouble(EvaluateImp evalImp)
evalImp
- the evalutation implementation that provides variable
values.