Interface JexlOperator.Uberspect

  • All Superinterfaces:
    JexlArithmetic.Uberspect
    All Known Implementing Classes:
    Operator
    Enclosing class:
    JexlOperator

    public static interface JexlOperator.Uberspect
    extends JexlArithmetic.Uberspect
    Uberspect that solves and evaluates JexlOperator overloads.

    This is used by the interpreter to find and execute operator overloads implemented in a derived JexlArithmetic - or in some cases, as methods of the left argument type (contains, size, ...).

    This also allows reusing the core logic when extending the applicative type-system; for instance, implementing a Comparator class that calls compare (operator.tryOverload(this, JexlOperator.COMPARE, left, right), etc.

    Since:
    3.5.0
    • Method Detail

      • tryAssignOverload

        java.lang.Object tryAssignOverload​(JexlCache.Reference node,
                                           JexlOperator operator,
                                           java.util.function.Consumer<java.lang.Object> assign,
                                           java.lang.Object... args)
        Evaluates an assign operator.

        This takes care of finding and caching the operator method when appropriate. If an overloads returns a value not-equal to TRY_FAILED, it means the side-effect is complete. Otherwise, a += b <=> a = a + b

        Parameters:
        node - an optional reference caching resolved method or failing signature
        operator - the operator
        assign - the actual function that performs the side effect
        args - the arguments, the first one being the target of assignment
        Returns:
        JexlEngine.TRY_FAILED if no operation was performed, the value to use as the side effect argument otherwise
      • size

        java.lang.Object size​(JexlCache.Reference node,
                              java.lang.Object object)
        Calculate the size of various types: Collection, Array, Map, String, and anything that has an int size() method.

        Seeks an overload or use the default arithmetic implementation.

        Note that the result may not be an integer.

        Parameters:
        node - an optional reference caching resolved method or failing signature
        object - the object to get the size of
        Returns:
        the evaluation result
      • empty

        java.lang.Object empty​(JexlCache.Reference node,
                               java.lang.Object object)
        Check for emptiness of various types: Collection, Array, Map, String, and anything that has a boolean isEmpty() method.

        Seeks an overload or use the default arithmetic implementation.

        Note that the result may not be a boolean.

        Parameters:
        node - the node holding the object
        object - the object to check the emptiness of
        Returns:
        the evaluation result
      • contains

        boolean contains​(JexlCache.Reference node,
                         JexlOperator operator,
                         java.lang.Object left,
                         java.lang.Object right)
        The 'match'/'in' operator implementation.

        Seeks an overload or use the default arithmetic implementation.

        Note that 'x in y' or 'x matches y' means 'y contains x' ; the JEXL operator arguments order syntax is the reverse of this method call.

        Parameters:
        node - an optional reference caching resolved method or failing signature
        operator - the calling operator, =~ or !~
        right - the left operand
        left - the right operand
        Returns:
        true if left matches right, false otherwise
      • startsWith

        boolean startsWith​(JexlCache.Reference node,
                           JexlOperator operator,
                           java.lang.Object left,
                           java.lang.Object right)
        The 'startsWith' operator implementation.

        Seeks an overload or use the default arithmetic implementation.

        Parameters:
        node - an optional reference caching resolved method or failing signature
        operator - the calling operator, $= or $!
        left - the left operand
        right - the right operand
        Returns:
        true if left starts with right, false otherwise
      • endsWith

        boolean endsWith​(JexlCache.Reference node,
                         JexlOperator operator,
                         java.lang.Object left,
                         java.lang.Object right)
        The 'endsWith' operator implementation.

        Seeks an overload or use the default arithmetic implementation.

        Parameters:
        node - an optional reference caching resolved method or failing signature
        operator - the calling operator, ^= or ^!
        left - the left operand
        right - the right operand
        Returns:
        true if left ends with right, false otherwise