Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public static boolean containsAll(final Collection<?> coll1, final Collection<?>
while (it.hasNext()) {
final Object p = it.next();
elementsAlreadySeen.add(p);
if (nextElement == null ? p == null : nextElement.equals(p)) {
if (Objects.equals(nextElement, p)) {
foundCurrentElement = true;
break;
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/apache/commons/collections4/ListUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,12 @@ public static boolean isEqualList(final Collection<?> list1, final Collection<?>

final Iterator<?> it1 = list1.iterator();
final Iterator<?> it2 = list2.iterator();
Object obj1 = null;
Object obj2 = null;

while (it1.hasNext() && it2.hasNext()) {
obj1 = it1.next();
obj2 = it2.next();
final Object obj1 = it1.next();
final Object obj2 = it2.next();

if (!(obj1 == null ? obj2 == null : obj1.equals(obj2))) {
if (!(Objects.equals(obj1, obj2))) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/**
* A ComparatorChain is a Comparator that wraps one or more Comparators in
Expand Down Expand Up @@ -338,9 +339,8 @@ public boolean equals(final Object object) {
}
if (object.getClass().equals(this.getClass())) {
final ComparatorChain<?> chain = (ComparatorChain<?>) object;
return (null == orderingBits ? null == chain.orderingBits : orderingBits.equals(chain.orderingBits)) &&
(null == comparatorChain ? null == chain.comparatorChain :
comparatorChain.equals(chain.comparatorChain));
return (Objects.equals(orderingBits, chain.orderingBits)) &&
(Objects.equals(comparatorChain, chain.comparatorChain));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.Serializable;
import java.util.Comparator;
import java.util.Objects;

import org.apache.commons.collections4.ComparatorUtils;
import org.apache.commons.collections4.Transformer;
Expand Down Expand Up @@ -120,8 +121,8 @@ public boolean equals(final Object object) {
}
if (object.getClass().equals(this.getClass())) {
final TransformingComparator<?, ?> comp = (TransformingComparator<?, ?>) object;
return (null == decorated ? null == comp.decorated : decorated.equals(comp.decorated)) &&
(null == transformer ? null == comp.transformer : transformer.equals(comp.transformer));
return (Objects.equals(decorated, comp.decorated)) &&
(Objects.equals(transformer, comp.transformer));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.commons.collections4.functors;

import java.io.Serializable;
import java.util.Objects;

import org.apache.commons.collections4.Equator;

Expand Down Expand Up @@ -57,11 +58,11 @@ private DefaultEquator() {
}

/**
* {@inheritDoc} Delegates to {@link Object#equals(Object)}.
* {@inheritDoc} Delegates to {@link Objects#equals(Object, Object)}.
*/
@Override
public boolean equate(final T o1, final T o2) {
return o1 == o2 || o1 != null && o1.equals(o2);
return Objects.equals(o1, o2);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;

import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -1187,23 +1188,23 @@ public boolean equals(final Object obj) {
return false;
}
otherValue = other.get(key3);
if (value3 == null ? otherValue != null : !value3.equals(otherValue)) {
if (!Objects.equals(value3, otherValue)) {
return false;
}
case 2:
if (!other.containsKey(key2)) {
return false;
}
otherValue = other.get(key2);
if (value2 == null ? otherValue != null : !value2.equals(otherValue)) {
if (!Objects.equals(value2, otherValue)) {
return false;
}
case 1:
if (!other.containsKey(key1)) {
return false;
}
otherValue = other.get(key1);
if (value1 == null ? otherValue != null : !value1.equals(otherValue)) {
if (!Objects.equals(value1, otherValue)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public V get(final Object key) {
Node<K, V> n = buckets[hash];

while (n != null) {
if (n.key == key || (n.key != null && n.key.equals(key))) {
if (Objects.equals(n.key, key)) {
return n.value;
}

Expand All @@ -232,7 +232,7 @@ public boolean containsKey(final Object key) {
Node<K, V> n = buckets[hash];

while (n != null) {
if (n.key == key || (n.key != null && n.key.equals(key))) {
if (Objects.equals(n.key, key)) {
return true;
}

Expand All @@ -255,7 +255,7 @@ public boolean containsValue(final Object value) {
Node<K, V> n = buckets[i];

while (n != null) {
if (n.value == value || (n.value != null && n.value.equals(value))) {
if (Objects.equals(n.value, value)) {
return true;
}

Expand Down Expand Up @@ -295,7 +295,7 @@ public V put(final K key, final V value) {
for (Node<K, V> next = n; next != null; next = next.next) {
n = next;

if (n.key == key || (n.key != null && n.key.equals(key))) {
if (Objects.equals(n.key, key)) {
final V returnVal = n.value;
n.value = value;
return returnVal;
Expand Down Expand Up @@ -328,7 +328,7 @@ public V remove(final Object key) {
Node<K, V> prev = null;

while (n != null) {
if (n.key == key || (n.key != null && n.key.equals(key))) {
if (Objects.equals(n.key, key)) {
// Remove this node from the linked list of nodes.
if (null == prev) {
// This node was the head, set the next node to be the new head.
Expand Down Expand Up @@ -647,7 +647,7 @@ public boolean remove(final Object obj) {
synchronized (locks[hash]) {
for (Node<K, V> n = buckets[hash]; n != null; n = n.next) {
final Object k = n.getKey();
if ((k == obj) || ((k != null) && k.equals(obj))) {
if (Objects.equals(k, obj)) {
StaticBucketMap.this.remove(k);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;

import org.apache.commons.collections4.IteratorUtils;
Expand Down Expand Up @@ -74,8 +75,7 @@ public int size() {
public int getCount(final Object object) {
for (final Entry<E> entry : entrySet()) {
final E element = entry.getElement();
if (element == object ||
element != null && element.equals(object)) {
if (Objects.equals(element, object)) {
return entry.getCount();
}
}
Expand Down Expand Up @@ -405,8 +405,7 @@ public boolean equals(final Object object) {
final Object otherElement = other.getElement();

return this.getCount() == other.getCount() &&
(element == otherElement ||
element != null && element.equals(otherElement));
(Objects.equals(element, otherElement));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ final boolean compareKeys(final K key, final K other) {
}

/**
* Returns true if both values are either null or equal.
* Delegates to {@link Objects#equals(Object, Object)}.
*/
static boolean compare(final Object a, final Object b) {
return a == null ? b == null : a.equals(b);
return Objects.equals(a, b);
}

/**
Expand Down