Skip to content
Permalink
Browse files

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
  • Loading branch information
mthl committed Jul 19, 2019
1 parent 6a99c09 commit cc85af164217365755460db8dff1faa765aebae4
@@ -112,18 +112,6 @@ public static Object getObjectException(byte[] bytes) throws ClassNotFoundExcept
}
}

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
@@ -21,14 +21,14 @@
import java.io.Serializable;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import javax.el.PropertyNotFoundException;

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 boolean equals(Object obj) {
}
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 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 @@ protected boolean isValid(Map.Entry<K, V> src) {
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
@@ -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 boolean equals(Object o) {
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
@@ -22,10 +22,9 @@
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 GenericMapValues(M source) {
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 int hashCode() {
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;
}
@@ -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 boolean equals(Object o) {
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 void testGetByteCount() throws Exception {
}
}

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;
@@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.apache.ofbiz.base.util.UtilMisc;
@@ -64,7 +65,7 @@ public int hashCode() {
public boolean equals(Object o) {
if (o instanceof Removal<?>) {
Removal<?> other = (Removal<?>) o;
return UtilObject.equalsHelper(oldValue, other.oldValue);
return Objects.equals(oldValue, other.oldValue);
}
return false;
}
@@ -86,7 +87,7 @@ public int hashCode() {
public boolean equals(Object o) {
if (o instanceof Addition<?>) {
Addition<?> other = (Addition<?>) o;
return UtilObject.equalsHelper(newValue, other.newValue);
return Objects.equals(newValue, other.newValue);
}
return false;
}
@@ -110,10 +111,10 @@ public int hashCode() {
public boolean equals(Object o) {
if (o instanceof Update<?>) {
Update<?> other = (Update<?>) o;
if (!UtilObject.equalsHelper(newValue, other.newValue)) {
if (!Objects.equals(newValue, other.newValue)) {
return false;
}
return UtilObject.equalsHelper(oldValue, other.oldValue);
return Objects.equals(oldValue, other.oldValue);
}
return false;
}
@@ -28,6 +28,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@@ -47,7 +48,6 @@
import org.apache.ofbiz.base.util.UtilFormatOut;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilObject;
import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.base.util.UtilXml;
@@ -1312,7 +1312,7 @@ public int storeAll(List<GenericValue> values, EntityStoreOptions storeOptions)
if (value.containsKey(fieldName)) {
Object fieldValue = value.get(fieldName);
Object oldValue = existing.get(fieldName);
if (!UtilObject.equalsHelper(oldValue, fieldValue)) {
if (!Objects.equals(oldValue, fieldValue)) {
toStore.put(fieldName, fieldValue);
atLeastOneField = true;
}
@@ -21,14 +21,14 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;

import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilObject;
import org.apache.ofbiz.base.util.UtilURL;
import org.apache.ofbiz.webapp.control.ConfigXMLReader;

@@ -154,7 +154,7 @@ public URL getLocationURL() throws MalformedURLException {
public boolean equals(Object obj) {
if (obj instanceof ControllerRequestArtifactInfo) {
ControllerRequestArtifactInfo that = (ControllerRequestArtifactInfo) obj;
return UtilObject.equalsHelper(this.controllerXmlUrl, that.controllerXmlUrl) && UtilObject.equalsHelper(this.requestUri, that.requestUri);
return Objects.equals(this.controllerXmlUrl, that.controllerXmlUrl) && Objects.equals(this.requestUri, that.requestUri);
} else {
return false;
}
@@ -20,11 +20,11 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
import java.util.Set;

import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilObject;
import org.apache.ofbiz.base.util.UtilURL;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.webapp.control.ConfigXMLReader;
@@ -112,8 +112,8 @@ public URL getLocationURL() throws MalformedURLException {
public boolean equals(Object obj) {
if (obj instanceof ControllerViewArtifactInfo) {
ControllerViewArtifactInfo that = (ControllerViewArtifactInfo) obj;
return UtilObject.equalsHelper(this.controllerXmlUrl, that.controllerXmlUrl) &&
UtilObject.equalsHelper(this.viewUri, that.viewUri);
return Objects.equals(this.controllerXmlUrl, that.controllerXmlUrl) &&
Objects.equals(this.viewUri, that.viewUri);
} else {
return false;
}

0 comments on commit cc85af1

Please sign in to comment.
You can’t perform that action at this time.