Improved: Remove useless ‘UtilObject#equalsHelper’
(OFBIZ-11140) git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863443 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -112,18 +112,6 @@ public final class UtilObject {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean equalsHelper(Object o1, Object o2) {
|
||||
if (o1 == o2) {
|
||||
// handles same-reference, or null
|
||||
return true;
|
||||
} else if (o1 == null || o2 == null) {
|
||||
// either o1 or o2 is null, but not both
|
||||
return false;
|
||||
} else {
|
||||
return o1.equals(o2);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> int compareToHelper(Comparable<T> o1, T o2) {
|
||||
if (o1 == o2) {
|
||||
// handles same-reference, or null
|
||||
|
||||
+2
-2
@@ -21,6 +21,7 @@ package org.apache.ofbiz.base.util.collections;
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.el.PropertyNotFoundException;
|
||||
|
||||
@@ -28,7 +29,6 @@ import org.apache.ofbiz.base.lang.IsEmpty;
|
||||
import org.apache.ofbiz.base.lang.SourceMonitored;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.UtilGenerics;
|
||||
import org.apache.ofbiz.base.util.UtilObject;
|
||||
import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.base.util.cache.UtilCache;
|
||||
import org.apache.ofbiz.base.util.string.FlexibleStringExpander;
|
||||
@@ -224,7 +224,7 @@ public final class FlexibleMapAccessor<T> implements Serializable, IsEmpty {
|
||||
}
|
||||
if (obj instanceof FlexibleMapAccessor) {
|
||||
FlexibleMapAccessor<?> that = (FlexibleMapAccessor<?>) obj;
|
||||
return UtilObject.equalsHelper(this.original, that.original);
|
||||
return Objects.equals(this.original, that.original);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
||||
|
||||
import org.apache.ofbiz.base.lang.Appender;
|
||||
import org.apache.ofbiz.base.util.UtilGenerics;
|
||||
import org.apache.ofbiz.base.util.UtilObject;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class GenericMap<K, V> implements Appender<StringBuilder>, Map<K, V>, Serializable {
|
||||
@@ -165,7 +164,7 @@ public abstract class GenericMap<K, V> implements Appender<StringBuilder>, Map<K
|
||||
entrySetUpdater.compareAndSet(this, null, new GenericMapEntrySet<K, V, GenericMap<K, V>>(this) {
|
||||
@Override
|
||||
protected boolean contains(Object key, Object value) {
|
||||
return UtilObject.equalsHelper(get(key, false), value);
|
||||
return Objects.equals(get(key, false), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@
|
||||
package org.apache.ofbiz.base.util.collections;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.ofbiz.base.util.UtilObject;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class GenericMapEntry<K, V> implements Map.Entry<K, V> {
|
||||
return true;
|
||||
}
|
||||
Map.Entry<?, ?> other = (Map.Entry<?, ?>) o;
|
||||
return UtilObject.equalsHelper(getKey(), other.getKey()) && UtilObject.equalsHelper(getValue(), other.getValue());
|
||||
return Objects.equals(getKey(), other.getKey()) && Objects.equals(getValue(), other.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-4
@@ -22,10 +22,9 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.ofbiz.base.util.UtilObject;
|
||||
|
||||
public abstract class GenericMapValues<K, V, M extends Map<K, V>> extends GenericMapCollection<K, V, M, V> {
|
||||
public GenericMapValues(M source) {
|
||||
super(source);
|
||||
@@ -35,7 +34,7 @@ public abstract class GenericMapValues<K, V, M extends Map<K, V>> extends Generi
|
||||
public boolean contains(Object item) {
|
||||
Iterator<V> it = iterator(false);
|
||||
while (it.hasNext()) {
|
||||
if (UtilObject.equalsHelper(item, it.next())) {
|
||||
if (Objects.equals(item, it.next())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -82,7 +81,7 @@ public abstract class GenericMapValues<K, V, M extends Map<K, V>> extends Generi
|
||||
public boolean remove(Object item) {
|
||||
Iterator<V> it = iterator(false);
|
||||
while (it.hasNext()) {
|
||||
if (UtilObject.equalsHelper(item, it.next())) {
|
||||
if (Objects.equals(item, it.next())) {
|
||||
it.remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@
|
||||
package org.apache.ofbiz.base.util.collections;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.ofbiz.base.util.UtilObject;
|
||||
|
||||
@@ -58,7 +59,7 @@ public class ReadOnlyMapEntry<K, V> implements Map.Entry<K, V> {
|
||||
return true;
|
||||
}
|
||||
Map.Entry<?, ?> other = (Map.Entry<?, ?>) o;
|
||||
return UtilObject.equalsHelper(getKey(), other.getKey()) && UtilObject.equalsHelper(getValue(), other.getValue());
|
||||
return Objects.equals(getKey(), other.getKey()) && Objects.equals(getValue(), other.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -260,16 +260,6 @@ public class UtilObjectTests extends GenericTestCaseBase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testEqualsHelper() {
|
||||
assertTrue("a == a", UtilObject.equalsHelper(this, this));
|
||||
assertFalse("null == a", UtilObject.equalsHelper(null, this));
|
||||
assertFalse("a == null", UtilObject.equalsHelper(this, null));
|
||||
assertTrue("null == null", UtilObject.equalsHelper(null, null));
|
||||
assertTrue("map == map", UtilObject.equalsHelper(new HashMap<String, Object>(), new HashMap<String, Object>()));
|
||||
assertFalse("map == this", UtilObject.equalsHelper(new HashMap<String, Object>(), this));
|
||||
assertFalse("this == map", UtilObject.equalsHelper(this, new HashMap<String, Object>()));
|
||||
}
|
||||
|
||||
public void testCompareToHelper() {
|
||||
Long one = 1L;
|
||||
Long two = 2L;
|
||||
|
||||
Reference in New Issue
Block a user