Applying my patch from LANG-393; EqualsBuilder uses compareTo for BigDecimal and not equals

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@611543 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2008-01-13 07:00:22 +00:00
parent 97f1c120c0
commit e199d381f8
2 changed files with 15 additions and 2 deletions

View File

@ -377,8 +377,12 @@ public class EqualsBuilder {
}
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);

View File

@ -16,6 +16,7 @@
*/
package org.apache.commons.lang.builder;
import java.math.BigDecimal;
import java.util.Arrays;
import junit.framework.Test;
@ -376,6 +377,14 @@ public class EqualsBuilderTest extends TestCase {
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() {
EqualsBuilder equalsBuilder = new EqualsBuilder();
assertTrue(equalsBuilder.isEquals());