From e687edb25fcd92cd9bad439d4d5bd7173782bc6f Mon Sep 17 00:00:00 2001 From: Michael Brohl Date: Sat, 28 Oct 2017 13:39:24 +0000 Subject: [PATCH] Improved: Fixing defects reported by FindBugs, package org.apache.ofbiz.entity.finder. (OFBIZ-9712) Thanks Dennis Balkir for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1813632 13f79535-47bb-0310-9956-ffa450edef68 --- .../ofbiz/entity/finder/ByAndFinder.java | 2 +- .../ofbiz/entity/finder/EntityFinderUtil.java | 41 +++++++++---------- .../ofbiz/entity/finder/PrimaryKeyFinder.java | 2 +- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java index 0a7e5b9933..2bf9040b50 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java @@ -48,7 +48,7 @@ public class ByAndFinder extends ListFinder { @Override public EntityCondition getWhereEntityCondition(Map context, ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader) { // create the by and map - Map entityContext = new HashMap(); + Map entityContext = new HashMap<>(); EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, entityContext); // then convert the types... modelEntity.convertFieldMapInPlace(entityContext, modelFieldTypeReader); diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java index 8865adea2c..0086dffe53 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java @@ -65,7 +65,7 @@ public final class EntityFinderUtil { Map, Object> fieldMap = null; List fieldMapElementList = UtilXml.childElementList(element, "field-map"); if (fieldMapElementList.size() > 0) { - fieldMap = new HashMap, Object>(fieldMapElementList.size()); + fieldMap = new HashMap<>(fieldMapElementList.size()); for (Element fieldMapElement: fieldMapElementList) { // set the env-name for each field-name, noting that if no field-name is specified it defaults to the env-name String fieldName = fieldMapElement.getAttribute("field-name"); @@ -118,7 +118,7 @@ public final class EntityFinderUtil { List selectFieldExpanderList = null; List selectFieldElementList = UtilXml.childElementList(element, "select-field"); if (selectFieldElementList.size() > 0) { - selectFieldExpanderList = new ArrayList(selectFieldElementList.size()); + selectFieldExpanderList = new ArrayList<>(selectFieldElementList.size()); for (Element selectFieldElement: selectFieldElementList) { selectFieldExpanderList.add(FlexibleStringExpander.getInstance(selectFieldElement.getAttribute("field-name"))); } @@ -129,7 +129,7 @@ public final class EntityFinderUtil { public static Set makeFieldsToSelect(List selectFieldExpanderList, Map context) { Set fieldsToSelect = null; if (UtilValidate.isNotEmpty(selectFieldExpanderList)) { - fieldsToSelect = new HashSet(); + fieldsToSelect = new HashSet<>(); for (FlexibleStringExpander selectFieldExpander: selectFieldExpanderList) { fieldsToSelect.add(selectFieldExpander.expandString(context)); } @@ -140,7 +140,7 @@ public final class EntityFinderUtil { public static List makeOrderByFieldList(List orderByExpanderList, Map context) { List orderByFields = null; if (UtilValidate.isNotEmpty(orderByExpanderList)) { - orderByFields = new ArrayList(orderByExpanderList.size()); + orderByFields = new ArrayList<>(orderByExpanderList.size()); for (FlexibleStringExpander orderByExpander: orderByExpanderList) { orderByFields.add(orderByExpander.expandString(context)); } @@ -209,9 +209,9 @@ public final class EntityFinderUtil { if ((operator.equals(EntityOperator.IN) || operator.equals(EntityOperator.BETWEEN) || operator.equals(EntityOperator.NOT_IN)) && value instanceof String) { String delim = null; - if (((String)value).indexOf("|") >= 0) { + if (((String)value).indexOf('|') >= 0) { delim = "|"; - } else if (((String)value).indexOf(",") >= 0) { + } else if (((String)value).indexOf(',') >= 0) { delim = ","; } if (delim != null) { @@ -240,20 +240,17 @@ public final class EntityFinderUtil { EntityCondition.makeCondition(EntityFunction.UPPER_FIELD(fieldName), UtilGenerics.>cast(operator), EntityFunction.UPPER(value)), EntityOperator.OR, EntityCondition.makeCondition(fieldName, EntityOperator.EQUALS, null)); - } else { - return EntityCondition.makeCondition( - EntityCondition.makeCondition(fieldName, UtilGenerics.>cast(operator), value), - EntityOperator.OR, - EntityCondition.makeCondition(fieldName, EntityOperator.EQUALS, null)); - } - } else { - if (ignoreCase) { - // use the stuff to upper case both sides - return EntityCondition.makeCondition(EntityFunction.UPPER_FIELD(fieldName), UtilGenerics.>cast(operator), EntityFunction.UPPER(value)); - } else { - return EntityCondition.makeCondition(fieldName, UtilGenerics.>cast(operator), value); } + return EntityCondition.makeCondition( + EntityCondition.makeCondition(fieldName, UtilGenerics.>cast(operator), value), + EntityOperator.OR, + EntityCondition.makeCondition(fieldName, EntityOperator.EQUALS, null)); } + if (ignoreCase) { + // use the stuff to upper case both sides + return EntityCondition.makeCondition(EntityFunction.UPPER_FIELD(fieldName), UtilGenerics.>cast(operator), EntityFunction.UPPER(value)); + } + return EntityCondition.makeCondition(fieldName, UtilGenerics.>cast(operator), value); } } @@ -275,7 +272,7 @@ public final class EntityFinderUtil { if (subElements.isEmpty()) { this.conditionList = null; } else { - List conditionList = new ArrayList(subElements.size()); + List conditionList = new ArrayList<>(subElements.size()); for (Element subElement : subElements) { if ("condition-expr".equals(subElement.getNodeName())) { conditionList.add(new ConditionExpr(subElement)); @@ -299,7 +296,7 @@ public final class EntityFinderUtil { Condition condition = this.conditionList.get(0); return condition.createCondition(context, modelEntity, modelFieldTypeReader); } - List entityConditionList = new ArrayList(this.conditionList.size()); + List entityConditionList = new ArrayList<>(this.conditionList.size()); for (Condition curCondition: this.conditionList) { EntityCondition econd = curCondition.createCondition(context, modelEntity, modelFieldTypeReader); if (econd != null) { @@ -388,7 +385,7 @@ public final class EntityFinderUtil { } result = results.subList(start, end); } else { - result = new LinkedList(); + result = new LinkedList<>(); } listAcsr.put(context, result); } @@ -451,7 +448,7 @@ public final class EntityFinderUtil { } result = results.subList(begin, end); } else { - result = new LinkedList(); + result = new LinkedList<>(); } listAcsr.put(context, result); } diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java index 8bd3505656..b2ecdd83a7 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java @@ -101,7 +101,7 @@ public class PrimaryKeyFinder extends Finder { Map, Object> fieldMap, List selectFieldExpanderList) throws GeneralException { // assemble the field map - Map entityContext = new HashMap(); + Map entityContext = new HashMap<>(); if (autoFieldMap) { // try a map called "parameters", try it first so values from here are overridden by values in the main context Object parametersObj = context.get("parameters");