You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/10/28 13:39:25 UTC

svn commit: r1813632 - in /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder: ByAndFinder.java EntityFinderUtil.java PrimaryKeyFinder.java

Author: mbrohl
Date: Sat Oct 28 13:39:24 2017
New Revision: 1813632

URL: http://svn.apache.org/viewvc?rev=1813632&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package 
org.apache.ofbiz.entity.finder.
(OFBIZ-9712)

Thanks Dennis Balkir for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java?rev=1813632&r1=1813631&r2=1813632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ByAndFinder.java Sat Oct 28 13:39:24 2017
@@ -48,7 +48,7 @@ public class ByAndFinder extends ListFin
     @Override
     public EntityCondition getWhereEntityCondition(Map<String, Object> context, ModelEntity modelEntity, ModelFieldTypeReader modelFieldTypeReader) {
         // create the by and map
-        Map<String, Object> entityContext = new HashMap<String, Object>();
+        Map<String, Object> entityContext = new HashMap<>();
         EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, entityContext);
         // then convert the types...
         modelEntity.convertFieldMapInPlace(entityContext, modelFieldTypeReader);

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java?rev=1813632&r1=1813631&r2=1813632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java Sat Oct 28 13:39:24 2017
@@ -65,7 +65,7 @@ public final class EntityFinderUtil {
         Map<FlexibleMapAccessor<Object>, Object> fieldMap = null;
         List<? extends Element> fieldMapElementList = UtilXml.childElementList(element, "field-map");
         if (fieldMapElementList.size() > 0) {
-            fieldMap = new HashMap<FlexibleMapAccessor<Object>, 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<FlexibleStringExpander> selectFieldExpanderList = null;
         List<? extends Element> selectFieldElementList = UtilXml.childElementList(element, "select-field");
         if (selectFieldElementList.size() > 0) {
-            selectFieldExpanderList = new ArrayList<FlexibleStringExpander>(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<String> makeFieldsToSelect(List<FlexibleStringExpander> selectFieldExpanderList, Map<String, Object> context) {
         Set<String> fieldsToSelect = null;
         if (UtilValidate.isNotEmpty(selectFieldExpanderList)) {
-            fieldsToSelect = new HashSet<String>();
+            fieldsToSelect = new HashSet<>();
             for (FlexibleStringExpander selectFieldExpander: selectFieldExpanderList) {
                 fieldsToSelect.add(selectFieldExpander.expandString(context));
             }
@@ -140,7 +140,7 @@ public final class EntityFinderUtil {
     public static List<String> makeOrderByFieldList(List<FlexibleStringExpander> orderByExpanderList, Map<String, Object> context) {
         List<String> orderByFields = null;
         if (UtilValidate.isNotEmpty(orderByExpanderList)) {
-            orderByFields = new ArrayList<String>(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.<EntityComparisonOperator<?,?>>cast(operator), EntityFunction.UPPER(value)),
                             EntityOperator.OR,
                             EntityCondition.makeCondition(fieldName, EntityOperator.EQUALS, null));
-                } else {
-                    return EntityCondition.makeCondition(
-                            EntityCondition.makeCondition(fieldName, UtilGenerics.<EntityComparisonOperator<?,?>>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.<EntityComparisonOperator<?,?>>cast(operator), EntityFunction.UPPER(value));
-                } else {
-                    return EntityCondition.makeCondition(fieldName, UtilGenerics.<EntityComparisonOperator<?,?>>cast(operator), value);
                 }
+                return EntityCondition.makeCondition(
+                        EntityCondition.makeCondition(fieldName, UtilGenerics.<EntityComparisonOperator<?,?>>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.<EntityComparisonOperator<?,?>>cast(operator), EntityFunction.UPPER(value));
             }
+            return EntityCondition.makeCondition(fieldName, UtilGenerics.<EntityComparisonOperator<?,?>>cast(operator), value);
         }
     }
 
@@ -275,7 +272,7 @@ public final class EntityFinderUtil {
             if (subElements.isEmpty()) {
                 this.conditionList = null;
             } else {
-                List<Condition> conditionList = new ArrayList<Condition>(subElements.size());
+                List<Condition> 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<EntityCondition> entityConditionList = new ArrayList<EntityCondition>(this.conditionList.size());
+            List<EntityCondition> 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<GenericValue>();
+                result = new LinkedList<>();
             }
             listAcsr.put(context, result);
         }
@@ -451,7 +448,7 @@ public final class EntityFinderUtil {
                 }
                 result = results.subList(begin, end);
             } else {
-                result = new LinkedList<GenericValue>();
+                result = new LinkedList<>();
             }
             listAcsr.put(context, result);
         }

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java?rev=1813632&r1=1813631&r2=1813632&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/PrimaryKeyFinder.java Sat Oct 28 13:39:24 2017
@@ -101,7 +101,7 @@ public class PrimaryKeyFinder extends Fi
             Map<FlexibleMapAccessor<Object>, Object> fieldMap, List<FlexibleStringExpander> selectFieldExpanderList) throws GeneralException {
 
         // assemble the field map
-        Map<String, Object> entityContext = new HashMap<String, Object>();
+        Map<String, Object> 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");