Skip to content

Commit 38f1346

Browse files
committed
Reuse Objects.equals() in org.apache.commons.collections4.list
1 parent c147999 commit 38f1346

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<action type="fix" dev="ggregory" due-to="Gary Gregory" issue="COLLECTIONS-815">Javadoc: Update ClosureUtils Javadoc to match runtime.</action>
4646
<action type="fix" dev="ggregory" due-to="Gary Gregory" issue="COLLECTIONS-777">Migrate to JUnit 5.</action>
4747
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix NullPointerException in FilterIterator.setNextObject().</action>
48+
<action type="fix" dev="ggregory" due-to="Gary Gregory">EqualPredicate.test(Object) should return true if the parameter is the same object as given the constructor.</action>
4849
<!-- ADD -->
4950
<action type="add" dev="ggregory" due-to="Gary Gregory">LayerManager.Builder implements Supplier.</action>
5051
<action type="add" dev="ggregory" due-to="Gary Gregory, hemanth0525">Add CollectionUtils.duplicateList(Collection).</action>

src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public boolean remove(final Object obj) {
181181
final Object key = entry.getKey();
182182
if (parent.containsKey(key)) {
183183
final V value = parent.normalMap.get(key);
184-
if (value == null ? entry.getValue() == null : value.equals(entry.getValue())) {
184+
if (Objects.equals(value, entry.getValue())) {
185185
parent.normalMap.remove(key);
186186
parent.reverseMap.remove(value);
187187
return true;

src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public boolean contains(final Object obj) {
231231
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
232232
final Object value = entry.getValue();
233233
final Node<K, V> node = lookupKey(entry.getKey());
234-
return node != null && node.getValue().equals(value);
234+
return node != null && Objects.equals(node.getValue(), value);
235235
}
236236

237237
@Override
@@ -247,7 +247,7 @@ public boolean remove(final Object obj) {
247247
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
248248
final Object value = entry.getValue();
249249
final Node<K, V> node = lookupKey(entry.getKey());
250-
if (node != null && node.getValue().equals(value)) {
250+
if (node != null && Objects.equals(node.getValue(), value)) {
251251
doRedBlackDelete(node);
252252
return true;
253253
}
@@ -424,7 +424,7 @@ public boolean contains(final Object obj) {
424424
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
425425
final Object value = entry.getValue();
426426
final Node<K, V> node = lookupValue(entry.getKey());
427-
return node != null && node.getKey().equals(value);
427+
return node != null && Objects.equals(node.getKey(), value);
428428
}
429429

430430
@Override
@@ -440,7 +440,7 @@ public boolean remove(final Object obj) {
440440
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;
441441
final Object value = entry.getValue();
442442
final Node<K, V> node = lookupValue(entry.getKey());
443-
if (node != null && node.getKey().equals(value)) {
443+
if (node != null && Objects.equals(node.getKey(), value)) {
444444
doRedBlackDelete(node);
445445
return true;
446446
}
@@ -605,7 +605,7 @@ public boolean equals(final Object obj) {
605605
return false;
606606
}
607607
final Map.Entry<?, ?> e = (Map.Entry<?, ?>) obj;
608-
return getKey().equals(e.getKey()) && getValue().equals(e.getValue());
608+
return Objects.equals(getKey(), e.getKey()) && Objects.equals(getValue(), e.getValue());
609609
}
610610

611611
private Object getData(final DataElement dataElement) {

src/main/java/org/apache/commons/collections4/functors/ConstantTransformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.commons.collections4.functors;
1818

1919
import java.io.Serializable;
20+
import java.util.Objects;
2021

2122
import org.apache.commons.collections4.Transformer;
2223

@@ -92,7 +93,7 @@ public boolean equals(final Object obj) {
9293
return false;
9394
}
9495
final Object otherConstant = ((ConstantTransformer<?, ?>) obj).getConstant();
95-
return otherConstant == getConstant() || otherConstant != null && otherConstant.equals(getConstant());
96+
return Objects.equals(otherConstant, getConstant());
9697
}
9798

9899
/**

src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.commons.collections4.keyvalue;
1818

1919
import java.util.Map;
20+
import java.util.Objects;
2021

2122
/**
2223
* Abstract Pair class to assist with creating correct
@@ -55,9 +56,8 @@ public boolean equals(final Object obj) {
5556
return false;
5657
}
5758
final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
58-
return
59-
(getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
60-
(getValue() == null ? other.getValue() == null : getValue().equals(other.getValue()));
59+
return Objects.equals(getKey(), other.getKey()) &&
60+
Objects.equals(getValue(), other.getValue());
6161
}
6262

6363
/**

src/main/java/org/apache/commons/collections4/keyvalue/DefaultKeyValue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.commons.collections4.keyvalue;
1818

1919
import java.util.Map;
20+
import java.util.Objects;
2021

2122
import org.apache.commons.collections4.KeyValue;
2223

@@ -91,8 +92,8 @@ public boolean equals(final Object obj) {
9192

9293
final DefaultKeyValue<?, ?> other = (DefaultKeyValue<?, ?>) obj;
9394
return
94-
(getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
95-
(getValue() == null ? other.getValue() == null : getValue().equals(other.getValue()));
95+
Objects.equals(getKey(), other.getKey()) &&
96+
Objects.equals(getValue(), other.getValue());
9697
}
9798

9899
/**

src/main/java/org/apache/commons/collections4/keyvalue/TiedMapEntry.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.Serializable;
2020
import java.util.Map;
21+
import java.util.Objects;
2122

2223
import org.apache.commons.collections4.KeyValue;
2324

@@ -71,10 +72,9 @@ public boolean equals(final Object obj) {
7172
return false;
7273
}
7374
final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
74-
final Object value = getValue();
7575
return
76-
(key == null ? other.getKey() == null : key.equals(other.getKey())) &&
77-
(value == null ? other.getValue() == null : value.equals(other.getValue()));
76+
Objects.equals(key, other.getKey()) &&
77+
Objects.equals(getValue(), other.getValue());
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)