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
This commit is contained in:
@@ -48,7 +48,7 @@ public class ByAndFinder extends ListFinder {
|
||||
@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);
|
||||
|
||||
+19
-22
@@ -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);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class PrimaryKeyFinder extends Finder {
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user