From 1b34cf7982a671fc9432ebe021f8735c1e39d8b1 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Sat, 24 Aug 2019 12:52:12 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Inline=20=E2=80=98UtilValidate#areE?= =?UTF-8?q?qual=E2=80=99=20(OFBIZ-11172)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ‘Objects#equals’ is already providing the same functionality of ‘null’ safe equality check. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1865843 13f79535-47bb-0310-9956-ffa450edef68 --- .../product/category/CategoryServices.groovy | 5 +++-- .../apache/ofbiz/base/util/UtilValidate.java | 7 ------- .../org/apache/ofbiz/entity/GenericEntity.java | 3 ++- .../ofbiz/entityext/eca/EntityEcaAction.java | 9 +++++---- .../ofbiz/entityext/eca/EntityEcaCondition.java | 13 +++++++------ .../ofbiz/entityext/eca/EntityEcaRule.java | 7 ++++--- .../ofbiz/service/eca/ServiceEcaAction.java | 11 ++++++----- .../ofbiz/service/eca/ServiceEcaCondition.java | 17 +++++++++-------- .../ofbiz/service/eca/ServiceEcaRule.java | 6 +++--- .../ofbiz/service/eca/ServiceEcaSetField.java | 9 +++++---- 10 files changed, 44 insertions(+), 43 deletions(-) diff --git a/applications/product/groovyScripts/product/category/CategoryServices.groovy b/applications/product/groovyScripts/product/category/CategoryServices.groovy index 81987465da5..76fdfb14f31 100644 --- a/applications/product/groovyScripts/product/category/CategoryServices.groovy +++ b/applications/product/groovyScripts/product/category/CategoryServices.groovy @@ -21,6 +21,7 @@ import org.apache.ofbiz.entity.util.EntityUtilProperties import java.sql.Timestamp +import java.util.Objects import org.apache.ofbiz.base.util.UtilDateTime import org.apache.ofbiz.base.util.UtilProperties @@ -135,7 +136,7 @@ def addProductToCategories() { def removeProductFromCategory() { // If the associated category was the primary category for the product, clear that field GenericValue product = from("Product").where(parameters).queryOne() - if (UtilValidate.areEqual(product?.primaryProductCategoryId, parameters.productCategoryId)) { + if (Objects.equals(product?.primaryProductCategoryId, parameters.productCategoryId)) { product.primaryProductCategoryId = null product.store() } @@ -822,4 +823,4 @@ def getAssociatedProductsList() { Map result = success() result.products = products return result -} \ No newline at end of file +} diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java index f7f5659dc7b..77a173b91bd 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java @@ -154,13 +154,6 @@ private UtilValidate() {} /** Valid contiguous U.S. postal codes */ public static final String ContiguousUSStateCodes = "AL|AZ|AR|CA|CO|CT|DE|DC|FL|GA|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|VA|WA|WV|WI|WY"; - public static boolean areEqual(Object obj, Object obj2) { - if (obj == null) { - return obj2 == null; - } - return obj.equals(obj2); - } - /** Check whether an object is empty, will see if it is a String, Map, Collection, etc. */ public static boolean isEmpty(Object o) { return ObjectType.isEmpty(o); diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java index 6917d7c469f..bb2cf60248b 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java @@ -35,6 +35,7 @@ import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; +import java.util.Objects; import java.util.ResourceBundle; import java.util.TreeSet; @@ -1065,7 +1066,7 @@ public boolean matchesFields(Map keyValuePairs) { return true; } for (Map.Entry anEntry: keyValuePairs.entrySet()) { - if (!UtilValidate.areEqual(anEntry.getValue(), this.fields.get(anEntry.getKey()))) { + if (!Objects.equals(anEntry.getValue(), this.fields.get(anEntry.getKey()))) { return false; } } diff --git a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java index 00653efa225..733f2e44c09 100644 --- a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java +++ b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java @@ -19,6 +19,7 @@ package org.apache.ofbiz.entityext.eca; import java.util.Map; +import java.util.Objects; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilMisc; @@ -150,10 +151,10 @@ public int hashCode() { public boolean equals(Object obj) { if (obj instanceof EntityEcaAction) { EntityEcaAction other = (EntityEcaAction) obj; - if (!UtilValidate.areEqual(this.serviceName, other.serviceName)) return false; - if (!UtilValidate.areEqual(this.serviceMode, other.serviceMode)) return false; - if (!UtilValidate.areEqual(this.runAsUser, other.runAsUser)) return false; - if (!UtilValidate.areEqual(this.valueAttr, other.valueAttr)) return false; + if (!Objects.equals(this.serviceName, other.serviceName)) return false; + if (!Objects.equals(this.serviceMode, other.serviceMode)) return false; + if (!Objects.equals(this.runAsUser, other.runAsUser)) return false; + if (!Objects.equals(this.valueAttr, other.valueAttr)) return false; if (this.resultToValue != other.resultToValue) return false; if (this.abortOnError != other.abortOnError) return false; if (this.rollbackOnError != other.rollbackOnError) return false; diff --git a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java index 9e40416fe01..edd77a6c8b1 100644 --- a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java +++ b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.ObjectType; @@ -166,12 +167,12 @@ public boolean equals(Object obj) { if (obj instanceof EntityEcaCondition) { EntityEcaCondition other = (EntityEcaCondition) obj; - if (!UtilValidate.areEqual(this.conditionService, other.conditionService)) return false; - if (!UtilValidate.areEqual(this.lhsValueName, other.lhsValueName)) return false; - if (!UtilValidate.areEqual(this.rhsValueName, other.rhsValueName)) return false; - if (!UtilValidate.areEqual(this.operator, other.operator)) return false; - if (!UtilValidate.areEqual(this.compareType, other.compareType)) return false; - if (!UtilValidate.areEqual(this.format, other.format)) return false; + if (!Objects.equals(this.conditionService, other.conditionService)) return false; + if (!Objects.equals(this.lhsValueName, other.lhsValueName)) return false; + if (!Objects.equals(this.rhsValueName, other.rhsValueName)) return false; + if (!Objects.equals(this.operator, other.operator)) return false; + if (!Objects.equals(this.compareType, other.compareType)) return false; + if (!Objects.equals(this.format, other.format)) return false; if (this.constant != other.constant) return false; if (this.isService != other.isService) return false; diff --git a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java index f20025f7938..6b18068db1a 100644 --- a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java +++ b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.apache.ofbiz.base.util.Debug; @@ -210,13 +211,13 @@ public int hashCode() { public boolean equals(Object obj) { if (obj instanceof EntityEcaRule) { EntityEcaRule other = (EntityEcaRule) obj; - if (!UtilValidate.areEqual(this.entityName, other.entityName)) { + if (!Objects.equals(this.entityName, other.entityName)) { return false; } - if (!UtilValidate.areEqual(this.operationName, other.operationName)) { + if (!Objects.equals(this.operationName, other.operationName)) { return false; } - if (!UtilValidate.areEqual(this.eventName, other.eventName)) { + if (!Objects.equals(this.eventName, other.eventName)) { return false; } if (!this.conditions.equals(other.conditions)) { diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java index d9495aedd77..ce889ce3e5a 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilGenerics; @@ -272,11 +273,11 @@ public boolean equals(Object obj) { if (obj instanceof ServiceEcaAction) { ServiceEcaAction other = (ServiceEcaAction) obj; - if (!UtilValidate.areEqual(this.eventName, other.eventName)) return false; - if (!UtilValidate.areEqual(this.serviceName, other.serviceName)) return false; - if (!UtilValidate.areEqual(this.serviceMode, other.serviceMode)) return false; - if (!UtilValidate.areEqual(this.resultMapName, other.resultMapName)) return false; - if (!UtilValidate.areEqual(this.runAsUser, other.runAsUser)) return false; + if (!Objects.equals(this.eventName, other.eventName)) return false; + if (!Objects.equals(this.serviceName, other.serviceName)) return false; + if (!Objects.equals(this.serviceMode, other.serviceMode)) return false; + if (!Objects.equals(this.resultMapName, other.resultMapName)) return false; + if (!Objects.equals(this.runAsUser, other.runAsUser)) return false; if (this.newTransaction != other.newTransaction) return false; if (this.resultToContext != other.resultToContext) return false; diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java index 654062a967e..b0434c1b0e9 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java @@ -21,6 +21,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.ObjectType; @@ -228,14 +229,14 @@ public boolean equals(Object obj) { if (obj instanceof ServiceEcaCondition) { ServiceEcaCondition other = (ServiceEcaCondition) obj; - if (!UtilValidate.areEqual(this.conditionService, other.conditionService)) return false; - if (!UtilValidate.areEqual(this.lhsValueName, other.lhsValueName)) return false; - if (!UtilValidate.areEqual(this.rhsValueName, other.rhsValueName)) return false; - if (!UtilValidate.areEqual(this.lhsMapName, other.lhsMapName)) return false; - if (!UtilValidate.areEqual(this.rhsMapName, other.rhsMapName)) return false; - if (!UtilValidate.areEqual(this.operator, other.operator)) return false; - if (!UtilValidate.areEqual(this.compareType, other.compareType)) return false; - if (!UtilValidate.areEqual(this.format, other.format)) return false; + if (!Objects.equals(this.conditionService, other.conditionService)) return false; + if (!Objects.equals(this.lhsValueName, other.lhsValueName)) return false; + if (!Objects.equals(this.rhsValueName, other.rhsValueName)) return false; + if (!Objects.equals(this.lhsMapName, other.lhsMapName)) return false; + if (!Objects.equals(this.rhsMapName, other.rhsMapName)) return false; + if (!Objects.equals(this.operator, other.operator)) return false; + if (!Objects.equals(this.compareType, other.compareType)) return false; + if (!Objects.equals(this.format, other.format)) return false; if (this.isConstant != other.isConstant) return false; if (this.isService != other.isService) return false; diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java index 18134bdee02..58533680938 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java @@ -22,11 +22,11 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilMisc; -import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.base.util.UtilXml; import org.apache.ofbiz.service.DispatchContext; import org.apache.ofbiz.service.GenericServiceException; @@ -196,10 +196,10 @@ public int hashCode() { public boolean equals(Object obj) { if (obj instanceof ServiceEcaRule) { ServiceEcaRule other = (ServiceEcaRule) obj; - if (!UtilValidate.areEqual(this.serviceName, other.serviceName)) { + if (!Objects.equals(this.serviceName, other.serviceName)) { return false; } - if (!UtilValidate.areEqual(this.eventName, other.eventName)) { + if (!Objects.equals(this.eventName, other.eventName)) { return false; } if (!this.conditions.equals(other.conditions)) { diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java index b35fd8f7a6c..b3610e39530 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Objects; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilGenerics; @@ -157,10 +158,10 @@ public boolean equals(Object obj) { if (obj instanceof ServiceEcaSetField) { ServiceEcaSetField other = (ServiceEcaSetField) obj; - if (!UtilValidate.areEqual(this.fieldName, other.fieldName)) return false; - if (!UtilValidate.areEqual(this.envName, other.envName)) return false; - if (!UtilValidate.areEqual(this.value, other.value)) return false; - if (!UtilValidate.areEqual(this.format, other.format)) return false; + if (!Objects.equals(this.fieldName, other.fieldName)) return false; + if (!Objects.equals(this.envName, other.envName)) return false; + if (!Objects.equals(this.value, other.value)) return false; + if (!Objects.equals(this.format, other.format)) return false; return true; } else {