Skip to content

Commit

Permalink
Improved: Inline ‘UtilValidate#areEqual’
Browse files Browse the repository at this point in the history
(OFBIZ-11172)

‘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
  • Loading branch information
mthl committed Aug 24, 2019
1 parent a3d74cb commit 1b34cf7
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -822,4 +823,4 @@ def getAssociatedProductsList() {
Map result = success()
result.products = products
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1065,7 +1066,7 @@ public boolean matchesFields(Map<String, ? extends Object> keyValuePairs) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1b34cf7

Please sign in to comment.