From cc85af164217365755460db8dff1faa765aebae4 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Fri, 19 Jul 2019 22:11:39 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Remove=20useless=20=E2=80=98UtilObj?= =?UTF-8?q?ect#equalsHelper=E2=80=99=20(OFBIZ-11140)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863443 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/ofbiz/base/util/UtilObject.java | 12 ------------ .../base/util/collections/FlexibleMapAccessor.java | 4 ++-- .../ofbiz/base/util/collections/GenericMap.java | 3 +-- .../ofbiz/base/util/collections/GenericMapEntry.java | 3 ++- .../base/util/collections/GenericMapValues.java | 7 +++---- .../base/util/collections/ReadOnlyMapEntry.java | 3 ++- .../apache/ofbiz/base/util/test/UtilObjectTests.java | 10 ---------- .../apache/ofbiz/base/util/cache/UtilCacheTests.java | 9 +++++---- .../org/apache/ofbiz/entity/GenericDelegator.java | 4 ++-- .../artifactinfo/ControllerRequestArtifactInfo.java | 4 ++-- .../artifactinfo/ControllerViewArtifactInfo.java | 6 +++--- 11 files changed, 22 insertions(+), 43 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java index 985d650dbc..a27b3daa4c 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilObject.java @@ -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 int compareToHelper(Comparable o1, T o2) { if (o1 == o2) { // handles same-reference, or null diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleMapAccessor.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleMapAccessor.java index c6acc2f33f..cf7c14716e 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleMapAccessor.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/FlexibleMapAccessor.java @@ -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 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; } diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java index 6363f0b8ca..3b3d276351 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMap.java @@ -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 implements Appender, Map, Serializable { @@ -165,7 +164,7 @@ public abstract class GenericMap implements Appender, Map>(this) { @Override protected boolean contains(Object key, Object value) { - return UtilObject.equalsHelper(get(key, false), value); + return Objects.equals(get(key, false), value); } @Override diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java index a43c75bd2f..9caaed40b8 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapEntry.java @@ -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 implements Map.Entry { 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 diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java index bafa3a5e93..b2a5cc0ca1 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/GenericMapValues.java @@ -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> extends GenericMapCollection { public GenericMapValues(M source) { super(source); @@ -35,7 +34,7 @@ public abstract class GenericMapValues> extends Generi public boolean contains(Object item) { Iterator 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> extends Generi public boolean remove(Object item) { Iterator it = iterator(false); while (it.hasNext()) { - if (UtilObject.equalsHelper(item, it.next())) { + if (Objects.equals(item, it.next())) { it.remove(); return true; } diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java index 1988727056..81ca92be6f 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/collections/ReadOnlyMapEntry.java @@ -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 implements Map.Entry { 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 diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java index b67915ebba..53ac9e59c0 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilObjectTests.java @@ -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(), new HashMap())); - assertFalse("map == this", UtilObject.equalsHelper(new HashMap(), this)); - assertFalse("this == map", UtilObject.equalsHelper(this, new HashMap())); - } - public void testCompareToHelper() { Long one = 1L; Long two = 2L; diff --git a/framework/base/src/test/java/org/apache/ofbiz/base/util/cache/UtilCacheTests.java b/framework/base/src/test/java/org/apache/ofbiz/base/util/cache/UtilCacheTests.java index 2cbf7ee61b..12aa70c2fa 100644 --- a/framework/base/src/test/java/org/apache/ofbiz/base/util/cache/UtilCacheTests.java +++ b/framework/base/src/test/java/org/apache/ofbiz/base/util/cache/UtilCacheTests.java @@ -34,6 +34,7 @@ import java.util.Collections; 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 class UtilCacheTests implements Serializable { 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 class UtilCacheTests implements Serializable { 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 class UtilCacheTests implements Serializable { 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; } diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java index cce07a6bf9..643cfefb38 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java @@ -28,6 +28,7 @@ import java.util.Iterator; 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.UtilDateTime; 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 class GenericDelegator implements Delegator { 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; } diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java index eb2f508c97..4d5ea6c961 100644 --- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java +++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerRequestArtifactInfo.java @@ -21,6 +21,7 @@ package org.apache.ofbiz.webtools.artifactinfo; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; @@ -28,7 +29,6 @@ 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 class ControllerRequestArtifactInfo extends ArtifactInfoBase { 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; } diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java index 7fea79d326..7756fa4a14 100644 --- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java +++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/ControllerViewArtifactInfo.java @@ -20,11 +20,11 @@ package org.apache.ofbiz.webtools.artifactinfo; 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 class ControllerViewArtifactInfo extends ArtifactInfoBase { 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; }