Class AbstractEvaluator

    • Constructor Detail

      • AbstractEvaluator

        public AbstractEvaluator()
    • Method Detail

      • evaluate

        public boolean evaluate​(String expression,
                                Map<String,​Object> values)
        Description copied from interface: IEvaluator
        Evaluate an expression as a boolean response.
        Specified by:
        evaluate in interface IEvaluator
        Parameters:
        expression - the expression to evaluate
        values - the variables that the expression can evaluate against
        Returns:
        true if the expression evaluates to truthy value.
        See Also:
        objectToBoolean(Object)
      • objectToBoolean

        public static boolean objectToBoolean​(Object obj)
        Given an input convert to a boolean expression.

        As Java doesn't have inherit truthiness such as JavaScript. We want to simulate it here, we will convert the following to inputs, all other inputs are true.

        • null - All null values are false.
        • boolean = All booleans are returned as they are.
        • 0 = All numbers are true, except 0 which is false
        • "true" = A string of the value "true" (ignoring case) is true, all other strings are false.
        Parameters:
        obj - the value to convert
        Returns:
        the value as a boolean
        See Also:
        Boolean.parseBoolean(String)