commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r589324 - in /commons/proper/jexl/branches/2.0/src: java/org/apache/commons/jexl/Interpreter.java test/org/apache/commons/jexl/JexlTest.java
Date Sun, 28 Oct 2007 10:30:32 GMT
Author: dion
Date: Sun Oct 28 03:30:28 2007
New Revision: 589324

URL: http://svn.apache.org/viewvc?rev=589324&view=rev
Log:
add relation equality operators for big dec and big int
JEXL-30

Modified:
    commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java
    commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java

Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java?rev=589324&r1=589323&r2=589324&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java Sun
Oct 28 03:30:28 2007
@@ -1025,6 +1025,8 @@
             return false;
         } else if (left.getClass().equals(right.getClass())) {
             return left.equals(right);
+        } else if (left instanceof BigDecimal || right instanceof BigDecimal) {
+            return Coercion.coerceBigDecimal(left).compareTo(Coercion.coerceBigDecimal(right))
== 0;
         } else if (isFloatingPointType(left, right)) {
             Double l = Coercion.coerceDouble(left);
             Double r = Coercion.coerceDouble(right);
@@ -1067,6 +1069,10 @@
             double rightDouble = Coercion.coerceDouble(right).doubleValue();
 
             return leftDouble < rightDouble;
+            } else if (left instanceof BigDecimal || right instanceof BigDecimal) {
+                BigDecimal l  = Coercion.coerceBigDecimal(left);
+                BigDecimal r  = Coercion.coerceBigDecimal(right);
+                return l.compareTo(r) < 0;
         } else if (Coercion.isNumberable(left) || Coercion.isNumberable(right)) {
             long leftLong = Coercion.coerceLong(left).longValue();
             long rightLong = Coercion.coerceLong(right).longValue();

Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java?rev=589324&r1=589323&r2=589324&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java Sun Oct
28 03:30:28 2007
@@ -17,6 +17,8 @@
 package org.apache.commons.jexl;
 
 import java.io.StringReader;
+import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.Calendar;
@@ -115,6 +117,8 @@
         jc.getVars().put("now", Calendar.getInstance().getTime());
         GregorianCalendar gc = new GregorianCalendar(5000, 11, 20);
         jc.getVars().put("now2", gc.getTime());
+        jc.getVars().put("bdec", new BigDecimal(7));
+        jc.getVars().put("bint", new BigInteger("7"));
 
         assertExpression(jc, "a == b", Boolean.FALSE);
         assertExpression(jc, "a==true", Boolean.TRUE);
@@ -152,6 +156,15 @@
 
         assertExpression(jc, "\"foo\" + \"bar\" == \"foobar\"", Boolean.TRUE);
 
+        assertExpression(jc, "bdec > num", Boolean.TRUE);
+        assertExpression(jc, "bdec >= num", Boolean.TRUE);
+        assertExpression(jc, "num <= bdec", Boolean.TRUE);
+        assertExpression(jc, "num < bdec", Boolean.TRUE);
+        assertExpression(jc, "bint > num", Boolean.TRUE);
+        assertExpression(jc, "bint == bdec", Boolean.TRUE);
+        assertExpression(jc, "bint >= num", Boolean.TRUE);
+        assertExpression(jc, "num <= bint", Boolean.TRUE);
+        assertExpression(jc, "num < bint", Boolean.TRUE);
     }
 
     public void testEmpty()



Mime
View raw message