You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by lu...@apache.org on 2003/06/17 22:18:11 UTC

cvs commit: jakarta-commons/el/src/java/org/apache/commons/el ArithmeticOperator.java Coercions.java DivideOperator.java GreaterThanOperator.java GreaterThanOrEqualsOperator.java LessThanOperator.java LessThanOrEqualsOperator.java MinusOperator.java ModulusOperator.java MultiplyOperator.java PlusOperator.java RelationalOperator.java UnaryMinusOperator.java

luehe       2003/06/17 13:18:11

  Modified:    el/src/java/org/apache/commons/el ArithmeticOperator.java
                        Coercions.java DivideOperator.java
                        GreaterThanOperator.java
                        GreaterThanOrEqualsOperator.java
                        LessThanOperator.java LessThanOrEqualsOperator.java
                        MinusOperator.java ModulusOperator.java
                        MultiplyOperator.java PlusOperator.java
                        RelationalOperator.java UnaryMinusOperator.java
  Log:
  Fix for Bugtraq 4879322 ("Number coercions from String to
  Big(Decimal/Integer) isn't performed correctly")
  
  Patch provided by Ryan Lubke
  
  Revision  Changes    Path
  1.2       +20 -6     jakarta-commons/el/src/java/org/apache/commons/el/ArithmeticOperator.java
  
  Index: ArithmeticOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/ArithmeticOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArithmeticOperator.java	4 Feb 2003 00:22:24 -0000	1.1
  +++ ArithmeticOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,8 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   /**
    *
  @@ -86,18 +88,30 @@
      *
      * Applies the operator to the given double values, returning a double
      **/
  -  public abstract double apply (double pLeft,
  -				double pRight,
  -				Logger pLogger);
  +  public abstract double apply (double pLeft, double pRight);
     
     //-------------------------------------
     /**
      *
      * Applies the operator to the given double values, returning a double
      **/
  -  public abstract long apply (long pLeft,
  -			      long pRight,
  -			      Logger pLogger);
  +  public abstract long apply (long pLeft, long pRight);
     
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public abstract BigDecimal apply(BigDecimal pLeft, BigDecimal pRight);
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public abstract BigInteger apply(BigInteger pLeft, BigInteger pRight);
  +
  +    //-------------------------------------
   }
  
  
  
  1.3       +122 -22   jakarta-commons/el/src/java/org/apache/commons/el/Coercions.java
  
  Index: Coercions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/Coercions.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Coercions.java	17 Jun 2003 17:31:27 -0000	1.2
  +++ Coercions.java	17 Jun 2003 20:18:10 -0000	1.3
  @@ -74,9 +74,17 @@
    *   Binary operator - A {+,-,*} B
    *     if A and B are null
    *       return 0
  + *     if A or B is BigDecimal, coerce both to BigDecimal and then:
  + *       if operator is +, return <code>A.add(B)</code>
  + *       if operator is -, return <code>A.subtract(B)</code>
  + *       if operator is *, return <code>A.multiply(B)</code>
    *     if A or B is Float, Double, or String containing ".", "e", or "E"
  - *       coerce both A and B to Double
  - *       apply operator
  + *       if A or B is BigInteger, coerce both A and B to BigDecimal and apply operator
  + *       coerce both A and B to Double and apply operator
  + *     if A or B is BigInteger, coerce both to BigInteger and then:
  + *       if operator is +, return <code>A.add(B)</code>
  + *       if operator is -, return <code>A.subtract(B)</code>
  + *       if operator is *, return <code>A.multiply(B)</code>
    *     otherwise
    *       coerce both A and B to Long
    *       apply operator
  @@ -85,6 +93,8 @@
    *   Binary operator - A {/,div} B
    *     if A and B are null
    *       return 0
  + *     if A or B is a BigDecimal or BigInteger, coerce both to BigDecimal and
  + *      return <code>A.divide(B, BigDecimal.ROUND_HALF_UP)</code>
    *     otherwise
    *       coerce both A and B to Double
    *       apply operator
  @@ -93,9 +103,11 @@
    *   Binary operator - A {%,mod} B
    *     if A and B are null
    *       return 0
  - *     if A or B is Float, Double, or String containing ".", "e" or "E"
  + *     if A or B is BigDecimal, Float, Double, or String containing ".", "e" or "E"
    *       coerce both to Double
    *       apply operator
  + *     if A or B is BigInteger, coerce both to BigInteger and return
  + *      <code>A.remainder(B)</code>
    *     otherwise
    *       coerce both A and B to Long
    *       apply operator
  @@ -104,6 +116,7 @@
    *   Unary minus operator - -A
    *     if A is null
    *       return 0
  + *     if A is BigInteger or BigDecimal, return <code>A.negate()</code>
    *     if A is String
    *       if A contains ".", "e", or "E"
    *         coerce to Double, apply operator
  @@ -126,6 +139,8 @@
    *     return true
    *   if A is Map and ((Map) A).isEmpty()
    *     return true
  + *   if A is Collection an ((Collection) A).isEmpty()
  + *     return true
    *   otherwise
    *     return false
    * 
  @@ -146,9 +161,13 @@
    *         return false
    *     if A or B is null
    *       return false
  + *     if A or B is BigDecimal, coerce both A and B to BigDecimal and use the
  + *      return value of <code>A.compareTo(B)</code>
    *     if A or B is Float or Double
    *       coerce both A and B to Double
    *       apply operator
  + *     if A or B is BigInteger, coerce both A and B to BigInteger and use the
  + *      return value of <code>A.compareTo(B)</code>
    *     if A or B is Byte,Short,Character,Integer,Long
    *       coerce both A and B to Long
    *       apply operator
  @@ -173,9 +192,15 @@
    *       apply operator
    *     if A or B is null
    *       return false for ==, true for !=
  + *     if A or B is BigDecimal, coerce both A and B to BigDecimal and then:
  + *       if operator is == or eq, return <code>A.equals(B)</code>
  + *       if operator is != or ne, return <code>!A.equals(B)</code>
    *     if A or B is Float or Double
    *       coerce both A and B to Double
    *       apply operator
  + *     if A or B is BigInteger, coerce both A and B to BigInteger and then:
  + *       if operator is == or eq, return <code>A.equals(B)</code>
  + *       if operator is != or ne, return <code>!A.equals(B)</code>
    *     if A or B is Byte,Short,Character,Integer,Long
    *       coerce both A and B to Long
    *       apply operator
  @@ -805,18 +830,42 @@
         return PrimitiveObjects.getInteger (0);
       }
   
  -    else if (isFloatingPointType (pLeft) ||
  -	     isFloatingPointType (pRight) ||
  -	     isFloatingPointString (pLeft) ||
  -	     isFloatingPointString (pRight)) {
  -      double left =
  -	coerceToPrimitiveNumber (pLeft, Double.class, pLogger).
  -	doubleValue ();
  -      double right =
  -	coerceToPrimitiveNumber (pRight, Double.class, pLogger).
  -	doubleValue ();
  -      return 
  -	PrimitiveObjects.getDouble (pOperator.apply (left, right, pLogger));
  +    else if (isBigDecimal(pLeft) || isBigDecimal(pRight)) {
  +        BigDecimal left = (BigDecimal)
  +            coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
  +        BigDecimal right = (BigDecimal)
  +            coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
  +        return pOperator.apply(left, right);
  +    }
  +
  +    else if (isFloatingPointType(pLeft) ||
  +        isFloatingPointType(pRight) ||
  +        isFloatingPointString(pLeft) ||
  +        isFloatingPointString(pRight)) {
  +        if (isBigInteger(pLeft) || isBigInteger(pRight)) {
  +            BigDecimal left = (BigDecimal)
  +                coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
  +            BigDecimal right = (BigDecimal)
  +                coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
  +            return pOperator.apply(left, right);
  +        } else {
  +            double left =
  +                coerceToPrimitiveNumber(pLeft, Double.class, pLogger).
  +                doubleValue();
  +            double right =
  +                coerceToPrimitiveNumber(pRight, Double.class, pLogger).
  +                doubleValue();
  +            return
  +                PrimitiveObjects.getDouble(pOperator.apply(left, right));
  +        }
  +    }
  +
  +    else if (isBigInteger(pLeft) || isBigInteger(pRight)) {
  +        BigInteger left = (BigInteger)
  +            coerceToPrimitiveNumber(pLeft, BigInteger.class, pLogger);
  +        BigInteger right = (BigInteger)
  +            coerceToPrimitiveNumber(pRight, BigInteger.class, pLogger);
  +        return pOperator.apply(left, right);
       }
   
       else {
  @@ -827,7 +876,7 @@
   	coerceToPrimitiveNumber (pRight, Long.class, pLogger).
   	longValue ();
         return
  -	PrimitiveObjects.getLong (pOperator.apply (left, right, pLogger));
  +	PrimitiveObjects.getLong (pOperator.apply (left, right));
       }
     }
   
  @@ -844,7 +893,15 @@
        Logger pLogger)
       throws ELException
     {
  -    if (isFloatingPointType (pLeft) ||
  +    if (isBigDecimal(pLeft) || isBigDecimal(pRight)) {
  +        BigDecimal left = (BigDecimal)
  +            coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
  +        BigDecimal right = (BigDecimal)
  +            coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
  +        return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
  +    }
  +
  +    else if (isFloatingPointType (pLeft) ||
   	isFloatingPointType (pRight)) {
         double left =
   	coerceToPrimitiveNumber (pLeft, Double.class, pLogger).
  @@ -853,7 +910,15 @@
   	coerceToPrimitiveNumber (pRight, Double.class, pLogger).
   	doubleValue ();
         return 
  -	PrimitiveObjects.getBoolean (pOperator.apply (left, right, pLogger));
  +	PrimitiveObjects.getBoolean (pOperator.apply (left, right));
  +    }
  +
  +    else if (isBigInteger(pLeft) || isBigInteger(pRight)) {
  +        BigInteger left = (BigInteger)
  +            coerceToPrimitiveNumber(pLeft, BigInteger.class, pLogger);
  +        BigInteger right = (BigInteger)
  +            coerceToPrimitiveNumber(pRight, BigInteger.class, pLogger);
  +        return PrimitiveObjects.getBoolean(pOperator.apply(left, right));
       }
   
       else if (isIntegerType (pLeft) ||
  @@ -865,7 +930,7 @@
   	coerceToPrimitiveNumber (pRight, Long.class, pLogger).
   	longValue ();
         return
  -	PrimitiveObjects.getBoolean (pOperator.apply (left, right, pLogger));
  +	PrimitiveObjects.getBoolean (pOperator.apply (left, right));
       }
   
       else if (pLeft instanceof String ||
  @@ -873,7 +938,7 @@
         String left = coerceToString (pLeft, pLogger);
         String right = coerceToString (pRight, pLogger);
         return
  -	PrimitiveObjects.getBoolean (pOperator.apply (left, right, pLogger));
  +	PrimitiveObjects.getBoolean (pOperator.apply (left, right));
       }
   
       else if (pLeft instanceof Comparable) {
  @@ -881,7 +946,7 @@
   	int result = ((Comparable) pLeft).compareTo (pRight);
   	return
   	  PrimitiveObjects.getBoolean 
  -	  (pOperator.apply (result, -result, pLogger));
  +	  (pOperator.apply (result, -result));
         }
         catch (Exception exc) {
   	if (pLogger.isLoggingError ()) {
  @@ -901,7 +966,7 @@
   	int result = ((Comparable) pRight).compareTo (pLeft);
   	return
   	  PrimitiveObjects.getBoolean 
  -	  (pOperator.apply (-result, result, pLogger));
  +	  (pOperator.apply (-result, result));
         }
         catch (Exception exc) {
   	if (pLogger.isLoggingError ()) {
  @@ -950,6 +1015,14 @@
         return PrimitiveObjects.getBoolean (pOperator.apply (false, pLogger));
       }
   
  +    else if (isBigDecimal(pLeft) || isBigDecimal(pRight)) {
  +        BigDecimal left = (BigDecimal)
  +            coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
  +        BigDecimal right = (BigDecimal)
  +            coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
  +        return PrimitiveObjects.getBoolean(pOperator.apply(left.equals(right), pLogger));
  +    }
  +
       else if (isFloatingPointType (pLeft) ||
   	     isFloatingPointType (pRight)) {
         double left =
  @@ -963,6 +1036,14 @@
   	(pOperator.apply (left == right, pLogger));
       }
   
  +    else if (isBigInteger(pLeft) || isBigInteger(pRight)) {
  +        BigInteger left = (BigInteger)
  +            coerceToPrimitiveNumber(pLeft, BigInteger.class, pLogger);
  +        BigInteger right = (BigInteger)
  +            coerceToPrimitiveNumber(pRight, BigInteger.class, pLogger);
  +        return PrimitiveObjects.getBoolean(pOperator.apply(left.equals(right), pLogger));
  +    }
  +
       else if (isIntegerType (pLeft) ||
   	     isIntegerType (pRight)) {
         long left =
  @@ -1100,4 +1181,23 @@
   
     //-------------------------------------
   
  +  /**
  +   * Returns true if the given object is BigInteger.
  +   * @param pObject - Object to evaluate
  +   * @return - true if the given object is BigInteger
  +   */
  +  public static boolean isBigInteger(Object pObject) {
  +      return
  +          pObject != null && pObject instanceof BigInteger;
  +  }
  +
  +  /**
  +   * Returns true if the given object is BigDecimal.
  +   * @param pObject - Object to evaluate
  +   * @return - true if the given object is BigDecimal
  +   */
  +  public static boolean isBigDecimal(Object pObject) {
  +      return
  +          pObject != null && pObject instanceof BigDecimal;
  +  }
   }
  
  
  
  1.2       +44 -19    jakarta-commons/el/src/java/org/apache/commons/el/DivideOperator.java
  
  Index: DivideOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/DivideOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DivideOperator.java	4 Feb 2003 00:22:24 -0000	1.1
  +++ DivideOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,7 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
   
   /**
    *
  @@ -116,25 +117,49 @@
         return PrimitiveObjects.getInteger (0);
       }
   
  -    double left =
  -      Coercions.coerceToPrimitiveNumber (pLeft, Double.class, pLogger).
  -      doubleValue ();
  -    double right =
  -      Coercions.coerceToPrimitiveNumber (pRight, Double.class, pLogger).
  -      doubleValue ();
  -
  -    try {
  -      return PrimitiveObjects.getDouble (left / right);
  -    }
  -    catch (Exception exc) {
  -      if (pLogger.isLoggingError ()) {
  -	pLogger.logError
  -	  (Constants.ARITH_ERROR,
  -	   getOperatorSymbol (),
  -	   "" + left,
  -	   "" + right);
  -      }
  -      return PrimitiveObjects.getInteger (0);
  +    if (Coercions.isBigDecimal(pLeft) ||
  +        Coercions.isBigInteger(pLeft) ||
  +        Coercions.isBigDecimal(pRight) ||
  +        Coercions.isBigInteger(pRight)) {
  +
  +        BigDecimal left = (BigDecimal)
  +            Coercions.coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
  +        BigDecimal right = (BigDecimal)
  +            Coercions.coerceToPrimitiveNumber(pRight, BigDecimal.class, pLogger);
  +
  +        try {
  +            return left.divide(right, BigDecimal.ROUND_HALF_UP);
  +        } catch (Exception exc) {
  +            if (pLogger.isLoggingError()) {
  +                pLogger.logError
  +                    (Constants.ARITH_ERROR,
  +                        getOperatorSymbol(),
  +                        "" + left,
  +                        "" + right);
  +            }
  +            return PrimitiveObjects.getInteger(0);
  +        }
  +    } else {
  +
  +        double left =
  +            Coercions.coerceToPrimitiveNumber(pLeft, Double.class, pLogger).
  +            doubleValue();
  +        double right =
  +            Coercions.coerceToPrimitiveNumber(pRight, Double.class, pLogger).
  +            doubleValue();
  +
  +        try {
  +            return PrimitiveObjects.getDouble(left / right);
  +        } catch (Exception exc) {
  +            if (pLogger.isLoggingError()) {
  +                pLogger.logError
  +                    (Constants.ARITH_ERROR,
  +                        getOperatorSymbol(),
  +                        "" + left,
  +                        "" + right);
  +            }
  +            return PrimitiveObjects.getInteger(0);
  +        }
       }
     }
   
  
  
  
  1.2       +25 -12    jakarta-commons/el/src/java/org/apache/commons/el/GreaterThanOperator.java
  
  Index: GreaterThanOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/GreaterThanOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GreaterThanOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ GreaterThanOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,8 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   /**
    *
  @@ -123,10 +125,7 @@
      *
      * Applies the operator to the given double values
      **/
  -  public boolean apply (double pLeft,
  -			double pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (double pLeft, double pRight) {
       return pLeft > pRight;
     }
     
  @@ -135,10 +134,7 @@
      *
      * Applies the operator to the given long values
      **/
  -  public boolean apply (long pLeft,
  -			long pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (long pLeft, long pRight) {
       return pLeft > pRight;
     }
     
  @@ -147,12 +143,29 @@
      *
      * Applies the operator to the given String values
      **/
  -  public boolean apply (String pLeft,
  -			String pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (String pLeft, String pRight) {
       return pLeft.compareTo (pRight) > 0;
     }
   
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigDecimal pLeft, BigDecimal pRight) {
  +        return isGreater(pLeft.compareTo(pRight));
  +    }
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigInteger pLeft, BigInteger pRight) {
  +        return isGreater(pLeft.compareTo(pRight));
  +    }
  +
  +    //-------------------------------------
   }
  
  
  
  1.2       +25 -12    jakarta-commons/el/src/java/org/apache/commons/el/GreaterThanOrEqualsOperator.java
  
  Index: GreaterThanOrEqualsOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/GreaterThanOrEqualsOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GreaterThanOrEqualsOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ GreaterThanOrEqualsOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,8 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   /**
    *
  @@ -123,10 +125,7 @@
      *
      * Applies the operator to the given double values
      **/
  -  public boolean apply (double pLeft,
  -			double pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (double pLeft, double pRight) {
       return pLeft >= pRight;
     }
     
  @@ -135,10 +134,7 @@
      *
      * Applies the operator to the given long values
      **/
  -  public boolean apply (long pLeft,
  -			long pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (long pLeft, long pRight) {
       return pLeft >= pRight;
     }
     
  @@ -147,12 +143,29 @@
      *
      * Applies the operator to the given String values
      **/
  -  public boolean apply (String pLeft,
  -			String pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (String pLeft, String pRight) {
       return pLeft.compareTo (pRight) >= 0;
     }
   
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigDecimal pLeft, BigDecimal pRight) {
  +        return (isGreater(pLeft.compareTo(pRight)) || isEqual(pLeft.compareTo(pRight)));
  +    }
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigInteger pLeft, BigInteger pRight) {
  +        return (isGreater(pLeft.compareTo(pRight)) || isEqual(pLeft.compareTo(pRight)));
  +    }
  +
  +    //-------------------------------------
   }
  
  
  
  1.2       +25 -12    jakarta-commons/el/src/java/org/apache/commons/el/LessThanOperator.java
  
  Index: LessThanOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/LessThanOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LessThanOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ LessThanOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,8 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   /**
    *
  @@ -123,10 +125,7 @@
      *
      * Applies the operator to the given double values
      **/
  -  public boolean apply (double pLeft,
  -			double pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (double pLeft, double pRight) {
       return pLeft < pRight;
     }
     
  @@ -135,10 +134,7 @@
      *
      * Applies the operator to the given long values
      **/
  -  public boolean apply (long pLeft,
  -			long pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (long pLeft, long pRight) {
       return pLeft < pRight;
     }
     
  @@ -147,12 +143,29 @@
      *
      * Applies the operator to the given String values
      **/
  -  public boolean apply (String pLeft,
  -			String pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (String pLeft, String pRight) {
       return pLeft.compareTo (pRight) < 0;
     }
   
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigDecimal pLeft, BigDecimal pRight) {
  +        return isLess(pLeft.compareTo(pRight));
  +    }
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigInteger pLeft, BigInteger pRight) {
  +        return isLess(pLeft.compareTo(pRight));
  +    }
  +
  +    //-------------------------------------
   }
  
  
  
  1.2       +25 -12    jakarta-commons/el/src/java/org/apache/commons/el/LessThanOrEqualsOperator.java
  
  Index: LessThanOrEqualsOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/LessThanOrEqualsOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LessThanOrEqualsOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ LessThanOrEqualsOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,8 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   /**
    *
  @@ -123,10 +125,7 @@
      *
      * Applies the operator to the given double values
      **/
  -  public boolean apply (double pLeft,
  -			double pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (double pLeft, double pRight) {
       return pLeft <= pRight;
     }
     
  @@ -135,10 +134,7 @@
      *
      * Applies the operator to the given long values
      **/
  -  public boolean apply (long pLeft,
  -			long pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (long pLeft, long pRight) {
       return pLeft <= pRight;
     }
     
  @@ -147,12 +143,29 @@
      *
      * Applies the operator to the given String values
      **/
  -  public boolean apply (String pLeft,
  -			String pRight,
  -			Logger pLogger)
  -  {
  +  public boolean apply (String pLeft, String pRight) {
       return pLeft.compareTo (pRight) <= 0;
     }
   
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigDecimal pLeft, BigDecimal pRight) {
  +        return (isLess(pLeft.compareTo(pRight)) || isEqual(pLeft.compareTo(pRight)));
  +    }
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public boolean apply(BigInteger pLeft, BigInteger pRight) {
  +        return (isLess(pLeft.compareTo(pRight)) || isEqual(pLeft.compareTo(pRight)));
  +    }
  +
  +    //-------------------------------------
   }
  
  
  
  1.2       +26 -10    jakarta-commons/el/src/java/org/apache/commons/el/MinusOperator.java
  
  Index: MinusOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/MinusOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MinusOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ MinusOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -55,6 +55,9 @@
   
   package org.apache.commons.el;
   
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
  +
   /**
    *
    * <p>The implementation of the minus operator
  @@ -89,8 +92,7 @@
      *
      * Returns the symbol representing the operator
      **/
  -  public String getOperatorSymbol ()
  -  {
  +  public String getOperatorSymbol () {
       return "-";
     }
   
  @@ -99,10 +101,7 @@
      *
      * Applies the operator to the given double values, returning a double
      **/
  -  public double apply (double pLeft,
  -		       double pRight,
  -		       Logger pLogger)
  -  {
  +  public double apply (double pLeft, double pRight) {
       return pLeft - pRight;
     }
     
  @@ -111,12 +110,29 @@
      *
      * Applies the operator to the given double values, returning a double
      **/
  -  public long apply (long pLeft,
  -		     long pRight,
  -		     Logger pLogger)
  -  {
  +  public long apply (long pLeft, long pRight) {
       return pLeft - pRight;
     }
     
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public BigDecimal apply(BigDecimal pLeft, BigDecimal pRight) {
  +        return pLeft.subtract(pRight);
  +    }
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigInteger values, returning a BigInteger
  +     **/
  +    public BigInteger apply(BigInteger pLeft, BigInteger pRight) {
  +        return pLeft.subtract(pRight);
  +    }
  +
  +    //-------------------------------------
   }
  
  
  
  1.2       +23 -1     jakarta-commons/el/src/java/org/apache/commons/el/ModulusOperator.java
  
  Index: ModulusOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/ModulusOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModulusOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ ModulusOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,7 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigInteger;
   
   /**
    *
  @@ -119,9 +120,11 @@
       if ((pLeft != null &&
   	 (Coercions.isFloatingPointType (pLeft) ||
   	  Coercions.isFloatingPointString (pLeft))) ||
  +      Coercions.isBigDecimal(pLeft) ||
   	(pRight != null &&
   	 (Coercions.isFloatingPointType (pRight) ||
  -	  Coercions.isFloatingPointString (pRight)))) {
  +	  Coercions.isFloatingPointString (pRight) ||
  +      Coercions.isBigDecimal(pRight)))) {
         double left =
   	Coercions.coerceToPrimitiveNumber (pLeft, Double.class, pLogger).
   	doubleValue ();
  @@ -142,6 +145,25 @@
   	}
   	return PrimitiveObjects.getInteger (0);
         }
  +    }
  +    else if (Coercions.isBigInteger(pLeft) || Coercions.isBigInteger(pRight)) {
  +        BigInteger left = (BigInteger)
  +             Coercions.coerceToPrimitiveNumber(pLeft, BigInteger.class, pLogger);
  +        BigInteger right = (BigInteger)
  +            Coercions.coerceToPrimitiveNumber(pRight, BigInteger.class, pLogger);
  +
  +        try {
  +            return left.remainder(right);
  +        } catch (Exception exc) {
  +            if (pLogger.isLoggingError()) {
  +                pLogger.logError
  +                    (Constants.ARITH_ERROR,
  +                        getOperatorSymbol(),
  +                        "" + left,
  +                        "" + right);
  +            }
  +            return PrimitiveObjects.getInteger(0);
  +        }
       }
       else {
         long left =
  
  
  
  1.2       +31 -4     jakarta-commons/el/src/java/org/apache/commons/el/MultiplyOperator.java
  
  Index: MultiplyOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/MultiplyOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MultiplyOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ MultiplyOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -55,6 +55,9 @@
   
   package org.apache.commons.el;
   
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
  +
   /**
    *
    * <p>The implementation of the multiply operator
  @@ -100,8 +103,8 @@
      * Applies the operator to the given double values, returning a double
      **/
     public double apply (double pLeft,
  -		       double pRight,
  -		       Logger pLogger)
  +		       double pRight
  +                       )
     {
       return pLeft * pRight;
     }
  @@ -112,11 +115,35 @@
      * Applies the operator to the given double values, returning a double
      **/
     public long apply (long pLeft,
  -		     long pRight,
  -		     Logger pLogger)
  +		     long pRight
  +                     )
     {
       return pLeft * pRight;
     }
     
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public BigDecimal apply(BigDecimal pLeft,
  +                            BigDecimal pRight
  +                            ) {
  +        return pLeft.multiply(pRight);
  +    }
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigInteger values, returning a BigInteger
  +     **/
  +    public BigInteger apply(BigInteger pLeft,
  +                            BigInteger pRight
  +                            ) {
  +        return pLeft.multiply(pRight);
  +    }
  +
  +    //-------------------------------------
   }
  
  
  
  1.2       +27 -10    jakarta-commons/el/src/java/org/apache/commons/el/PlusOperator.java
  
  Index: PlusOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/PlusOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PlusOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ PlusOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -55,6 +55,10 @@
   
   package org.apache.commons.el;
   
  +import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
  +
   /**
    *
    * <p>The implementation of the plus operator
  @@ -89,8 +93,7 @@
      *
      * Returns the symbol representing the operator
      **/
  -  public String getOperatorSymbol ()
  -  {
  +  public String getOperatorSymbol () {
       return "+";
     }
   
  @@ -99,10 +102,7 @@
      *
      * Applies the operator to the given double values, returning a double
      **/
  -  public double apply (double pLeft,
  -		       double pRight,
  -		       Logger pLogger)
  -  {
  +  public double apply (double pLeft, double pRight) {
       return pLeft + pRight;
     }
     
  @@ -111,12 +111,29 @@
      *
      * Applies the operator to the given double values, returning a double
      **/
  -  public long apply (long pLeft,
  -		     long pRight,
  -		     Logger pLogger)
  -  {
  +  public long apply (long pLeft, long pRight) {
       return pLeft + pRight;
     }
     
     //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public BigDecimal apply(BigDecimal pLeft, BigDecimal pRight) {
  +        return pLeft.add(pRight);
  +    }
  +
  +    //-------------------------------------
  +
  +    /**
  +     *
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public BigInteger apply(BigInteger pLeft, BigInteger pRight) {
  +        return pLeft.add(pRight);
  +    }
  +
  +    //-------------------------------------
   }
  
  
  
  1.2       +61 -6     jakarta-commons/el/src/java/org/apache/commons/el/RelationalOperator.java
  
  Index: RelationalOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/RelationalOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RelationalOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ RelationalOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,8 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigDecimal;
  +import java.math.BigInteger;
   
   /**
    *
  @@ -69,6 +71,7 @@
   public abstract class RelationalOperator
     extends BinaryOperator
   {
  +
     //-------------------------------------
     /**
      *
  @@ -88,8 +91,8 @@
      * Applies the operator to the given double values
      **/
     public abstract boolean apply (double pLeft,
  -				 double pRight,
  -				 Logger pLogger);
  +				 double pRight
  +                                 );
     
     //-------------------------------------
     /**
  @@ -97,8 +100,8 @@
      * Applies the operator to the given long values
      **/
     public abstract boolean apply (long pLeft,
  -				 long pRight,
  -				 Logger pLogger);
  +				 long pRight
  +                                 );
     
     //-------------------------------------
     /**
  @@ -106,8 +109,60 @@
      * Applies the operator to the given String values
      **/
     public abstract boolean apply (String pLeft,
  -				 String pRight,
  -				 Logger pLogger);
  +				 String pRight
  +                                 );
   
     //-------------------------------------
  +
  +
  +    /**
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public abstract boolean apply(BigDecimal pLeft, BigDecimal pRight);
  +
  +    //-------------------------------------
  +
  +    /**
  +     * Applies the operator to the given BigDecimal values, returning a BigDecimal
  +     **/
  +    public abstract boolean apply(BigInteger pLeft, BigInteger pRight);
  +
  +    //-------------------------------------
  +
  +
  +    /**
  +     * Test return value of BigInteger/BigDecimal A.compareTo(B).
  +     * @param val - result of BigInteger/BigDecimal compareTo() call
  +     * @return - true if result is less than 0, otherwise false
  +     */
  +    protected boolean isLess(int val) {
  +        if (val < 0)
  +            return true;
  +        else
  +            return false;
  +    }
  +
  +    /**
  +     * Test return value of BigInteger/BigDecimal A.compareTo(B).
  +     * @param val - result of BigInteger/BigDecimal compareTo() call
  +     * @return - true if result is equal to 0, otherwise false
  +     */
  +    protected boolean isEqual(int val) {
  +        if (val == 0)
  +            return true;
  +        else
  +            return false;
  +    }
  +
  +    /**
  +     * Test return value of BigInteger/BigDecimal A.compareTo(B).
  +     * @param val - result of BigInteger/BigDecimal compareTo() call
  +     * @return - true if result is greater than 0, otherwise false
  +     */
  +    protected boolean isGreater(int val) {
  +        if (val > 0)
  +            return true;
  +        else
  +            return false;
  +    }
   }
  
  
  
  1.2       +10 -0     jakarta-commons/el/src/java/org/apache/commons/el/UnaryMinusOperator.java
  
  Index: UnaryMinusOperator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/el/src/java/org/apache/commons/el/UnaryMinusOperator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UnaryMinusOperator.java	4 Feb 2003 00:22:25 -0000	1.1
  +++ UnaryMinusOperator.java	17 Jun 2003 20:18:10 -0000	1.2
  @@ -56,6 +56,8 @@
   package org.apache.commons.el;
   
   import javax.servlet.jsp.el.ELException;
  +import java.math.BigInteger;
  +import java.math.BigDecimal;
   
   /**
    *
  @@ -114,6 +116,14 @@
         }
         */
         return PrimitiveObjects.getInteger (0);
  +    }
  +
  +    else if (pValue instanceof BigInteger) {
  +        return ((BigInteger) pValue).negate();
  +    }
  +
  +    else if (pValue instanceof BigDecimal) {
  +        return ((BigDecimal) pValue).negate();
       }
   
       else if (pValue instanceof String) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org