|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unkrig.commons.text.expression.ExpressionEvaluator
public class ExpressionEvaluator
Supports two operation modes:
evaluate(String, Mapping))parse(String)) into an Expression object for repeated
evaluation (see Expression.evaluate(Mapping)).
| Field Summary | |
|---|---|
static java.util.Set<java.lang.Object> |
FALSES
All values the are implicitly regarded als false:
null
""
Boolean.FALSE
(byte) 0
(short) 0
(integer) 0
(long) 0
|
| Constructor Summary | |
|---|---|
ExpressionEvaluator(java.util.Collection<java.lang.String> variableNames)
|
|
ExpressionEvaluator(Predicate<java.lang.String> isValidVariableName)
|
|
ExpressionEvaluator(java.lang.String... variableNames)
|
|
| Method Summary | ||
|---|---|---|
protected static java.lang.Object |
binaryNumericPromotion(java.lang.Object value,
java.lang.Object other)
Converts and returns the value to Integer, Long, Float, Double or String as appropriate for comparison with other. |
|
java.lang.Object |
evaluate(java.lang.String spec,
Mapping<java.lang.String,?> variables)
Scans, parses and evaluates an expression. |
|
|
evaluateTo(java.lang.String spec,
Mapping<java.lang.String,?> variables,
java.lang.Class<T> targetType)
Scans, parses, evaluates and returns an expression. |
|
boolean |
evaluateToBoolean(java.lang.String spec,
Mapping<java.lang.String,?> variables)
Scans, parses and evaluates an expression. |
|
java.lang.Object |
evaluateToPrimitive(java.lang.String spec,
Mapping<java.lang.String,?> variables,
java.lang.Class<?> targetType)
Scans, parses and evaluates an expression. |
|
java.lang.ClassLoader |
getClassLoader()
|
|
java.lang.String[] |
getImports()
|
|
Expression |
parse(ProducerWhichThrows<AbstractScanner.Token<Scanner.TokenType>,ScanException> tokenProducer)
Parses an expression from a tokenProducer. |
|
Expression |
parse(java.lang.String spec)
Parses an expression. |
|
|
parser(ProducerWhichThrows<AbstractScanner.Token<Scanner.TokenType>,ScanException> tokenProducer)
|
|
ExpressionEvaluator |
setClassLoader(java.lang.ClassLoader classLoader)
|
|
ExpressionEvaluator |
setImports(java.lang.String[] imports)
|
|
static
|
to(java.lang.Object subject,
java.lang.Class<T> targetType)
Converts the given subject to the given targetType. |
|
static boolean |
toBoolean(java.lang.Object subject)
|
|
static
|
toPrimitive(java.lang.Object subject,
java.lang.Class<T> targetType)
Converts the given subject to the given primitive target type. |
|
static java.lang.String |
toString(java.lang.Object subject)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.util.Set<java.lang.Object> FALSES
false:
null
""
Boolean.FALSE
(byte) 0
(short) 0
(integer) 0
(long) 0
| Constructor Detail |
|---|
public ExpressionEvaluator(Predicate<java.lang.String> isValidVariableName)
isValidVariableName - Evaluates whether a string is a valid variable name; if not, then the parser will
throw a ParseExceptionpublic ExpressionEvaluator(java.util.Collection<java.lang.String> variableNames)
variableNames - Contains all valid variable namespublic ExpressionEvaluator(java.lang.String... variableNames)
variableNames - The names of the variables that can be referred to in an expression| Method Detail |
|---|
public java.lang.String[] getImports()
public ExpressionEvaluator setImports(java.lang.String[] imports)
imports - Names of imprted packagespublic java.lang.ClassLoader getClassLoader()
ClassLoaderpublic ExpressionEvaluator setClassLoader(java.lang.ClassLoader classLoader)
classLoader - Used to load classes named in the expression; by default the ClassLoader which loaded
the ExpressionEvaluator class.
public Expression parse(java.lang.String spec)
throws ParseException
ParseException
public Expression parse(ProducerWhichThrows<AbstractScanner.Token<Scanner.TokenType>,ScanException> tokenProducer)
throws ParseException
tokenProducer.
ParseExceptionpublic <E extends java.lang.Exception> Parser<Expression,E> parser(ProducerWhichThrows<AbstractScanner.Token<Scanner.TokenType>,ScanException> tokenProducer)
tokenProducer - The source of tokens to be parsed, e.g. Scanner.stringScanner()
Parser for expression parsing
@Nullable
public java.lang.Object evaluate(java.lang.String spec,
Mapping<java.lang.String,?> variables)
throws ParseException,
EvaluationException
ParseException - spec refers to a variable which is not contained in variables
ParseException - Any other parse error
EvaluationException
public static java.lang.String toString(@Nullable
java.lang.Object subject)
subject.toString() or null iff subject == null
@Nullable
protected static java.lang.Object binaryNumericPromotion(@Nullable
java.lang.Object value,
@Nullable
java.lang.Object other)
value to Integer, Long, Float, Double or String as appropriate for comparison with other.
Returns the original value iff the value is incomparable with other.
Examples:
value | other | Result |
|---|---|---|
| null | any | null |
| any | null | value |
| non-primitive | any | value |
| any | non-primitive | value |
| Byte | Short | Integer |
| Long | Short | Long |
| Byte | String | String |
public <T> T evaluateTo(java.lang.String spec,
Mapping<java.lang.String,?> variables,
java.lang.Class<T> targetType)
throws ParseException,
EvaluationException
T
EvaluationException - The expression evaluates to null
EvaluationException - The value is not assignable to T
ParseException
public java.lang.Object evaluateToPrimitive(java.lang.String spec,
Mapping<java.lang.String,?> variables,
java.lang.Class<?> targetType)
throws ParseException,
EvaluationException
EvaluationException - The expression evaluates to null (and the targetType is not boolean.class)
EvaluationException - The expression value cannot be converted to the given targetType
ParseException
public boolean evaluateToBoolean(@Nullable
java.lang.String spec,
Mapping<java.lang.String,?> variables)
throws ParseException,
EvaluationException
null iff the spec is null; otherwise the expresasion value
ParseException
EvaluationException
@Nullable
public static <T> T to(@Nullable
java.lang.Object subject,
java.lang.Class<T> targetType)
throws EvaluationException
subject to the given targetType.
Special processing applies for target types String and Boolean.
EvaluationExceptiontoBoolean(Object),
toString(Object)
public static <T> T toPrimitive(@Nullable
java.lang.Object subject,
java.lang.Class<T> targetType)
throws EvaluationException
subject to the given primitive target type. Special processing applies for target
type boolean.class, see toBoolean(Object).
EvaluationException - The subject is null (and the targetType is not boolean.class)
EvaluationException - The subject cannot be converted to the given targetType
public static boolean toBoolean(@Nullable
java.lang.Object subject)
subject equals on of the FALSES
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||