Skip to content
Permalink
Browse files

Improved: Inline ‘UtilGenerics#checkCollection(Object)’

(OFBIZ-11141)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863502 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 20, 2019
1 parent e9a56a7 commit 54f210a8668f3b300827fb9cf5cc7b366406d75f
@@ -179,7 +179,7 @@
Delegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
Map<String, Object> result = new HashMap<>();
List<String> featureOrder = UtilMisc.makeListWritable(UtilGenerics.<String>checkCollection(context.get("featureOrder")));
List<String> featureOrder = UtilMisc.makeListWritable(UtilGenerics.cast(context.get("featureOrder")));

if (UtilValidate.isEmpty(featureOrder)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
@@ -520,7 +520,7 @@ Now you have a confirmed production run (starting tomorrow) happening in facilit
calendarType = "CAL_PERSONAL";
}
String partyId = (String) context.get("partyId");
Collection<String> partyIds = UtilGenerics.checkCollection(context.get("partyIds"));
Collection<String> partyIds = UtilGenerics.cast(context.get("partyIds"));
String facilityId = (String) context.get("facilityId");
String fixedAssetId = (String) context.get("fixedAssetId");
String workEffortTypeId = (String) context.get("workEffortTypeId");
@@ -32,10 +32,6 @@ private UtilGenerics() {}
return (V) object;
}

public static <T> Collection<T> checkCollection(Object object) {
return cast(object);
}

public static <E, C extends Collection<E>> C checkCollection(Object object, Class<E> type) {
if (object != null) {
if (!(Collection.class.isInstance(object))) {
@@ -342,7 +342,7 @@ private static Object transformParamValue(String[] value) {
paramEntry.setValue(canonicalizeParameter((String) paramEntry.getValue()));
} else if (paramEntry.getValue() instanceof Collection<?>) {
List<String> newList = new LinkedList<>();
for (String listEntry: UtilGenerics.<String>checkCollection(paramEntry.getValue())) {
for (String listEntry: UtilGenerics.<Collection<String>>cast(paramEntry.getValue())) {
newList.add(canonicalizeParameter(listEntry));
}
paramEntry.setValue(newList);
@@ -997,7 +997,8 @@ public static void addValue(StringBuffer buffer, ModelField field, Object value,
public static void addValue(StringBuilder buffer, ModelField field, Object value, List<EntityConditionParam> params) {
if (value instanceof Collection<?>) {
buffer.append("(");
Iterator<Object> it = UtilGenerics.checkCollection(value).iterator();
Collection<Object> coll = UtilGenerics.cast(value);
Iterator<Object> it = coll.iterator();
while (it.hasNext()) {
Object thisValue = it.next();
addValueSingle(buffer, field, thisValue, params);
@@ -96,7 +96,7 @@ public boolean doCompare(Object lValue, Object rValue, Class<?> type, Locale loc
return false;
}
if (lValue instanceof Collection) {
Collection<Object> collection = UtilGenerics.checkCollection(lValue);
Collection<Object> collection = UtilGenerics.cast(lValue);
return collection.contains(rValue);
}
if (lValue instanceof String && rValue instanceof String) {
@@ -100,7 +100,7 @@ public boolean exec(MethodContext methodContext) throws MiniLangException {
throw new MiniLangRuntimeException("Error with entityListIterator: " + e.getMessage(), this);
}
} else if (objList instanceof Collection<?>) {
Collection<Object> theCollection = UtilGenerics.checkCollection(objList);
Collection<Object> theCollection = UtilGenerics.cast(objList);
if (theCollection.size() == 0) {
if (Debug.verboseOn()) {
Debug.logVerbose("Collection has zero entries, doing nothing: " + this, module);
@@ -18,7 +18,6 @@
*******************************************************************************/
package org.apache.ofbiz.webapp.event;

import static org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
import static org.apache.ofbiz.base.util.UtilGenerics.checkMap;

import java.io.File;
@@ -404,7 +403,7 @@ public static Object getObjectFromServicePath(String servicePath, Map<String, ?
servicePathMap.put(entry.getKey(), entry.getValue());
}
} else if (servicePathObject instanceof Collection<?>) {
Collection<?> servicePathColl = checkCollection(servicePathObject);
Collection<?> servicePathColl = UtilGenerics.cast(servicePathObject);
int count=0;
servicePathMap = new HashMap<>();
for (Object value: servicePathColl) {
@@ -380,7 +380,7 @@ public String getEntry(Map<String, ? extends Object> context, String defaultValu
DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd hh:mm:ss z yyyy", timeZone, null);
return df.format((java.util.Date) retVal);
} else if (retVal instanceof Collection) {
Collection<Object> col = UtilGenerics.checkCollection(retVal);
Collection<Object> col = UtilGenerics.cast(retVal);
Iterator<Object> iter = col.iterator();
List<Object> newCol = new ArrayList<>(col.size());
while (iter.hasNext()) {

0 comments on commit 54f210a

Please sign in to comment.
You can’t perform that action at this time.