Enum JexlOperator

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

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

  • 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
    • 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
    • getMethodName

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

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