Author: mthl
Date: Sat Jul 20 16:18:23 2019
New Revision: 1863489
URL: http://svn.apache.org/viewvc?rev=1863489&view=rev
Log:
Improved: Make ‘UtilGenerics#checkCollection(Object, Class)’ more generic
(OFBIZ-11141)
Remove ‘checkList’, ‘checkSet’ and ‘checkStack’ by using
‘checkCollection’ instead.
Modified:
ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilGenericsTest.java
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/status/StatusServices.java
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncServices.java
Modified:
ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
(original)
+++
ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/ICalConverter.java
Sat Jul 20 16:18:23 2019
@@ -440,7 +440,7 @@ public class ICalConverter {
protected static List<GenericValue> getRelatedWorkEfforts(GenericValue
workEffort, Map<String, Object> context) {
Map<String, ? extends Object> serviceMap =
UtilMisc.toMap("workEffortId", workEffort.getString("workEffortId"));
Map<String, Object> resultMap = invokeService("getICalWorkEfforts",
serviceMap, context);
- List<GenericValue> workEfforts =
UtilGenerics.checkList(resultMap.get("workEfforts"), GenericValue.class);
+ List<GenericValue> workEfforts =
UtilGenerics.checkCollection(resultMap.get("workEfforts"), GenericValue.class);
if (workEfforts != null) {
return WorkEffortWorker.removeDuplicateWorkEfforts(workEfforts);
}
@@ -735,7 +735,7 @@ public class ICalConverter {
validWorkEfforts.add(workEffort.getString("workEffortId"));
}
}
- List<Component> components =
UtilGenerics.checkList(calendar.getComponents(), Component.class);
+ List<Component> components =
UtilGenerics.checkCollection(calendar.getComponents(), Component.class);
ResponseProperties responseProps = null;
for (Component component : components) {
if (Component.VEVENT.equals(component.getName()) ||
Component.VTODO.equals(component.getName())) {
@@ -784,9 +784,9 @@ public class ICalConverter {
ResponseProperties responseProps = null;
Map<String, Object> serviceMap = new HashMap<>();
List<Property> partyList = new LinkedList<>();
-
partyList.addAll(UtilGenerics.checkList(component.getProperties("ATTENDEE"),
Property.class));
-
partyList.addAll(UtilGenerics.checkList(component.getProperties("CONTACT"),
Property.class));
-
partyList.addAll(UtilGenerics.checkList(component.getProperties("ORGANIZER"),
Property.class));
+
partyList.addAll(UtilGenerics.checkCollection(component.getProperties("ATTENDEE"),
Property.class));
+
partyList.addAll(UtilGenerics.checkCollection(component.getProperties("CONTACT"),
Property.class));
+
partyList.addAll(UtilGenerics.checkCollection(component.getProperties("ORGANIZER"),
Property.class));
for (Property property : partyList) {
String partyId = fromXParameter(property.getParameters(),
partyIdXParamName);
if (partyId == null) {
Modified:
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilGenerics.java
Sat Jul 20 16:18:23 2019
@@ -23,7 +23,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Stack;
public final class UtilGenerics {
@@ -55,20 +54,15 @@ public final class UtilGenerics {
return cast(object);
}
- public static <T> Collection<T> checkCollection(Object object, Class<T>
type) {
+ public static <E, C extends Collection<E>> C checkCollection(Object
object, Class<E> type) {
checkCollectionContainment(object, Collection.class, type);
- return checkCollection(object);
+ return cast(object);
}
public static <T> List<T> checkList(Object object) {
return cast(object);
}
- public static <T> List<T> checkList(Object object, Class<T> type) {
- checkCollectionContainment(object, List.class, type);
- return checkList(object);
- }
-
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> checkMap(Object object) {
if (object != null && !(object instanceof Map)) {
@@ -97,20 +91,10 @@ public final class UtilGenerics {
return checkMap(object);
}
- public static <T> Stack<T> checkStack(Object object, Class<T> type) {
- checkCollectionContainment(object, Stack.class, type);
- return cast(object);
- }
-
public static <T> Set<T> checkSet(Object object) {
return cast(object);
}
- public static <T> Set<T> checkSet(Object object, Class<T> type) {
- checkCollectionContainment(object, Set.class, type);
- return checkSet(object);
- }
-
/** Returns the Object argument as a parameterized List if the Object
argument
* is an instance of List. Otherwise returns null.
*/
Modified:
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
Sat Jul 20 16:18:23 2019
@@ -23,7 +23,6 @@ import static java.util.stream.Collector
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
-import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -236,7 +235,7 @@ public final class UtilHttp {
if (multiPartMap.containsKey(fieldName)) {
Object mapValue = multiPartMap.get(fieldName);
if (mapValue instanceof List<?>) {
- checkList(mapValue,
Object.class).add(item.getString());
+ UtilGenerics.checkCollection(mapValue,
Object.class).add(item.getString());
} else if (mapValue instanceof String) {
List<String> newList = new LinkedList<>();
newList.add((String) mapValue);
Modified:
ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilGenericsTest.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilGenericsTest.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilGenericsTest.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilGenericsTest.java
Sat Jul 20 16:18:23 2019
@@ -21,6 +21,7 @@ package org.apache.ofbiz.base.util;
import static org.junit.Assert.assertNull;
import java.util.Arrays;
+import java.util.Collection;
import org.junit.Test;
@@ -28,21 +29,21 @@ public class UtilGenericsTest {
@Test
public void basicCheckCollection() {
- UtilGenerics.<String>checkCollection(Arrays.asList("foo", "bar",
"baz"), String.class);
+ UtilGenerics.<String,
Collection<String>>checkCollection(Arrays.asList("foo", "bar", "baz"),
String.class);
}
@Test(expected = ClassCastException.class)
public void incompatibleCollectionCheckCollection() {
- UtilGenerics.<String>checkCollection("not a collection", String.class);
+ UtilGenerics.<String, Collection<String>>checkCollection("not a
collection", String.class);
}
@Test(expected = IllegalArgumentException.class)
public void heterogenousCheckCollection() {
- UtilGenerics.<String>checkCollection(Arrays.asList("foo", 0),
String.class);
+ UtilGenerics.<String,
Collection<String>>checkCollection(Arrays.asList("foo", 0), String.class);
}
@Test
public void nullCheckCollection() {
- assertNull(UtilGenerics.<String>checkCollection(null, String.class));
+ assertNull(UtilGenerics.<String,
Collection<String>>checkCollection(null, String.class));
}
}
Modified:
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/CommonServices.java
Sat Jul 20 16:18:23 2019
@@ -18,7 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.common;
-import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
+import static org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
import static org.apache.ofbiz.base.util.UtilGenerics.checkMap;
import java.io.BufferedReader;
@@ -432,7 +432,7 @@ public class CommonServices {
}
public static Map<String, Object> simpleMapListTest(DispatchContext dctx,
Map<String, ?> context) {
- List<String> listOfStrings = checkList(context.get("listOfStrings"),
String.class);
+ List<String> listOfStrings =
checkCollection(context.get("listOfStrings"), String.class);
Map<String, String> mapOfStrings =
checkMap(context.get("mapOfStrings"), String.class, String.class);
for (String str: listOfStrings) {
Modified:
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java
Sat Jul 20 16:18:23 2019
@@ -18,7 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.common;
-import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
+import static org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
import static org.apache.ofbiz.base.util.UtilGenerics.checkMap;
import java.sql.Timestamp;
@@ -551,7 +551,7 @@ public class FindServices {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"CommonFindErrorPreparingConditions", UtilMisc.toMap("errorString",
gse.getMessage()), locale));
}
EntityConditionList<EntityCondition> exprList =
UtilGenerics.cast(prepareResult.get("entityConditionList"));
- List<String> orderByList = checkList(prepareResult.get("orderByList"),
String.class);
+ List<String> orderByList =
checkCollection(prepareResult.get("orderByList"), String.class);
Map<String, Object> executeResult = null;
try {
@@ -667,7 +667,7 @@ public class FindServices {
public static Map<String, Object> executeFind(DispatchContext dctx,
Map<String, ?> context) {
String entityName = (String) context.get("entityName");
EntityConditionList<EntityCondition> entityConditionList =
UtilGenerics.cast(context.get("entityConditionList"));
- List<String> orderByList = checkList(context.get("orderByList"),
String.class);
+ List<String> orderByList = checkCollection(context.get("orderByList"),
String.class);
boolean noConditionFind = "Y".equals(context.get("noConditionFind"));
boolean distinct = "Y".equals(context.get("distinct"));
List<String> fieldList =
UtilGenerics.checkList(context.get("fieldList"));
Modified:
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/FtpServices.java
Sat Jul 20 16:18:23 2019
@@ -18,8 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.common;
-import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
-
+import static org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -96,7 +95,7 @@ public class FtpServices {
errorList.add(UtilProperties.getMessage(resource,
"CommonFtpFileNotSentSuccesfully", UtilMisc.toMap("replyString",
ftp.getReplyString()), locale));
} else {
Debug.logInfo("[putFile] store was successful",
module);
- List<String> siteCommands =
checkList(context.get("siteCommands"), String.class);
+ List<String> siteCommands =
checkCollection(context.get("siteCommands"), String.class);
if (siteCommands != null) {
for (String command : siteCommands) {
Debug.logInfo("[putFile] sending SITE command:
" + command, module);
Modified:
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/status/StatusServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/status/StatusServices.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/status/StatusServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/status/StatusServices.java
Sat Jul 20 16:18:23 2019
@@ -18,8 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.common.status;
-import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
-
+import static org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -46,7 +45,7 @@ public class StatusServices {
public static Map<String, Object> getStatusItems(DispatchContext ctx,
Map<String, ?> context) {
Delegator delegator = ctx.getDelegator();
- List<String> statusTypes = checkList(context.get("statusTypeIds"),
String.class);
+ List<String> statusTypes =
checkCollection(context.get("statusTypeIds"), String.class);
Locale locale = (Locale) context.get("locale");
if (UtilValidate.isEmpty(statusTypes)) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"CommonStatusMandatory", locale));
Modified:
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/common/src/main/java/org/apache/ofbiz/common/telecom/TelecomServices.java
Sat Jul 20 16:18:23 2019
@@ -18,8 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.common.telecom;
-import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
-
+import static org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -51,7 +50,7 @@ public class TelecomServices {
String telecomMsgTypeEnumId = (String)
context.get("telecomMsgTypeEnumId");
String telecomMethodTypeId = (String)
context.get("telecomMethodTypeId");
String telecomGatewayConfigId = (String)
context.get("telecomGatewayConfigId");
- List<String> numbers = checkList(context.get("numbers"), String.class);
+ List<String> numbers = checkCollection(context.get("numbers"),
String.class);
String message = (String) context.get("message");
String telecomEnabled =
EntityUtilProperties.getPropertyValue("general",
"telecom.notifications.enabled", delegator);
Modified:
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncServices.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncServices.java?rev=1863489&r1=1863488&r2=1863489&view=diff
==============================================================================
---
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncServices.java
(original)
+++
ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/synchronization/EntitySyncServices.java
Sat Jul 20 16:18:23 2019
@@ -18,8 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.entityext.synchronization;
-import static org.apache.ofbiz.base.util.UtilGenerics.checkList;
-
+import static org.apache.ofbiz.base.util.UtilGenerics.checkCollection;
import java.io.IOException;
import java.net.URL;
import java.sql.Timestamp;
@@ -325,11 +324,11 @@ public class EntitySyncServices {
gotMoreData = true;
// at least one of the is not empty, make sure none of
them are null now too...
- List<GenericValue> valuesToCreate =
checkList(result.get("valuesToCreate"), GenericValue.class);
+ List<GenericValue> valuesToCreate =
checkCollection(result.get("valuesToCreate"), GenericValue.class);
if (valuesToCreate == null) valuesToCreate =
Collections.emptyList();
- List<GenericValue> valuesToStore =
checkList(result.get("valuesToStore"), GenericValue.class);
+ List<GenericValue> valuesToStore =
checkCollection(result.get("valuesToStore"), GenericValue.class);
if (valuesToStore == null) valuesToStore =
Collections.emptyList();
- List<GenericEntity> keysToRemove =
checkList(result.get("keysToRemove"), GenericEntity.class);
+ List<GenericEntity> keysToRemove =
checkCollection(result.get("keysToRemove"), GenericEntity.class);
if (keysToRemove == null) keysToRemove =
Collections.emptyList();
Map<String, Object> callLocalStoreContext =
UtilMisc.toMap("entitySyncId", entitySyncId, "delegatorName",
context.get("localDelegatorName"),
@@ -557,9 +556,9 @@ public class EntitySyncServices {
// de-serialize the value lists
try {
- List<GenericValue> valuesToCreate =
checkList(XmlSerializer.deserialize(createString, delegator),
GenericValue.class);
- List<GenericValue> valuesToStore =
checkList(XmlSerializer.deserialize(storeString, delegator),
GenericValue.class);
- List<GenericEntity> keysToRemove =
checkList(XmlSerializer.deserialize(removeString, delegator),
GenericEntity.class);
+ List<GenericValue> valuesToCreate =
checkCollection(XmlSerializer.deserialize(createString, delegator),
GenericValue.class);
+ List<GenericValue> valuesToStore =
checkCollection(XmlSerializer.deserialize(storeString, delegator),
GenericValue.class);
+ List<GenericEntity> keysToRemove =
checkCollection(XmlSerializer.deserialize(removeString, delegator),
GenericEntity.class);
Map<String, Object> storeContext =
UtilMisc.toMap("entitySyncId", entitySyncId, "valuesToCreate", valuesToCreate,
"valuesToStore", valuesToStore,
"keysToRemove", keysToRemove, "userLogin", userLogin);