svn commit: r713573 - /ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r713573 - /ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java

doogie-3
Author: doogie
Date: Wed Nov 12 16:14:30 2008
New Revision: 713573

URL: http://svn.apache.org/viewvc?rev=713573&view=rev
Log:
Replay the generics patch, the fix for the reported bug is nexted.

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java?rev=713573&r1=713572&r2=713573&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductServices.java Wed Nov 12 16:14:30 2008
@@ -28,9 +28,11 @@
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
+import javolution.util.FastSet;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
@@ -58,38 +60,34 @@
     /**
      * Creates a Collection of product entities which are variant products from the specified product ID.
      */
-    public static Map prodFindAllVariants(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodFindAllVariants(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Parent (virtual) product ID
-        context.put("type", "PRODUCT_VARIANT");
-        return prodFindAssociatedByType(dctx, context);
+        Map<String, Object> subContext = UtilMisc.makeMapWritable(context);
+        subContext.put("type", "PRODUCT_VARIANT");
+        return prodFindAssociatedByType(dctx, subContext);
     }
 
     /**
      * Finds a specific product or products which contain the selected features.
      */
-    public static Map prodFindSelectedVariant(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodFindSelectedVariant(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Parent (virtual) product ID
         // * Map selectedFeatures  -- Selected features
         GenericDelegator delegator = dctx.getDelegator();
         Locale locale = (Locale) context.get("locale");
         String productId = (String) context.get("productId");
-        Map selectedFeatures = (Map) context.get("selectedFeatures");
-        ArrayList products = new ArrayList();
+        Map selectedFeatures = UtilGenerics.checkMap(context.get("selectedFeatures"));
+        List<GenericValue> products = FastList.newInstance();
         // All the variants for this products are retrieved
-        Map resVariants = prodFindAllVariants(dctx, context);
-        List variants = (List)resVariants.get("assocProducts");
-        GenericValue oneVariant = null;
-        Iterator variantsIt = variants.iterator();
-        while (variantsIt.hasNext()) {
+        Map<String, Object> resVariants = prodFindAllVariants(dctx, context);
+        List<GenericValue> variants = UtilGenerics.checkList(resVariants.get("assocProducts"));
+        for (GenericValue oneVariant: variants) {
             // For every variant, all the standard features are retrieved
-            oneVariant = (GenericValue)variantsIt.next();
-            Map feaContext = new HashMap();
-            feaContext.put("productId", oneVariant.get("productIdTo"));
+            Map<String, String> feaContext = FastMap.newInstance();
+            feaContext.put("productId", oneVariant.getString("productIdTo"));
             feaContext.put("type", "STANDARD_FEATURE");
-            Map resFeatures = prodGetFeatures(dctx, feaContext);
-            List features = (List)resFeatures.get("productFeatures");
-            Iterator featuresIt = features.iterator();
-            GenericValue oneFeature = null;
+            Map<String, Object> resFeatures = prodGetFeatures(dctx, feaContext);
+            List<GenericValue> features = UtilGenerics.checkList(resFeatures.get("productFeatures"));
             boolean variantFound = true;
             // The variant is discarded if at least one of its standard features
             // has the same type of one of the selected features but a different feature id.
@@ -99,8 +97,7 @@
             // Variant2: (COLOR, Black), (SIZE, Small) --> ok
             // Variant3: (COLOR, Black), (SIZE, Small), (IMAGE, SkyLine) --> ok
             // Variant4: (COLOR, Black), (IMAGE, SkyLine) --> ok
-            while (featuresIt.hasNext()) {
-                oneFeature = (GenericValue)featuresIt.next();
+            for (GenericValue oneFeature: features) {
                 if (selectedFeatures.containsKey(oneFeature.getString("productFeatureTypeId"))) {
                     if (!selectedFeatures.containsValue(oneFeature.getString("productFeatureId"))) {
                         variantFound = false;
@@ -112,7 +109,7 @@
                 try {
                     products.add(delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", oneVariant.getString("productIdTo"))));
                 } catch (GenericEntityException e) {
-                    Map messageMap = UtilMisc.toMap("errProductFeatures", e.toString());
+                    Map<String, String> messageMap = UtilMisc.toMap("errProductFeatures", e.toString());
                     String errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_features_errors", messageMap, locale);
                     Debug.logError(e, errMsg, module);
                     return ServiceUtil.returnError(errMsg);
@@ -120,7 +117,7 @@
             }
         }
 
-        Map result = ServiceUtil.returnSuccess();
+        Map<String, Object> result = ServiceUtil.returnSuccess();
         result.put("products", products);
         return result;
     }
@@ -128,7 +125,7 @@
     /**
      * Finds product variants based on a product ID and a distinct feature.
      */
-    public static Map prodFindDistinctVariants(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodFindDistinctVariants(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Parent (virtual) product ID
         // * String feature        -- Distinct feature name
         GenericDelegator delegator = dctx.getDelegator();
@@ -141,25 +138,24 @@
     /**
      * Finds a Set of feature types in sequence.
      */
-    public static Map prodFindFeatureTypes(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodFindFeatureTypes(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Product ID to look up feature types
         GenericDelegator delegator = dctx.getDelegator();
         String productId = (String) context.get("productId");
         Locale locale = (Locale) context.get("locale");
         String errMsg=null;
-        Set featureSet = new LinkedHashSet();
+        Set<String> featureSet = new LinkedHashSet<String>();
 
         try {
-            Map fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE");
-            List order = UtilMisc.toList("sequenceNum", "productFeatureTypeId");
-            List features = delegator.findByAndCache("ProductFeatureAndAppl", fields, order);
-            Iterator i = features.iterator();
-            while (i.hasNext()) {
-                featureSet.add(((GenericValue) i.next()).getString("productFeatureTypeId"));
+            Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE");
+            List<String> order = UtilMisc.toList("sequenceNum", "productFeatureTypeId");
+            List<GenericValue> features = delegator.findByAndCache("ProductFeatureAndAppl", fields, order);
+            for (GenericValue v: features) {
+                featureSet.add(v.getString("productFeatureTypeId"));
             }
             //if (Debug.infoOn()) Debug.logInfo("" + featureSet, module);
         } catch (GenericEntityException e) {
-            Map messageMap = UtilMisc.toMap("errProductFeatures", e.toString());
+            Map<String, String> messageMap = UtilMisc.toMap("errProductFeatures", e.toString());
             errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_features_errors", messageMap, locale);
             Debug.logError(e, errMsg, module);
             return ServiceUtil.returnError(errMsg);
@@ -171,7 +167,7 @@
             Debug.logWarning(errMsg + " for product " + productId, module);
             //return ServiceUtil.returnError(errMsg);
         }
-        Map result = ServiceUtil.returnSuccess();
+        Map<String, Object> result = ServiceUtil.returnSuccess();
         result.put("featureSet", featureSet);
         return result;
     }
@@ -179,7 +175,7 @@
     /**
      * Builds a variant feature tree.
      */
-    public static Map prodMakeFeatureTree(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodMakeFeatureTree(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Parent (virtual) product ID
         // * List featureOrder     -- Order of features
         // * String productStoreId -- Product Store ID for Inventory
@@ -188,24 +184,23 @@
 
         GenericDelegator delegator = dctx.getDelegator();
         LocalDispatcher dispatcher = dctx.getDispatcher();
-        Map result = new HashMap();
-        List featureOrder = new LinkedList((Collection) context.get("featureOrder"));
+        Map<String, Object> result = FastMap.newInstance();
+        List<String> featureOrder = UtilMisc.makeListWritable(UtilGenerics.<String>checkList(context.get("featureOrder")));
 
         if (featureOrder == null || featureOrder.size() == 0) {
             return ServiceUtil.returnError("Empty list of features passed");
         }
 
-        Collection variants = (Collection) prodFindAllVariants(dctx, context).get("assocProducts");
-        List virtualVariant = new ArrayList();
+        List<GenericValue> variants = UtilGenerics.checkList(prodFindAllVariants(dctx, context).get("assocProducts"));
+        List<String> virtualVariant = FastList.newInstance();
 
         if (variants == null || variants.size() == 0) {
             return ServiceUtil.returnSuccess();
         }
-        List items = new ArrayList();
-        Iterator i = variants.iterator();
+        List<String> items = FastList.newInstance();
 
-        while (i.hasNext()) {
-            String productIdTo = (String) ((GenericValue) i.next()).get("productIdTo");
+        for (GenericValue variant: variants) {
+            String productIdTo = variant.getString("productIdTo");
 
             // first check to see if intro and discontinue dates are within range
             GenericValue productTo = null;
@@ -214,7 +209,7 @@
                 productTo = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productIdTo));
             } catch (GenericEntityException e) {
                 Debug.logError(e, module);
-                Map messageMap = UtilMisc.toMap("productIdTo", productIdTo, "errMessage", e.toString());
+                Map<String, String> messageMap = UtilMisc.toMap("productIdTo", productIdTo, "errMessage", e.toString());
                 return ServiceUtil.returnError(UtilProperties.getMessage(resource, "productservices.error_finding_associated_variant_with_ID_error", messageMap, locale));
             }
             if (productTo == null) {
@@ -248,7 +243,7 @@
 
             // next check inventory for each item: if inventory is not required or is available
             try {
-                Map invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", productIdTo, "quantity", new Double(1.0)));
+                Map<String, Object> invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", productIdTo, "quantity", Double.valueOf(1.0)));
                 if (ServiceUtil.isError(invReqResult)) {
                     return ServiceUtil.returnError("Error calling the isStoreInventoryRequired when building the variant product tree.", null, null, invReqResult);
                 } else if ("Y".equals((String) invReqResult.get("availableOrNotRequired"))) {
@@ -267,10 +262,10 @@
         String productId = (String) context.get("productId");
 
         // Make the selectable feature list
-        List selectableFeatures = null;
+        List<GenericValue> selectableFeatures = null;
         try {
-            Map fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE");
-            List sort = UtilMisc.toList("sequenceNum");
+            Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE");
+            List<String> sort = UtilMisc.toList("sequenceNum");
 
             selectableFeatures = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort);
             selectableFeatures = EntityUtil.filterByDate(selectableFeatures, true);
@@ -278,20 +273,17 @@
             Debug.logError(e, module);
             return ServiceUtil.returnError(UtilProperties.getMessage(resource,"productservices.empty_list_of_selectable_features_found", locale));
         }
-        Map features = new HashMap();
-        Iterator sFIt = selectableFeatures.iterator();
-
-        while (sFIt.hasNext()) {
-            GenericValue v = (GenericValue) sFIt.next();
+        Map<String, List<String>> features = FastMap.newInstance();
+        for (GenericValue v: selectableFeatures) {
             String featureType = v.getString("productFeatureTypeId");
             String feature = v.getString("description");
 
             if (!features.containsKey(featureType)) {
-                List featureList = new LinkedList();
+                List<String> featureList = FastList.newInstance();
                 featureList.add(feature);
                 features.put(featureType, featureList);
             } else {
-                List featureList = (LinkedList) features.get(featureType);
+                List<String> featureList = features.get(featureType);
                 featureList.add(feature);
                 features.put(featureType, featureList);
             }
@@ -313,9 +305,9 @@
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         }
 
-        Map sample = null;
+        Map<String, GenericValue> sample = null;
         try {
-            sample = makeVariantSample(dctx.getDelegator(), features, items, (String) featureOrder.get(0));
+            sample = makeVariantSample(dctx.getDelegator(), features, items, featureOrder.get(0));
         } catch (Exception e) {
             return ServiceUtil.returnError(e.getMessage());
         }
@@ -329,22 +321,22 @@
     /**
      * Gets the product features of a product.
      */
-    public static Map prodGetFeatures(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodGetFeatures(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Product ID to fond
         // * String type           -- Type of feature (STANDARD_FEATURE, SELECTABLE_FEATURE)
         // * String distinct       -- Distinct feature (SIZE, COLOR)
         GenericDelegator delegator = dctx.getDelegator();
-        Map result = new HashMap();
+        Map<String, Object> result = FastMap.newInstance();
         String productId = (String) context.get("productId");
         String distinct = (String) context.get("distinct");
         String type = (String) context.get("type");
         Locale locale = (Locale) context.get("locale");
         String errMsg=null;
-        Collection features = null;
+        List<GenericValue> features = null;
 
         try {
-            Map fields = UtilMisc.toMap("productId", productId);
-            List order = UtilMisc.toList("sequenceNum", "productFeatureTypeId");
+            Map<String, String> fields = UtilMisc.toMap("productId", productId);
+            List<String> order = UtilMisc.toList("sequenceNum", "productFeatureTypeId");
 
             if (distinct != null) fields.put("productFeatureTypeId", distinct);
             if (type != null) fields.put("productFeatureApplTypeId", type);
@@ -352,7 +344,7 @@
             result.put("productFeatures", features);
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         } catch (GenericEntityException e) {
-            Map messageMap = UtilMisc.toMap("errMessage", e.toString());
+            Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString());
             errMsg = UtilProperties.getMessage(resource,"productservices.problem_reading_product_feature_entity", messageMap, locale);
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
             result.put(ModelService.ERROR_MESSAGE, errMsg);
@@ -363,10 +355,10 @@
     /**
      * Finds a product by product ID.
      */
-    public static Map prodFindProduct(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodFindProduct(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Product ID to find
         GenericDelegator delegator = dctx.getDelegator();
-        Map result = new HashMap();
+        Map<String, Object> result = FastMap.newInstance();
         String productId = (String) context.get("productId");
         Locale locale = (Locale) context.get("locale");
         String errMsg = null;
@@ -383,13 +375,13 @@
             GenericValue mainProduct = product;
 
             if (product.get("isVariant") != null && product.getString("isVariant").equalsIgnoreCase("Y")) {
-                List c = product.getRelatedByAndCache("AssocProductAssoc",
+                List<GenericValue> c = product.getRelatedByAndCache("AssocProductAssoc",
                         UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT"));
                 //if (Debug.infoOn()) Debug.logInfo("Found related: " + c, module);
                 c = EntityUtil.filterByDate(c);
                 //if (Debug.infoOn()) Debug.logInfo("Found Filtered related: " + c, module);
                 if (c.size() > 0) {
-                    GenericValue asV = (GenericValue) c.iterator().next();
+                    GenericValue asV = c.iterator().next();
 
                     //if (Debug.infoOn()) Debug.logInfo("ASV: " + asV, module);
                     mainProduct = asV.getRelatedOneCache("MainProduct");
@@ -400,7 +392,7 @@
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         } catch (GenericEntityException e) {
             e.printStackTrace();
-            Map messageMap = UtilMisc.toMap("errMessage", e.getMessage());
+            Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage());
             errMsg = UtilProperties.getMessage(resource,"productservices.problems_reading_product_entity", messageMap, locale);
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
             result.put(ModelService.ERROR_MESSAGE, errMsg);
@@ -412,11 +404,11 @@
     /**
      * Finds associated products by product ID and association ID.
      */
-    public static Map prodFindAssociatedByType(DispatchContext dctx, Map context) {
+    public static Map<String, Object> prodFindAssociatedByType(DispatchContext dctx, Map<String, ? extends Object> context) {
         // * String productId      -- Current Product ID
         // * String type           -- Type of association (ie PRODUCT_UPGRADE, PRODUCT_COMPLEMENT, PRODUCT_VARIANT)
         GenericDelegator delegator = dctx.getDelegator();
-        Map result = new HashMap();
+        Map<String, Object> result = FastMap.newInstance();
         String productId = (String) context.get("productId");
         String productIdTo = (String) context.get("productIdTo");
         String type = (String) context.get("type");
@@ -447,7 +439,7 @@
         try {
             product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));
         } catch (GenericEntityException e) {
-            Map messageMap = UtilMisc.toMap("errMessage", e.getMessage());
+            Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage());
             errMsg = UtilProperties.getMessage(resource,"productservices.productservices.problems_reading_product_entity", messageMap, locale);
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
             result.put(ModelService.ERROR_MESSAGE, errMsg);
@@ -462,7 +454,7 @@
         }
 
         try {
-            List productAssocs = null;
+            List<GenericValue> productAssocs = null;
 
             if (productIdTo == null) {
                 productAssocs = product.getRelatedCache("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", type), UtilMisc.toList("sequenceNum"));
@@ -487,7 +479,7 @@
             result.put("assocProducts", productAssocs);
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         } catch (GenericEntityException e) {
-            Map messageMap = UtilMisc.toMap("errMessage", e.getMessage());
+            Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage());
             errMsg = UtilProperties.getMessage(resource,"productservices.problems_product_association_relation_error", messageMap, locale);
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
             result.put(ModelService.ERROR_MESSAGE, errMsg);
@@ -498,11 +490,11 @@
     }
 
     // Builds a product feature tree
-    private static Map makeGroup(GenericDelegator delegator, Map featureList, List items, List order, int index)
+    private static Map<String, Object> makeGroup(GenericDelegator delegator, Map<String, List<String>> featureList, List<String> items, List<String> order, int index)
         throws IllegalArgumentException, IllegalStateException {
-        //List featureKey = new ArrayList();
-        Map tempGroup = new HashMap();
-        Map group = new LinkedHashMap();
+        //List featureKey = FastList.newInstance();
+        Map<String, List<String>> tempGroup = FastMap.newInstance();
+        Map<String, Object> group = new LinkedHashMap<String, Object>();
         String orderKey = (String) order.get(index);
 
         if (featureList == null) {
@@ -517,21 +509,18 @@
         }
 
         // loop through items and make the lists
-        Iterator itemIterator = items.iterator();
-
-        while (itemIterator.hasNext()) {
+        for (String thisItem: items) {
             // -------------------------------
             // Gather the necessary data
             // -------------------------------
-            String thisItem = (String) itemIterator.next();
 
             if (Debug.verboseOn()) Debug.logVerbose("ThisItem: " + thisItem, module);
-            List features = null;
+            List<GenericValue> features = null;
 
             try {
-                Map fields = UtilMisc.toMap("productId", thisItem, "productFeatureTypeId", orderKey,
+                Map<String, String> fields = UtilMisc.toMap("productId", thisItem, "productFeatureTypeId", orderKey,
                         "productFeatureApplTypeId", "STANDARD_FEATURE");
-                List sort = UtilMisc.toList("sequenceNum");
+                List<String> sort = UtilMisc.toList("sequenceNum");
 
                 // get the features and filter out expired dates
                 features = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort);
@@ -542,19 +531,16 @@
             if (Debug.verboseOn()) Debug.logVerbose("Features: " + features, module);
 
             // -------------------------------
-            Iterator featuresIterator = features.iterator();
-
-            while (featuresIterator.hasNext()) {
-                GenericValue item = (GenericValue) featuresIterator.next();
-                Object itemKey = item.get("description");
+            for (GenericValue item: features) {
+                String itemKey = item.getString("description");
 
                 if (tempGroup.containsKey(itemKey)) {
-                    List itemList = (List) tempGroup.get(itemKey);
+                    List<String> itemList = tempGroup.get(itemKey);
 
                     if (!itemList.contains(thisItem))
                         itemList.add(thisItem);
                 } else {
-                    List itemList = UtilMisc.toList(thisItem);
+                    List<String> itemList = UtilMisc.toList(thisItem);
 
                     tempGroup.put(itemKey, itemList);
                 }
@@ -563,17 +549,13 @@
         if (Debug.verboseOn()) Debug.logVerbose("TempGroup: " + tempGroup, module);
 
         // Loop through the feature list and order the keys in the tempGroup
-        List orderFeatureList = (List) featureList.get(orderKey);
+        List<String> orderFeatureList = featureList.get(orderKey);
 
         if (orderFeatureList == null) {
             throw new IllegalArgumentException("Cannot build feature tree: orderFeatureList is null for orderKey=" + orderKey);
         }
 
-        Iterator featureListIt = orderFeatureList.iterator();
-
-        while (featureListIt.hasNext()) {
-            String featureStr = (String) featureListIt.next();
-
+        for (String featureStr: orderFeatureList) {
             if (tempGroup.containsKey(featureStr))
                 group.put(featureStr, tempGroup.get(featureStr));
         }
@@ -591,13 +573,11 @@
         }
 
         // loop through the keysets and get the sub-groups
-        Iterator groupIterator = group.keySet().iterator();
-        while (groupIterator.hasNext()) {
-            Object key = groupIterator.next();
-            List itemList = (List) group.get(key);
+        for (String key: group.keySet()) {
+            List<String> itemList = UtilGenerics.checkList(group.get(key));
 
             if (UtilValidate.isNotEmpty(itemList)) {
-                Map subGroup = makeGroup(delegator, featureList, itemList, order, index + 1);
+                Map<String, Object> subGroup = makeGroup(delegator, featureList, itemList, order, index + 1);
                 group.put(key, subGroup);
             } else {
                 // do nothing, ie put nothing in the Map
@@ -608,19 +588,16 @@
     }
 
     // builds a variant sample (a single sku for a featureType)
-    private static Map makeVariantSample(GenericDelegator delegator, Map featureList, List items, String feature) {
-        Map tempSample = new HashMap();
-        Map sample = new LinkedHashMap();
-        Iterator itemIt = items.iterator();
-
-        while (itemIt.hasNext()) {
-            String productId = (String) itemIt.next();
-            List features = null;
+    private static Map<String, GenericValue> makeVariantSample(GenericDelegator delegator, Map<String, List<String>> featureList, List<String> items, String feature) {
+        Map<String, GenericValue> tempSample = FastMap.newInstance();
+        Map<String, GenericValue> sample = new LinkedHashMap<String, GenericValue>();
+        for (String productId: items) {
+            List<GenericValue> features = null;
 
             try {
-                Map fields = UtilMisc.toMap("productId", productId, "productFeatureTypeId", feature,
+                Map<String, String> fields = UtilMisc.toMap("productId", productId, "productFeatureTypeId", feature,
                         "productFeatureApplTypeId", "STANDARD_FEATURE");
-                List sort = UtilMisc.toList("sequenceNum", "description");
+                List<String> sort = UtilMisc.toList("sequenceNum", "description");
 
                 // get the features and filter out expired dates
                 features = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort);
@@ -628,11 +605,7 @@
             } catch (GenericEntityException e) {
                 throw new IllegalStateException("Problem reading relation: " + e.getMessage());
             }
-            Iterator featureIt = features.iterator();
-
-            while (featureIt.hasNext()) {
-                GenericValue featureAppl = (GenericValue) featureIt.next();
-
+            for (GenericValue featureAppl: features) {
                 try {
                     GenericValue product = delegator.findByPrimaryKeyCache("Product",
                             UtilMisc.toMap("productId", productId));
@@ -645,12 +618,8 @@
         }
 
         // Sort the sample based on the feature list.
-        List features = (LinkedList) featureList.get(feature);
-        Iterator fi = features.iterator();
-
-        while (fi.hasNext()) {
-            String f = (String) fi.next();
-
+        List<String> features = featureList.get(feature);
+        for (String f: features) {
             if (tempSample.containsKey(f))
                 sample.put(f, tempSample.get(f));
         }
@@ -658,9 +627,9 @@
         return sample;
     }
 
-    public static Map quickAddVariant(DispatchContext dctx, Map context) {
+    public static Map<String, Object> quickAddVariant(DispatchContext dctx, Map<String, ? extends Object> context) {
         GenericDelegator delegator = dctx.getDelegator();
-        Map result = new HashMap();
+        Map<String, Object> result = FastMap.newInstance();
         Locale locale = (Locale) context.get("locale");
         String errMsg=null;
         String productId = (String) context.get("productId");
@@ -672,7 +641,7 @@
             // read the product, duplicate it with the given id
             GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));
             if (product == null) {
-                Map messageMap = UtilMisc.toMap("productId", productId);
+                Map<String, String> messageMap = UtilMisc.toMap("productId", productId);
                 errMsg = UtilProperties.getMessage(resource,"productservices.product_not_found_with_ID", messageMap, locale);
                 result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
                 result.put(ModelService.ERROR_MESSAGE, errMsg);
@@ -707,7 +676,7 @@
                                                                            "productFeatureApplTypeId", "STANDARD_FEATURE"));
             }
             // add an association from productId to variantProductId of the PRODUCT_VARIANT
-            Map productAssocMap = UtilMisc.toMap("productId", productId, "productIdTo", variantProductId,
+            Map<String, Object> productAssocMap = UtilMisc.toMap("productId", productId, "productIdTo", variantProductId,
                                                  "productAssocTypeId", "PRODUCT_VARIANT",
                                                  "fromDate", UtilDateTime.nowTimestamp());
             if (prodAssocSeqNum != null) {
@@ -737,7 +706,7 @@
             
         } catch (GenericEntityException e) {
             Debug.logError(e, "Entity error creating quick add variant data", module);
-            Map messageMap = UtilMisc.toMap("errMessage", e.toString());
+            Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString());
             errMsg = UtilProperties.getMessage(resource,"productservices.entity_error_quick_add_variant_data", messageMap, locale);
             result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
             result.put(ModelService.ERROR_MESSAGE, errMsg);
@@ -751,7 +720,7 @@
      * This will create a virtual product and return its ID, and associate all of the variants with it.
      * It will not put the selectable features on the virtual or standard features on the variant.
      */
-    public static Map quickCreateVirtualWithVariants(DispatchContext dctx, Map context) {
+    public static Map<String, Object> quickCreateVirtualWithVariants(DispatchContext dctx, Map<String, ? extends Object> context) {
         GenericDelegator delegator = dctx.getDelegator();
         Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
         
@@ -761,7 +730,7 @@
         String productFeatureIdTwo = (String) context.get("productFeatureIdTwo");
         String productFeatureIdThree = (String) context.get("productFeatureIdThree");
 
-        Map successResult = ServiceUtil.returnSuccess();
+        Map<String, Object> successResult = ServiceUtil.returnSuccess();
         
         try {
             // Generate new virtual productId, prefix with "VP", put in successResult
@@ -790,17 +759,15 @@
             
             // separate variantProductIdsBag into a Set of variantProductIds
             //note: can be comma, tab, or white-space delimited
-            Set prelimVariantProductIds = new HashSet();
-            List splitIds = Arrays.asList(variantProductIdsBag.split("[,\\p{Space}]"));
+            Set<String> prelimVariantProductIds = FastSet.newInstance();
+            List<String> splitIds = Arrays.asList(variantProductIdsBag.split("[,\\p{Space}]"));
             Debug.logInfo("Variants: bag=" + variantProductIdsBag, module);
             Debug.logInfo("Variants: split=" + splitIds, module);
             prelimVariantProductIds.addAll(splitIds);
             //note: should support both direct productIds and GoodIdentification entries (what to do if more than one GoodID? Add all?
 
-            Map variantProductsById = new HashMap();
-            Iterator variantProductIdIter = prelimVariantProductIds.iterator();
-            while (variantProductIdIter.hasNext()) {
-                String variantProductId = (String) variantProductIdIter.next();
+            Map<String, GenericValue> variantProductsById = FastMap.newInstance();
+            for (String variantProductId: prelimVariantProductIds) {
                 if (UtilValidate.isEmpty(variantProductId)) {
                     // not sure why this happens, but seems to from time to time with the split method
                     continue;
@@ -811,7 +778,7 @@
                     variantProductsById.put(variantProductId, variantProduct);
                 } else {
                     // is a GoodIdentification.idValue?
-                    List goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId));
+                    List<GenericValue> goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId));
                     if (goodIdentificationList == null || goodIdentificationList.size() == 0) {
                         // whoops, nothing found... return error
                         return ServiceUtil.returnError("Error creating a virtual with variants: the ID [" + variantProductId + "] is not a valid Product.productId or a GoodIdentification.idValue");
@@ -822,32 +789,26 @@
                         Debug.logWarning("Warning creating a virtual with variants: the ID [" + variantProductId + "] was not a productId and resulted in [" + goodIdentificationList.size() + "] GoodIdentification records: " + goodIdentificationList, module);
                     }
                     
-                    Iterator goodIdentificationIter = goodIdentificationList.iterator();
-                    while (goodIdentificationIter.hasNext()) {
-                        GenericValue goodIdentification = (GenericValue) goodIdentificationIter.next();
+                    for (GenericValue goodIdentification: goodIdentificationList) {
                         GenericValue giProduct = goodIdentification.getRelatedOne("Product");
                         if (giProduct != null) {
-                            variantProductsById.put(giProduct.get("productId"), giProduct);
+                            variantProductsById.put(giProduct.getString("productId"), giProduct);
                         }
                     }
                 }
             }
 
             // Attach productFeatureIdOne, Two, Three to the new virtual and all variant products as a standard feature
-            Set featureProductIds = new HashSet();
+            Set<String> featureProductIds = FastSet.newInstance();
             featureProductIds.add(productId);
             featureProductIds.addAll(variantProductsById.keySet());
-            Set productFeatureIds = new HashSet();
+            Set<String> productFeatureIds = FastSet.newInstance();
             productFeatureIds.add(productFeatureIdOne);
             productFeatureIds.add(productFeatureIdTwo);
             productFeatureIds.add(productFeatureIdThree);
             
-            Iterator featureProductIdIter = featureProductIds.iterator();
-            while (featureProductIdIter.hasNext()) {
-                Iterator productFeatureIdIter = productFeatureIds.iterator();
-                String featureProductId = (String) featureProductIdIter.next();
-                while (productFeatureIdIter.hasNext()) {
-                    String productFeatureId = (String) productFeatureIdIter.next();
+            for (String featureProductId: featureProductIds) {
+                for (String productFeatureId: productFeatureIds) {
                     if (UtilValidate.isNotEmpty(productFeatureId)) {
                         GenericValue productFeatureAppl = delegator.makeValue("ProductFeatureAppl",
                                 UtilMisc.toMap("productId", featureProductId, "productFeatureId", productFeatureId,
@@ -857,10 +818,8 @@
                 }
             }
             
-            Iterator variantProductIter = variantProductsById.values().iterator();
-            while (variantProductIter.hasNext()) {
+            for (GenericValue variantProduct: variantProductsById.values()) {
                 // for each variant product set: isVirtual=N, isVariant=Y, introductionDate=now
-                GenericValue variantProduct = (GenericValue) variantProductIter.next();
                 variantProduct.set("isVirtual", "N");
                 variantProduct.set("isVariant", "Y");
                 variantProduct.set("introductionDate", nowTimestamp);
@@ -880,7 +839,7 @@
         return successResult;
     }
 
-    public static Map updateProductIfAvailableFromShipment(DispatchContext dctx, Map context) {
+    public static Map<String, Object> updateProductIfAvailableFromShipment(DispatchContext dctx, Map<String, ? extends Object> context) {
         if ("Y".equals(UtilProperties.getPropertyValue("catalog.properties", "reactivate.product.from.receipt", "N"))) {
             LocalDispatcher dispatcher = dctx.getDispatcher();
             GenericDelegator delegator = dctx.getDelegator();
@@ -908,7 +867,7 @@
                 if (product != null) {
                     Timestamp salesDiscontinuationDate = product.getTimestamp("salesDiscontinuationDate");
                     if (salesDiscontinuationDate != null && salesDiscontinuationDate.before(UtilDateTime.nowTimestamp())) {
-                        Map invRes = null;
+                        Map<String, Object> invRes = null;
                         try {
                             invRes = dispatcher.runSync("getProductInventoryAvailable", UtilMisc.<String, Object>toMap("productId", productId, "userLogin", userLogin));
                         } catch (GenericServiceException e) {
@@ -944,7 +903,7 @@
         return ServiceUtil.returnSuccess();
     }
     
-    public static Map addAdditionalViewForProduct(DispatchContext dctx, Map context) {
+    public static Map<String, Object> addAdditionalViewForProduct(DispatchContext dctx, Map<String, ? extends Object> context) {
         LocalDispatcher dispatcher = dctx.getDispatcher();
         GenericDelegator delegator = dctx.getDelegator();
         GenericValue userLogin = (GenericValue) context.get("userLogin");
@@ -967,7 +926,7 @@
                 filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1);
             }
             
-            List fileExtension = FastList.newInstance();
+            List<GenericValue> fileExtension = FastList.newInstance();
             try {
                 fileExtension = delegator.findByAnd("FileExtension", UtilMisc.toMap("mimeTypeId", (String) context.get("_uploadedFile_contentType")));
             } catch (GenericEntityException e) {
@@ -999,12 +958,12 @@
             if (UtilValidate.isNotEmpty(imageUrl) && imageUrl.length() > 0) {
                 String contentId = (String) context.get("contentId");
                 
-                Map dataResourceCtx = FastMap.newInstance();
+                Map<String, Object> dataResourceCtx = FastMap.newInstance();
                 dataResourceCtx.put("objectInfo", imageUrl);
                 dataResourceCtx.put("dataResourceName", (String) context.get("_uploadedFile_fileName"));
                 dataResourceCtx.put("userLogin", userLogin);
                 
-                Map productContentCtx = FastMap.newInstance();
+                Map<String, Object> productContentCtx = FastMap.newInstance();
                 productContentCtx.put("productId", productId);
                 productContentCtx.put("productContentTypeId", productContentTypeId);
                 productContentCtx.put("fromDate", (Timestamp) context.get("fromDate"));
@@ -1032,14 +991,14 @@
                         if (dataResource != null) {
                             dataResourceCtx.put("dataResourceId", dataResource.getString("dataResourceId"));
                             try {
-                                Map dataResourceResult = dispatcher.runSync("updateDataResource", dataResourceCtx);
+                                dispatcher.runSync("updateDataResource", dataResourceCtx);
                             } catch (GenericServiceException e) {
                                 Debug.logError(e, module);
                                 ServiceUtil.returnError(e.getMessage());
                             }
                         } else {
                             dataResourceCtx.put("dataResourceTypeId", "URL_RESOURCE");
-                            Map dataResourceResult = FastMap.newInstance();
+                            Map<String, Object> dataResourceResult = FastMap.newInstance();
                             try {
                                 dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx);
                             } catch (GenericServiceException e) {
@@ -1047,12 +1006,12 @@
                                 ServiceUtil.returnError(e.getMessage());
                             }
                             
-                            Map contentCtx = FastMap.newInstance();
+                            Map<String, Object> contentCtx = FastMap.newInstance();
                             contentCtx.put("contentId", contentId);
                             contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId"));
                             contentCtx.put("userLogin", userLogin);
                             try {
-                                Map contentResult = dispatcher.runSync("updateContent", contentCtx);
+                                dispatcher.runSync("updateContent", contentCtx);
                             } catch (GenericServiceException e) {
                                 Debug.logError(e, module);
                                 ServiceUtil.returnError(e.getMessage());
@@ -1061,7 +1020,7 @@
                             
                         productContentCtx.put("contentId", contentId);
                         try {
-                            Map productContentResult = dispatcher.runSync("updateProductContent", productContentCtx);
+                            Map<String, Object> productContentResult = dispatcher.runSync("updateProductContent", productContentCtx);
                         } catch (GenericServiceException e) {
                             Debug.logError(e, module);
                             ServiceUtil.returnError(e.getMessage());
@@ -1069,7 +1028,7 @@
                     }
                 } else {
                     dataResourceCtx.put("dataResourceTypeId", "URL_RESOURCE");
-                    Map dataResourceResult = FastMap.newInstance();
+                    Map<String, Object> dataResourceResult = FastMap.newInstance();
                     try {
                         dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx);
                     } catch (GenericServiceException e) {
@@ -1077,11 +1036,11 @@
                         ServiceUtil.returnError(e.getMessage());
                     }
 
-                    Map contentCtx = FastMap.newInstance();
+                    Map<String, Object> contentCtx = FastMap.newInstance();
                     contentCtx.put("contentTypeId", "DOCUMENT");
                     contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId"));
                     contentCtx.put("userLogin", userLogin);
-                    Map contentResult = FastMap.newInstance();
+                    Map<String, Object> contentResult = FastMap.newInstance();
                     try {
                         contentResult = dispatcher.runSync("createContent", contentCtx);
                     } catch (GenericServiceException e) {
@@ -1091,7 +1050,7 @@
                     
                     productContentCtx.put("contentId", contentResult.get("contentId"));
                     try {
-                        Map productContentResult = dispatcher.runSync("createProductContent", productContentCtx);
+                        Map<String, Object> productContentResult = dispatcher.runSync("createProductContent", productContentCtx);
                     } catch (GenericServiceException e) {
                         Debug.logError(e, module);
                         ServiceUtil.returnError(e.getMessage());
@@ -1129,7 +1088,7 @@
         }
                 
         if (UtilValidate.isNotEmpty(productsFound)) {          
-            LinkedList<GenericValue> productsList = new LinkedList<GenericValue>();
+            List<GenericValue> productsList = FastList.newInstance();
             // gets the first productId of the List
             product = EntityUtil.getFirst(productsFound);
             // remove this productId