Class BooleanExpression


  • public final class BooleanExpression
    extends Object
    Utility methods specific to infix expressions consisting of boolean constant, operators, and variables. See also InfixExpression. A boolean infix expression looks like this:
     (a or b) and c or true
     
    The supported operators are defined by EBooleanOperator, the defined constants by EBooleanConstant.
    Since:
    7.0.0
    Author:
    XIMA MEDIA GmbH
    • 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 return null when no value is available -- this is treated as false. If you have a Map<String, Boolean>, you can just use a map::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 return null when no value is available -- this is treated as false.
        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.
      • getConstants

        public static Iterable<IConstant> getConstants()
        Returns:
        A list of all constants supported by this type of expression.