Author: mthl
Date: Sat Aug 24 12:52:12 2019
New Revision: 1865843
URL: http://svn.apache.org/viewvc?rev=1865843&view=rev
Log:
Improved: Inline ‘UtilValidate#areEqual’
(OFBIZ-11172)
‘Objects#equals’ is already providing the same functionality of ‘null’
safe equality check.
Modified:
ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java
Modified:
ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy
(original)
+++
ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/product/category/CategoryServices.groovy
Sat Aug 24 12:52:12 2019
@@ -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
+}
Modified:
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
Sat Aug 24 12:52:12 2019
@@ -154,13 +154,6 @@ public final class 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);
Modified:
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
Sat Aug 24 12:52:12 2019
@@ -35,6 +35,7 @@ import java.util.List;
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 class GenericEntity implements Ma
return true;
}
for (Map.Entry<String, ? extends Object> 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;
}
}
Modified:
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaAction.java
Sat Aug 24 12:52:12 2019
@@ -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 final class EntityEcaAction imple
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;
Modified:
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java
Sat Aug 24 12:52:12 2019
@@ -22,6 +22,7 @@ import java.util.ArrayList;
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 final class EntityEcaCondition im
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;
Modified:
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaRule.java
Sat Aug 24 12:52:12 2019
@@ -23,6 +23,7 @@ import java.util.Collections;
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 final class EntityEcaRule impleme
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)) {
Modified:
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaAction.java
Sat Aug 24 12:52:12 2019
@@ -22,6 +22,7 @@ import java.util.HashMap;
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 class ServiceEcaAction implements
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;
Modified:
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java
Sat Aug 24 12:52:12 2019
@@ -21,6 +21,7 @@ package org.apache.ofbiz.service.eca;
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 class ServiceEcaCondition impleme
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;
Modified:
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaRule.java
Sat Aug 24 12:52:12 2019
@@ -22,11 +22,11 @@ import java.util.ArrayList;
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 final class ServiceEcaRule implem
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)) {
Modified:
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java?rev=1865843&r1=1865842&r2=1865843&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaSetField.java
Sat Aug 24 12:52:12 2019
@@ -22,6 +22,7 @@ package org.apache.ofbiz.service.eca;
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 class ServiceEcaSetField {
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 {