commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r611543 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang/builder/EqualsBuilder.java test/org/apache/commons/lang/builder/EqualsBuilderTest.java
Date Sun, 13 Jan 2008 07:00:23 GMT
Author: bayard
Date: Sat Jan 12 23:00:22 2008
New Revision: 611543

URL: http://svn.apache.org/viewvc?rev=611543&view=rev
Log:
Applying my patch from LANG-393; EqualsBuilder uses compareTo for BigDecimal and not equals

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/EqualsBuilder.java
    commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/EqualsBuilderTest.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/EqualsBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/EqualsBuilder.java?rev=611543&r1=611542&r2=611543&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/EqualsBuilder.java
(original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/builder/EqualsBuilder.java
Sat Jan 12 23:00:22 2008
@@ -377,8 +377,12 @@
         }
         Class lhsClass = lhs.getClass();
         if (!lhsClass.isArray()) {
-            // The simple case, not an array, just test the element
-            isEquals = lhs.equals(rhs);
+            if (lhs instanceof java.math.BigDecimal) {
+                isEquals = (((java.math.BigDecimal)lhs).compareTo(rhs) == 0);
+            } else {
+                // The simple case, not an array, just test the element
+                isEquals = lhs.equals(rhs);
+            }
         } else if (lhs.getClass() != rhs.getClass()) {
             // Here when we compare different dimensions, for example: a boolean[][] to a
boolean[] 
             this.setEquals(false);

Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/EqualsBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/EqualsBuilderTest.java?rev=611543&r1=611542&r2=611543&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/EqualsBuilderTest.java
(original)
+++ commons/proper/lang/trunk/src/test/org/apache/commons/lang/builder/EqualsBuilderTest.java
Sat Jan 12 23:00:22 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.lang.builder;
 
+import java.math.BigDecimal;
 import java.util.Arrays;
 
 import junit.framework.Test;
@@ -374,6 +375,14 @@
         assertTrue(!new EqualsBuilder().append(o1, Float.NaN).isEquals());
         assertTrue(new EqualsBuilder().append(Float.NaN, Float.NaN).isEquals());
         assertTrue(new EqualsBuilder().append(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).isEquals());
+    }
+
+    // https://issues.apache.org/jira/browse/LANG-393
+    public void testBigDecimal() {
+        BigDecimal o1 = new BigDecimal("2.0");
+        BigDecimal o2 = new BigDecimal("2.00");
+        assertTrue(new EqualsBuilder().append(o1, o1).isEquals());
+        assertTrue(new EqualsBuilder().append(o1, o2).isEquals());
     }
 
     public void testAccessors() {



Mime
View raw message