Class BooleanExpression
- java.lang.Object
-
- de.xima.fc.workflow.parser.infix.bool.BooleanExpression
-
public final class BooleanExpression extends Object
Utility methods specific to infix expressions consisting of boolean constant, operators, and variables. See alsoInfixExpression
. A boolean infix expression looks like this:(a or b) and c or true
The supported operators are defined byEBooleanOperator
, the defined constants byEBooleanConstant
.- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Boolean
eval(CharSequence expression, Function<String,Boolean> variableResolver, Locale locale)
Utility method that retrieves the parser, parses the infix expression, and evaluates it.static Iterable<IConstant>
getConstants()
static IInfixExpressionHandler<de.xima.fc.workflow.parser.infix.bool.EBooleanConstant,de.xima.fc.workflow.parser.infix.bool.EBooleanOperator>
getHandler()
static Iterable<IOperator>
getOperators()
static IEvalContext<Boolean,de.xima.fc.workflow.parser.infix.bool.EBooleanConstant,de.xima.fc.workflow.parser.infix.bool.EBooleanOperator>
newEvalContext(Function<String,Boolean> variableResolver)
Creates a new context for evaluating boolean expressions.
-
-
-
Method Detail
-
eval
public static Boolean eval(CharSequence expression, Function<String,Boolean> variableResolver, Locale locale) throws InfixExpressionException
Utility method that retrieves the parser, parses the infix expression, and evaluates it.- Parameters:
expression
- Expression to parse.variableResolver
- Resolver that returns the value for a given variable name. May returnnull
when no value is available -- this is treated asfalse
. If you have aMap<String, Boolean>
, you can just use amap::get
method reference.locale
- Locale for localizing error messages.- Returns:
- The result obtained by evaluating the expression with the given variable resolver.
- Throws:
InfixExpressionException
- When the expression could not be parsed or evaluated, such as when its syntax is wrong or the variable resolver threw an exception.
-
getHandler
public static IInfixExpressionHandler<de.xima.fc.workflow.parser.infix.bool.EBooleanConstant,de.xima.fc.workflow.parser.infix.bool.EBooleanOperator> getHandler()
- Returns:
- The immutable instance of the parser for boolean infix expressions.
-
newEvalContext
public static IEvalContext<Boolean,de.xima.fc.workflow.parser.infix.bool.EBooleanConstant,de.xima.fc.workflow.parser.infix.bool.EBooleanOperator> newEvalContext(Function<String,Boolean> variableResolver)
Creates a new context for evaluating boolean expressions.- Parameters:
variableResolver
- Resolver that returns the value for a given variable name. May returnnull
when no value is available -- this is treated asfalse
.- Returns:
- A new evaluation context with the given variable resolver.
-
getOperators
public static Iterable<IOperator> getOperators()
- Returns:
- A list of all operators supported by this type of expression.
-
-