Enum JexlOperator

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<JexlOperator>

    public enum JexlOperator
    extends java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int arity
      The method arity (ie number of arguments).
      private JexlOperator base
      The base operator.
      private java.lang.String methodName
      The associated operator method name.
      private java.lang.String operator
      The operator symbol.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private JexlOperator​(java.lang.String o, java.lang.String m, int argc)
      Creates a base operator.
      private JexlOperator​(java.lang.String o, java.lang.String m, JexlOperator b)
      Creates a side effect operator with arity == 2.
      private JexlOperator​(java.lang.String o, java.lang.String m, JexlOperator b, int a)
      Creates a side effect operator.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getArity()
      Gets this operator number of parameters.
      JexlOperator getBaseOperator()
      Gets the base operator.
      java.lang.String getMethodName()
      Gets this operator method name in a JexlArithmetic.
      java.lang.String getOperatorSymbol()
      Gets this operator symbol.
      static JexlOperator valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static JexlOperator[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • operator

        private final java.lang.String operator
        The operator symbol.
      • methodName

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

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

      • JexlOperator

        private JexlOperator​(java.lang.String o,
                             java.lang.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​(java.lang.String o,
                             java.lang.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​(java.lang.String o,
                             java.lang.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 Detail

      • values

        public static JexlOperator[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (JexlOperator c : JexlOperator.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static JexlOperator valueOf​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.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 java.lang.String getMethodName()
        Gets this operator method name in a JexlArithmetic.
        Returns:
        the method name
      • getOperatorSymbol

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