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:
parent
97f1c120c0
commit
e199d381f8
|
@ -377,8 +377,12 @@ public class EqualsBuilder {
|
||||||
}
|
}
|
||||||
Class lhsClass = lhs.getClass();
|
Class lhsClass = lhs.getClass();
|
||||||
if (!lhsClass.isArray()) {
|
if (!lhsClass.isArray()) {
|
||||||
// The simple case, not an array, just test the element
|
if (lhs instanceof java.math.BigDecimal) {
|
||||||
isEquals = lhs.equals(rhs);
|
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()) {
|
} else if (lhs.getClass() != rhs.getClass()) {
|
||||||
// Here when we compare different dimensions, for example: a boolean[][] to a boolean[]
|
// Here when we compare different dimensions, for example: a boolean[][] to a boolean[]
|
||||||
this.setEquals(false);
|
this.setEquals(false);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang.builder;
|
package org.apache.commons.lang.builder;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
@ -376,6 +377,14 @@ public class EqualsBuilderTest extends TestCase {
|
||||||
assertTrue(new EqualsBuilder().append(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).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() {
|
public void testAccessors() {
|
||||||
EqualsBuilder equalsBuilder = new EqualsBuilder();
|
EqualsBuilder equalsBuilder = new EqualsBuilder();
|
||||||
assertTrue(equalsBuilder.isEquals());
|
assertTrue(equalsBuilder.isEquals());
|
||||||
|
|
Loading…
Reference in New Issue