public final class ExpressionUtil extends Object
Expression
.Modifier and Type | Method and Description |
---|---|
static Expression |
constantExpression(Object value) |
static <T> T |
evaluateExpressionTo(String[] imports,
String input,
Class<T> targetType,
Mapping<String,?> variables)
Scans, parses and evaluates an expression, and converts the result to
<T> . |
static String |
evaluateLeniently(Expression expression,
Mapping<String,?> variables) |
static String |
evaluateLeniently(Expression expression,
Object... variableNamesAndValues) |
static <T> T |
evaluateTo(Expression expression,
Class<T> targetClass,
Mapping<String,?> variables) |
static <T> T |
evaluateTo(Expression expression,
Class<T> targetClass,
Object... variableNamesAndValues) |
static Expression |
expand(String s,
Predicate<? super String> isValidVariableName)
Turns the given string into an expression.
|
static Expression |
expand(String s,
Set<String> variableNames)
Turns the given string into an expression.
|
static Expression |
expand(String s,
String... variableNames)
Turns the given string into an expression.
|
static Expression |
fromPredicate(Predicate<? super String> predicate,
String variableName) |
static Expression |
logicalAnd(Expression operand1,
Expression operand2) |
static Expression |
logicalOr(Expression operand1,
Expression operand2) |
static <T> Predicate<T> |
toPredicate(Expression expression,
String parameterName) |
public static Expression constantExpression(@Nullable Object value)
Expression
that evaluates to a constant value;
Expression.TRUE
iff the expression is constant and evaluates to true
;
Expression.FALSE
iff the expression is constant and evaluates to false
;
Expression.NULL
iff the expression is constant and evaluates to null
public static Expression expand(String s, String... variableNames) throws ParseException
s
- The string to expandvariableNames
- All contained variable names can be used in the expressionParseException
public static Expression expand(String s, Set<String> variableNames) throws ParseException
s
- The string to expandvariableNames
- All contained variable names can be used in the expressionParseException
public static Expression expand(String s, Predicate<? super String> isValidVariableName) throws ParseException
s
- The string to expandisValidVariableName
- Evalutaes to whether the subject is a valid variable nameParseException
public static String evaluateLeniently(Expression expression, Mapping<String,?> variables)
public static String evaluateLeniently(Expression expression, Object... variableNamesAndValues)
@Nullable public static <T> T evaluateTo(Expression expression, Class<T> targetClass, Mapping<String,?> variables) throws EvaluationException
EvaluationException
- The expression evaluates to null
EvaluationException
- A problem occurred during evaluation, e.g. a class could not be loaded, or a type
cast could not be performed@Nullable public static <T> T evaluateTo(Expression expression, Class<T> targetClass, Object... variableNamesAndValues) throws EvaluationException
EvaluationException
- The expression evaluates to null
EvaluationException
- A problem occurred during evaluation, e.g. a class could not be loaded, or a type
cast could not be performed@Nullable public static <T> T evaluateExpressionTo(@Nullable String[] imports, String input, Class<T> targetType, Mapping<String,?> variables) throws ParseException, EvaluationException
<T>
.variables
- The variables that the expression can useParseException
EvaluationException
public static <T> Predicate<T> toPredicate(Expression expression, String parameterName)
T
- The type of the predicate's subjectparameterName
- The name under which the predicate subject is accessible for the expressionPredicate
which evaluates to the value of the given expression;
Expression.TRUE
iff the expression is constant and evaluates to
true
;
Expression.FALSE
iff the expression is constant and evaluates to
false
public static Expression fromPredicate(Predicate<? super String> predicate, String variableName)
Expression
which evaluates to the result of the given predicate, where the subject
to the predicate is the value of the named variable of the expressionpublic static Expression logicalAnd(Expression operand1, Expression operand2)
Expression
which evaluates the operand1, and, if that is true
the
operand2public static Expression logicalOr(Expression operand1, Expression operand2)
Expression
which evaluates the operand1, and, if that is false
the
operand2Copyright © 2018 Arno Unkrig. All rights reserved.