Enum JexlOperator

java.lang.Object
java.lang.Enum<JexlOperator>
org.apache.commons.jexl3.JexlOperator
All Implemented Interfaces:
Serializable, Comparable<JexlOperator>, java.lang.constant.Constable

public enum JexlOperator extends Enum<JexlOperator>
The JEXL operators. These are the operators that are executed by JexlArithmetic methods.

Each of them associates a symbol to a method signature. For instance, '+' is associated to 'T add(L x, R y)'.

The default JexlArithmetic implements generic versions of these methods using Object as arguments. You can use your own derived JexlArithmetic that override and/or overload those operator methods. Note that these are overloads by convention, not actual Java overloads. The following rules apply to all operator methods:

  • Operator methods should be public
  • Operators return type should be respected when primitive (int, boolean,...)
  • Operators may be overloaded multiple times with different signatures
  • Operators may return JexlEngine.TRY_AGAIN to fallback on default JEXL implementation
For side effect operators, operators that modify the left-hand size value (+=, -=, etc), the user implemented overload methods may return:
  • JexlEngine.TRY_FAIL to let the default fallback behavior be executed.
  • Any other value will be used as the new value to be assigned to the left-hand-side.
Note that side effect operators always return the left-hand side value (with an exception for postfix ++ and --).
Since:
3.0
  • Enum Constant Details

    • ADD

      public static final JexlOperator ADD
      Add operator.
      Syntax: x + y
      Method: T add(L x, R y);.
      See Also:
    • SUBTRACT

      public static final JexlOperator SUBTRACT
      Subtract operator.
      Syntax: x - y
      Method: T subtract(L x, R y);.
      See Also:
    • MULTIPLY

      public static final JexlOperator MULTIPLY
      Multiply operator.
      Syntax: x * y
      Method: T multiply(L x, R y);.
      See Also:
    • DIVIDE

      public static final JexlOperator DIVIDE
      Divide operator.
      Syntax: x / y
      Method: T divide(L x, R y);.
      See Also:
    • MOD

      public static final JexlOperator MOD
      Modulo operator.
      Syntax: x % y
      Method: T mod(L x, R y);.
      See Also:
    • AND

      public static final JexlOperator AND
      Bitwise-and operator.
      Syntax: x & y
      Method: T and(L x, R y);.
      See Also:
    • OR

      public static final JexlOperator OR
      Bitwise-or operator.
      Syntax: x | y
      Method: T or(L x, R y);.
      See Also:
    • XOR

      public static final JexlOperator XOR
      Bitwise-xor operator.
      Syntax: x ^ y
      Method: T xor(L x, R y);.
      See Also:
    • SHIFTRIGHT

      public static final JexlOperator SHIFTRIGHT
      Bit-pattern right-shift operator.
      Syntax: x >> y
      Method: T rightShift(L x, R y);.
      See Also:
    • SHIFTRIGHTU

      public static final JexlOperator SHIFTRIGHTU
      Bit-pattern right-shift unsigned operator.
      Syntax: x >>> y
      Method: T rightShiftUnsigned(L x, R y);.
      See Also:
    • SHIFTLEFT

      public static final JexlOperator SHIFTLEFT
      Bit-pattern left-shift operator.
      Syntax: x << y
      Method: T leftShift(L x, R y);.
      See Also:
    • EQ

      public static final JexlOperator EQ
      Equals operator.
      Syntax: x == y
      Method: boolean equals(L x, R y);.
      See Also:
    • LT

      public static final JexlOperator LT
      Less-than operator.
      Syntax: x < y
      Method: boolean lessThan(L x, R y);.
      See Also:
    • LTE

      public static final JexlOperator LTE
      Less-than-or-equal operator.
      Syntax: x <= y
      Method: boolean lessThanOrEqual(L x, R y);.
      See Also:
    • GT

      public static final JexlOperator GT
      Greater-than operator.
      Syntax: x > y
      Method: boolean greaterThan(L x, R y);.
      See Also:
    • GTE

      public static final JexlOperator GTE
      Greater-than-or-equal operator.
      Syntax: x >= y
      Method: boolean greaterThanOrEqual(L x, R y);.
      See Also:
    • CONTAINS

      public static final JexlOperator CONTAINS
      Contains operator.
      Syntax: x =~ y
      Method: boolean contains(L x, R y);.
      See Also:
    • STARTSWITH

      public static final JexlOperator STARTSWITH
      Starts-with operator.
      Syntax: x =^ y
      Method: boolean startsWith(L x, R y);.
      See Also:
    • ENDSWITH

      public static final JexlOperator ENDSWITH
      Ends-with operator.
      Syntax: x =$ y
      Method: boolean endsWith(L x, R y);.
      See Also:
    • NOT

      public static final JexlOperator NOT
      Not operator.
      Syntax: !x
      Method: T not(L x);.
      See Also:
    • COMPLEMENT

      public static final JexlOperator COMPLEMENT
      Complement operator.
      Syntax: ~x
      Method: T complement(L x);.
      See Also:
    • NEGATE

      public static final JexlOperator NEGATE
      Negate operator.
      Syntax: -x
      Method: T negate(L x);.
      See Also:
    • POSITIVIZE

      public static final JexlOperator POSITIVIZE
      Positivize operator.
      Syntax: +x
      Method: T positivize(L x);.
      See Also:
    • EMPTY

      public static final JexlOperator EMPTY
      Empty operator.
      Syntax: empty x or empty(x)
      Method: boolean empty(L x);.
      See Also:
    • SIZE

      public static final JexlOperator SIZE
      Size operator.
      Syntax: size x or size(x)
      Method: int size(L x);.
      See Also:
    • SELF_ADD

      public static final JexlOperator SELF_ADD
      Self-add operator.
      Syntax: x += y
      Method: T selfAdd(L x, R y);.
    • SELF_SUBTRACT

      public static final JexlOperator SELF_SUBTRACT
      Self-subtract operator.
      Syntax: x -= y
      Method: T selfSubtract(L x, R y);.
    • SELF_MULTIPLY

      public static final JexlOperator SELF_MULTIPLY
      Self-multiply operator.
      Syntax: x *= y
      Method: T selfMultiply(L x, R y);.
    • SELF_DIVIDE

      public static final JexlOperator SELF_DIVIDE
      Self-divide operator.
      Syntax: x /= y
      Method: T selfDivide(L x, R y);.
    • SELF_MOD

      public static final JexlOperator SELF_MOD
      Self-modulo operator.
      Syntax: x %= y
      Method: T selfMod(L x, R y);.
    • SELF_AND

      public static final JexlOperator SELF_AND
      Self-and operator.
      Syntax: x &= y
      Method: T selfAnd(L x, R y);.
    • SELF_OR

      public static final JexlOperator SELF_OR
      Self-or operator.
      Syntax: x |= y
      Method: T selfOr(L x, R y);.
    • SELF_XOR

      public static final JexlOperator SELF_XOR
      Self-xor operator.
      Syntax: x ^= y
      Method: T selfXor(L x, R y);.
    • SELF_SHIFTRIGHT

      public static final JexlOperator SELF_SHIFTRIGHT
      Self-right-shift operator.
      Syntax: x >>= y
      Method: T selfShiftRight(L x, R y);.
    • SELF_SHIFTRIGHTU

      public static final JexlOperator SELF_SHIFTRIGHTU
      Self-right-shift unsigned operator.
      Syntax: x >>> y
      Method: T selfShiftRightUnsigned(L x, R y);.
    • SELF_SHIFTLEFT

      public static final JexlOperator SELF_SHIFTLEFT
      Self-left-shift operator.
      Syntax: x << y
      Method: T selfShiftLeft(L x, R y);.
    • INCREMENT

      public static final JexlOperator INCREMENT
      Increment pseudo-operator.
      No syntax, used as helper for the prefix and postfix versions of ++.
      See Also:
    • DECREMENT

      public static final JexlOperator DECREMENT
      Decrement pseudo-operator.
      No syntax, used as helper for the prefix and postfix versions of --.
      See Also:
    • INCREMENT_AND_GET

      public static final JexlOperator INCREMENT_AND_GET
      Prefix ++ operator, increments and returns the value after incrementing.
      Syntax: ++x
      Method: T incrementAndGet(L x);.
    • GET_AND_INCREMENT

      public static final JexlOperator GET_AND_INCREMENT
      Postfix ++, increments and returns the value before incrementing.
      Syntax: x++
      Method: T getAndIncrement(L x);.
    • DECREMENT_AND_GET

      public static final JexlOperator DECREMENT_AND_GET
      Prefix --, decrements and returns the value after decrementing.
      Syntax: --x
      Method: T decrementAndGet(L x);.
    • GET_AND_DECREMENT

      public static final JexlOperator GET_AND_DECREMENT
      Postfix --, decrements and returns the value before decrementing.
      Syntax: x--
      Method: T getAndDecrement(L x);.
    • ASSIGN

      public static final JexlOperator ASSIGN
      Marker for side effect.
      Returns this from 'self*' overload method to let the engine know the side effect has been performed and there is no need to assign the result.
    • PROPERTY_GET

      public static final JexlOperator PROPERTY_GET
      Property get operator as in: x.y.
      Syntax: x.y
      Method: Object propertyGet(L x, R y);.
    • PROPERTY_SET

      public static final JexlOperator PROPERTY_SET
      Property set operator as in: x.y = z.
      Syntax: x.y = z
      Method: void propertySet(L x, R y, V z);.
    • ARRAY_GET

      public static final JexlOperator ARRAY_GET
      Array get operator as in: x[y].
      Syntax: x.y
      Method: Object arrayGet(L x, R y);.
    • ARRAY_SET

      public static final JexlOperator ARRAY_SET
      Array set operator as in: x[y] = z.
      Syntax: x[y] = z
      Method: void arraySet(L x, R y, V z);.
    • FOR_EACH

      public static final JexlOperator FOR_EACH
      Iterator generator as in for(var x : y). If the returned Iterator is AutoCloseable, close will be called after the last execution of the loop block.
      Syntax: for(var x : y){...}
      Method: Iterator<Object> forEach(R y);.
      Since:
      3.1
    • CONDITION

      public static final JexlOperator CONDITION
      Test condition in if, for, while.
      Method: boolean testCondition(R y);.
      Since:
      3.3
  • Field Details

    • operator

      private final String operator
      The operator symbol.
    • methodName

      private final String methodName
      The associated operator method name.
    • arity

      private final int arity
      The method arity (ie number of arguments).
    • base

      private final JexlOperator base
      The base operator.
  • Constructor Details

    • JexlOperator

      private JexlOperator(String o, String m, int argc)
      Creates a base operator.
      Parameters:
      o - the operator name
      m - the method name associated to this operator in a JexlArithmetic
      argc - the number of parameters for the method
    • JexlOperator

      private JexlOperator(String o, String m, JexlOperator b)
      Creates a side effect operator with arity == 2.
      Parameters:
      o - the operator name
      m - the method name associated to this operator in a JexlArithmetic
      b - the base operator, ie + for +=
    • JexlOperator

      private JexlOperator(String o, String m, JexlOperator b, int a)
      Creates a side effect operator.
      Parameters:
      o - the operator name
      m - the method name associated to this operator in a JexlArithmetic
      b - the base operator, ie + for +=
      a - the operator arity
  • Method Details

    • values

      public static JexlOperator[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static JexlOperator valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • getOperatorSymbol

      public final String getOperatorSymbol()
      Gets this operator symbol.
      Returns:
      the symbol
    • getMethodName

      public final String getMethodName()
      Gets this operator method name in a JexlArithmetic.
      Returns:
      the method name
    • getArity

      public int getArity()
      Gets this operator number of parameters.
      Returns:
      the method arity
    • getBaseOperator

      public final JexlOperator getBaseOperator()
      Gets the base operator.
      Returns:
      the base operator