diff --git a/applications/order/src/org/ofbiz/order/OrderManagerEvents.java b/applications/order/src/org/ofbiz/order/OrderManagerEvents.java index 60d5ab358a..c450650489 100644 --- a/applications/order/src/org/ofbiz/order/OrderManagerEvents.java +++ b/applications/order/src/org/ofbiz/order/OrderManagerEvents.java @@ -19,7 +19,6 @@ package org.ofbiz.order; import java.math.BigDecimal; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -83,11 +82,9 @@ public class OrderManagerEvents { return "error"; } if (paymentPrefs != null) { - Iterator i = paymentPrefs.iterator(); - while (i.hasNext()) { + for(GenericValue ppref : paymentPrefs) { // update the preference to received // TODO: updating payment preferences should be done as a service - GenericValue ppref = i.next(); ppref.set("statusId", "PAYMENT_RECEIVED"); ppref.set("authDate", UtilDateTime.nowTimestamp()); toBeStored.add(ppref); @@ -179,9 +176,7 @@ public class OrderManagerEvents { return "error"; } - Iterator pmti = paymentMethodTypes.iterator(); - while (pmti.hasNext()) { - GenericValue paymentMethodType = pmti.next(); + for(GenericValue paymentMethodType : paymentMethodTypes) { String paymentMethodTypeId = paymentMethodType.getString("paymentMethodTypeId"); String amountStr = request.getParameter(paymentMethodTypeId + "_amount"); String paymentReference = request.getParameter(paymentMethodTypeId + "_reference"); @@ -251,9 +246,7 @@ public class OrderManagerEvents { Debug.logError(e, "ERROR: Unable to get existing payment preferences from order", module); } if (UtilValidate.isNotEmpty(currentPrefs)) { - Iterator cpi = currentPrefs.iterator(); - while (cpi.hasNext()) { - GenericValue cp = cpi.next(); + for(GenericValue cp : currentPrefs) { String paymentMethodType = cp.getString("paymentMethodTypeId"); if ("EXT_OFFLINE".equals(paymentMethodType)) { offlineValue = cp; diff --git a/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java b/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java index a266caa4c8..b6666d083f 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java +++ b/applications/order/src/org/ofbiz/order/order/OrderChangeHelper.java @@ -18,7 +18,6 @@ *******************************************************************************/ package org.ofbiz.order.order; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -185,9 +184,7 @@ public class OrderChangeHelper { Debug.logError(e, "ERROR: Unable to get OrderItem records for OrderHeader : " + orderId, module); } if (UtilValidate.isNotEmpty(orderItems)) { - Iterator oii = orderItems.iterator(); - while (oii.hasNext()) { - GenericValue orderItem = oii.next(); + for(GenericValue orderItem : orderItems) { String orderItemSeqId = orderItem.getString("orderItemSeqId"); GenericValue product = null; @@ -264,9 +261,7 @@ public class OrderChangeHelper { } List opps = orh.getPaymentPreferences(); - Iterator oppi = opps.iterator(); - while (oppi.hasNext()) { - GenericValue opp = oppi.next(); + for(GenericValue opp : opps) { if ("PAYMENT_RECEIVED".equals(opp.getString("statusId"))) { List payments = orh.getOrderPayments(opp); if (UtilValidate.isEmpty(payments)) { diff --git a/applications/order/src/org/ofbiz/order/order/OrderListState.java b/applications/order/src/org/ofbiz/order/order/OrderListState.java index 39dc37b029..77830d8402 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderListState.java +++ b/applications/order/src/org/ofbiz/order/order/OrderListState.java @@ -167,8 +167,7 @@ public class OrderListState implements Serializable { } private void changeOrderListStates(HttpServletRequest request) { - for (Iterator iter = parameterToOrderStatusId.keySet().iterator(); iter.hasNext();) { - String param = iter.next(); + for(String param : parameterToOrderStatusId.keySet()) { String value = request.getParameter(param); if ("Y".equals(value)) { orderStatusState.put(param, "Y"); @@ -176,8 +175,7 @@ public class OrderListState implements Serializable { orderStatusState.put(param, "N"); } } - for (Iterator iter = parameterToOrderTypeId.keySet().iterator(); iter.hasNext();) { - String param = iter.next(); + for(String param : parameterToOrderTypeId.keySet()) { String value = request.getParameter(param); if ("Y".equals(value)) { orderTypeState.put(param, "Y"); @@ -185,8 +183,7 @@ public class OrderListState implements Serializable { orderTypeState.put(param, "N"); } } - for (Iterator iter = parameterToFilterId.keySet().iterator(); iter.hasNext();) { - String param = iter.next(); + for(String param : parameterToFilterId.keySet()) { String value = request.getParameter(param); if ("Y".equals(value)) { orderFilterState.put(param, "Y"); @@ -244,14 +241,12 @@ public class OrderListState implements Serializable { } List statusConditions = FastList.newInstance(); - for (Iterator iter = orderStatusState.keySet().iterator(); iter.hasNext();) { - String status = iter.next(); + for(String status : orderFilterState.keySet()) { if (!hasStatus(status)) continue; statusConditions.add(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, parameterToOrderStatusId.get(status))); } List typeConditions = FastList.newInstance(); - for (Iterator iter = orderTypeState.keySet().iterator(); iter.hasNext();) { - String type = iter.next(); + for(String type : orderTypeState.keySet()) { if (!hasType(type)) continue; typeConditions.add(EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, parameterToOrderTypeId.get(type))); } diff --git a/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java b/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java index bb3be949be..b8ca5d7b78 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java +++ b/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java @@ -20,7 +20,6 @@ package org.ofbiz.order.order; import java.math.BigDecimal; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -115,10 +114,8 @@ public class OrderLookupServices { // the base order header fields List orderTypeList = UtilGenerics.checkList(context.get("orderTypeId")); if (orderTypeList != null) { - Iterator i = orderTypeList.iterator(); List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String orderTypeId = i.next(); + for(String orderTypeId : orderTypeList) { paramList.add("orderTypeId=" + orderTypeId); if (!"PURCHASE_ORDER".equals(orderTypeId) || ("PURCHASE_ORDER".equals(orderTypeId) && canViewPo)) { @@ -136,10 +133,8 @@ public class OrderLookupServices { List orderStatusList = UtilGenerics.checkList(context.get("orderStatusId")); if (orderStatusList != null) { - Iterator i = orderStatusList.iterator(); List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String orderStatusId = i.next(); + for(String orderStatusId : orderStatusList) { paramList.add("orderStatusId=" + orderStatusId); if ("PENDING".equals(orderStatusId)) { List pendExprs = FastList.newInstance(); @@ -156,10 +151,8 @@ public class OrderLookupServices { List productStoreList = UtilGenerics.checkList(context.get("productStoreId")); if (productStoreList != null) { - Iterator i = productStoreList.iterator(); List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String productStoreId = i.next(); + for(String productStoreId : productStoreList) { paramList.add("productStoreId=" + productStoreId); orExprs.add(EntityCondition.makeCondition("productStoreId", EntityOperator.EQUALS, productStoreId)); } @@ -168,10 +161,8 @@ public class OrderLookupServices { List webSiteList = UtilGenerics.checkList(context.get("orderWebSiteId")); if (webSiteList != null) { - Iterator i = webSiteList.iterator(); List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String webSiteId = i.next(); + for(String webSiteId : webSiteList) { paramList.add("webSiteId=" + webSiteId); orExprs.add(EntityCondition.makeCondition("webSiteId", EntityOperator.EQUALS, webSiteId)); } @@ -180,10 +171,8 @@ public class OrderLookupServices { List saleChannelList = UtilGenerics.checkList(context.get("salesChannelEnumId")); if (saleChannelList != null) { - Iterator i = saleChannelList.iterator(); List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String salesChannelEnumId = i.next(); + for(String salesChannelEnumId : saleChannelList) { paramList.add("salesChannelEnumId=" + salesChannelEnumId); orExprs.add(EntityCondition.makeCondition("salesChannelEnumId", EntityOperator.EQUALS, salesChannelEnumId)); } @@ -335,10 +324,8 @@ public class OrderLookupServices { if (roleTypeList != null) { fieldsToSelect.add("roleTypeId"); - Iterator i = roleTypeList.iterator(); List orExprs = FastList.newInstance(); - while (i.hasNext()) { - String roleTypeId = i.next(); + for(String roleTypeId : roleTypeList) { paramList.add("roleTypeId=" + roleTypeId); orExprs.add(makeExpr("roleTypeId", roleTypeId)); } @@ -397,9 +384,7 @@ public class OrderLookupServices { } List variants = UtilGenerics.checkList(varLookup.get("assocProducts")); if (variants != null) { - Iterator i = variants.iterator(); - while (i.hasNext()) { - GenericValue v = i.next(); + for(GenericValue v : variants) { orExprs.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, v.getString("productIdTo"))); } } @@ -639,9 +624,7 @@ public class OrderLookupServices { if ("Y".equals(doFilter) && orderList.size() > 0) { paramList.add("filterInventoryProblems=Y"); - Iterator i = orderList.iterator(); - while (i.hasNext()) { - GenericValue orderHeader = i.next(); + for(GenericValue orderHeader : orderList) { OrderReadHelper orh = new OrderReadHelper(orderHeader); BigDecimal backorderQty = orh.getOrderBackorderQuantity(); if (backorderQty.compareTo(BigDecimal.ZERO) == 1) { @@ -682,9 +665,7 @@ public class OrderLookupServices { } if (doPoFilter && orderList.size() > 0) { - Iterator i = orderList.iterator(); - while (i.hasNext()) { - GenericValue orderHeader = i.next(); + for(GenericValue orderHeader : orderList) { OrderReadHelper orh = new OrderReadHelper(orderHeader); String orderType = orh.getOrderTypeId(); String orderId = orh.getOrderId(); diff --git a/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java b/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java index 46fae61b48..e65f84c8ba 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java +++ b/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java @@ -214,9 +214,7 @@ public class OrderReadHelper { public Map getReceivedPaymentTotalsByPaymentMethod() { Map paymentMethodAmounts = FastMap.newInstance(); List paymentPrefs = getPaymentPreferences(); - Iterator ppit = paymentPrefs.iterator(); - while (ppit.hasNext()) { - GenericValue paymentPref = ppit.next(); + for(GenericValue paymentPref : paymentPrefs) { List payments = FastList.newInstance(); try { List exprs = UtilMisc.toList(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_RECEIVED"), @@ -234,9 +232,7 @@ public class OrderReadHelper { } BigDecimal chargedToPaymentPref = ZERO; - Iterator payit = payments.iterator(); - while (payit.hasNext()) { - GenericValue payment = payit.next(); + for(GenericValue payment : payments) { if (payment.get("amount") != null) { chargedToPaymentPref = chargedToPaymentPref.add(payment.getBigDecimal("amount")).setScale(scale+1, rounding); } @@ -263,9 +259,7 @@ public class OrderReadHelper { public Map getReturnedTotalsByPaymentMethod() { Map paymentMethodAmounts = FastMap.newInstance(); List paymentPrefs = getPaymentPreferences(); - Iterator ppit = paymentPrefs.iterator(); - while (ppit.hasNext()) { - GenericValue paymentPref = ppit.next(); + for(GenericValue paymentPref : paymentPrefs) { List returnItemResponses = FastList.newInstance(); try { returnItemResponses = orderHeader.getDelegator().findByAnd("ReturnItemResponse", UtilMisc.toMap("orderPaymentPreferenceId", paymentPref.getString("orderPaymentPreferenceId"))); @@ -273,9 +267,7 @@ public class OrderReadHelper { Debug.logError(e, module); } BigDecimal refundedToPaymentPref = ZERO; - Iterator ririt = returnItemResponses.iterator(); - while (ririt.hasNext()) { - GenericValue returnItemResponse = ririt.next(); + for(GenericValue returnItemResponse : returnItemResponses) { refundedToPaymentPref = refundedToPaymentPref.add(returnItemResponse.getBigDecimal("responseAmount")).setScale(scale+1, rounding); } @@ -302,9 +294,7 @@ public class OrderReadHelper { prefs = UtilMisc.toList(orderPaymentPreference); } if (prefs != null) { - Iterator i = prefs.iterator(); - while (i.hasNext()) { - GenericValue payPref = i.next(); + for(GenericValue payPref : prefs) { try { orderPayments.addAll(payPref.getRelated("Payment")); } catch (GenericEntityException e) { @@ -405,9 +395,7 @@ public class OrderReadHelper { } public boolean hasPhysicalProductItems() throws GenericEntityException { - Iterator orderItemIter = this.getOrderItems().iterator(); - while (orderItemIter.hasNext()) { - GenericValue orderItem = orderItemIter.next(); + for(GenericValue orderItem : this.getOrderItems()) { GenericValue product = orderItem.getRelatedOneCache("Product"); if (product != null) { GenericValue productType = product.getRelatedOneCache("ProductType"); @@ -442,9 +430,7 @@ public class OrderReadHelper { List shippingLocations = FastList.newInstance(); List shippingCms = this.getOrderContactMechs("SHIPPING_LOCATION"); if (shippingCms != null) { - Iterator i = shippingCms.iterator(); - while (i.hasNext()) { - GenericValue ocm = i.next(); + for(GenericValue ocm : shippingCms) { if (ocm != null) { try { GenericValue addr = ocm.getDelegator().findByPrimaryKey("PostalAddress", @@ -500,9 +486,7 @@ public class OrderReadHelper { List billingLocations = FastList.newInstance(); List billingCms = this.getOrderContactMechs("BILLING_LOCATION"); if (billingCms != null) { - Iterator i = billingCms.iterator(); - while (i.hasNext()) { - GenericValue ocm = i.next(); + for(GenericValue ocm : billingCms) { if (ocm != null) { try { GenericValue addr = ocm.getDelegator().findByPrimaryKey("PostalAddress", @@ -807,9 +791,7 @@ public class OrderReadHelper { Debug.logError(e, "Unable to get ProductFeatureAppl for item : " + item, module); } if (featureAppls != null) { - Iterator fai = featureAppls.iterator(); - while (fai.hasNext()) { - GenericValue appl = fai.next(); + for(GenericValue appl : featureAppls) { featureSet.add(appl.getString("productFeatureId")); } } @@ -823,9 +805,7 @@ public class OrderReadHelper { Debug.logError(e, "Unable to get OrderAdjustment from item : " + item, module); } if (additionalFeatures != null) { - Iterator afi = additionalFeatures.iterator(); - while (afi.hasNext()) { - GenericValue adj = afi.next(); + for(GenericValue adj : additionalFeatures) { String featureId = adj.getString("productFeatureId"); if (featureId != null) { featureSet.add(featureId); @@ -840,9 +820,7 @@ public class OrderReadHelper { Map featureMap = FastMap.newInstance(); List validItems = getValidOrderItems(shipGroupSeqId); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { List featureAppls = null; if (item.get("productId") != null) { try { @@ -854,9 +832,7 @@ public class OrderReadHelper { Debug.logError(e, "Unable to get ProductFeatureAppl for item : " + item, module); } if (featureAppls != null) { - Iterator fai = featureAppls.iterator(); - while (fai.hasNext()) { - GenericValue appl = fai.next(); + for(GenericValue appl : featureAppls) { BigDecimal lastQuantity = featureMap.get(appl.getString("productFeatureId")); if (lastQuantity == null) { lastQuantity = BigDecimal.ZERO; @@ -875,9 +851,7 @@ public class OrderReadHelper { Debug.logError(e, "Unable to get OrderAdjustment from item : " + item, module); } if (additionalFeatures != null) { - Iterator afi = additionalFeatures.iterator(); - while (afi.hasNext()) { - GenericValue adj = afi.next(); + for(GenericValue adj : additionalFeatures) { String featureId = adj.getString("productFeatureId"); if (featureId != null) { BigDecimal lastQuantity = featureMap.get(featureId); @@ -899,9 +873,7 @@ public class OrderReadHelper { boolean shippingApplies = false; List validItems = this.getValidOrderItems(); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { GenericValue product = null; try { product = item.getRelatedOne("Product"); @@ -923,9 +895,7 @@ public class OrderReadHelper { boolean taxApplies = false; List validItems = this.getValidOrderItems(); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { GenericValue product = null; try { product = item.getRelatedOne("Product"); @@ -947,9 +917,7 @@ public class OrderReadHelper { BigDecimal shippableTotal = ZERO; List validItems = getValidOrderItems(shipGroupSeqId); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { GenericValue product = null; try { product = item.getRelatedOne("Product"); @@ -971,9 +939,7 @@ public class OrderReadHelper { BigDecimal shippableQuantity = ZERO; List shipGroups = getOrderItemShipGroups(); if (UtilValidate.isNotEmpty(shipGroups)) { - Iterator shipGroupsIt = shipGroups.iterator(); - while (shipGroupsIt.hasNext()) { - GenericValue shipGroup = shipGroupsIt.next(); + for(GenericValue shipGroup : shipGroups) { shippableQuantity = shippableQuantity.add(getShippableQuantity(shipGroup.getString("shipGroupSeqId"))); } } @@ -984,9 +950,7 @@ public class OrderReadHelper { BigDecimal shippableQuantity = ZERO; List validItems = getValidOrderItems(shipGroupSeqId); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { GenericValue product = null; try { product = item.getRelatedOne("Product"); @@ -1008,9 +972,7 @@ public class OrderReadHelper { BigDecimal shippableWeight = ZERO; List validItems = getValidOrderItems(shipGroupSeqId); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { shippableWeight = shippableWeight.add(this.getItemWeight(item).multiply(getOrderItemQuantity(item))).setScale(scale, rounding); } } @@ -1062,9 +1024,7 @@ public class OrderReadHelper { List validItems = getValidOrderItems(); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { shippableSizes.add(this.getItemSize(item)); } } @@ -1077,8 +1037,7 @@ public class OrderReadHelper { */ public BigDecimal getOrderPaymentPreferenceTotalByType(String paymentMethodTypeId) { BigDecimal total = ZERO; - for (Iterator iter = getPaymentPreferences().iterator(); iter.hasNext();) { - GenericValue preference = iter.next(); + for(GenericValue preference : getPaymentPreferences()) { if (preference.get("maxAmount") == null) continue; if (paymentMethodTypeId == null || paymentMethodTypeId.equals(preference.get("paymentMethodTypeId"))) { total = total.add(preference.getBigDecimal("maxAmount")).setScale(scale, rounding); @@ -1111,8 +1070,7 @@ public class OrderReadHelper { // get a set of invoice IDs that belong to the order List orderItemBillings = orderHeader.getRelatedCache("OrderItemBilling"); Set invoiceIds = new HashSet(); - for (Iterator iter = orderItemBillings.iterator(); iter.hasNext();) { - GenericValue orderItemBilling = iter.next(); + for(GenericValue orderItemBilling : orderItemBillings) { invoiceIds.add(orderItemBilling.getString("invoiceId")); } @@ -1126,8 +1084,7 @@ public class OrderReadHelper { EntityConditionList ecl = EntityCondition.makeCondition(conditions, EntityOperator.AND); List payments = orderHeader.getDelegator().findList("PaymentAndApplication", ecl, null, null, null, true); - for (Iterator iter = payments.iterator(); iter.hasNext();) { - GenericValue payment = iter.next(); + for (GenericValue payment : payments) { if (payment.get("amountApplied") == null) continue; total = total.add(payment.getBigDecimal("amountApplied")).setScale(scale, rounding); } @@ -1235,9 +1192,7 @@ public class OrderReadHelper { List validItems = getValidOrderItems(shipGroupSeqId); if (validItems != null) { - Iterator i = validItems.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : validItems) { shippableInfo.add(this.getItemInfoMap(item)); } } @@ -1269,10 +1224,8 @@ public class OrderReadHelper { StringBuilder emails = new StringBuilder(); if (orderContactMechs != null) { - Iterator oci = orderContactMechs.iterator(); - while (oci.hasNext()) { + for(GenericValue orderContactMech : orderContactMechs) { try { - GenericValue orderContactMech = oci.next(); GenericValue contactMech = orderContactMech.getRelatedOne("ContactMech"); emails.append(emails.length() > 0 ? "," : "").append(contactMech.getString("infoString")); } catch (GenericEntityException e) { @@ -1301,22 +1254,19 @@ public class OrderReadHelper { List prefs = getPaymentPreferences(); // add up the covered amount, but skip preferences which are declined or cancelled - for (Iterator iter = prefs.iterator(); iter.hasNext();) { - GenericValue pref = iter.next(); + for(GenericValue pref : prefs) { if ("PAYMENT_CANCELLED".equals(pref.get("statusId")) || "PAYMENT_DECLINED".equals(pref.get("statusId"))) { continue; } else if ("PAYMENT_SETTLED".equals(pref.get("statusId"))) { List responses = pref.getRelatedByAnd("PaymentGatewayResponse", UtilMisc.toMap("transCodeEnumId", "PGT_CAPTURE")); - for (Iterator respIter = responses.iterator(); respIter.hasNext();) { - GenericValue response = respIter.next(); + for(GenericValue response : responses) { BigDecimal amount = response.getBigDecimal("amount"); if (amount != null) { openAmount = openAmount.add(amount); } } responses = pref.getRelatedByAnd("PaymentGatewayResponse", UtilMisc.toMap("transCodeEnumId", "PGT_REFUND")); - for (Iterator respIter = responses.iterator(); respIter.hasNext();) { - GenericValue response = respIter.next(); + for(GenericValue response : responses) { BigDecimal amount = response.getBigDecimal("amount"); if (amount != null) { openAmount = openAmount.subtract(amount); @@ -1449,9 +1399,7 @@ public class OrderReadHelper { public boolean getRejectedOrderItems() { List items = getOrderItems(); - Iterator i = items.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : items) { List receipts = null; try { receipts = item.getRelated("ShipmentReceipt"); @@ -1459,9 +1407,7 @@ public class OrderReadHelper { Debug.logWarning(e, module); } if (UtilValidate.isNotEmpty(receipts)) { - Iterator recIter = receipts.iterator(); - while (recIter.hasNext()) { - GenericValue rec = recIter.next(); + for(GenericValue rec : receipts) { BigDecimal rejected = rec.getBigDecimal("quantityRejected"); if (rejected != null && rejected.compareTo(BigDecimal.ZERO) > 0) { return true; @@ -1487,9 +1433,7 @@ public class OrderReadHelper { return false; }*/ List items = getOrderItems(); - Iterator i = items.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : items) { List receipts = null; try { receipts = item.getRelated("ShipmentReceipt"); @@ -1497,9 +1441,7 @@ public class OrderReadHelper { Debug.logWarning(e, module); } if (UtilValidate.isNotEmpty(receipts)) { - Iterator recIter = receipts.iterator(); - while (recIter.hasNext()) { - GenericValue rec = recIter.next(); + for(GenericValue rec : receipts) { BigDecimal acceptedQuantity = rec.getBigDecimal("quantityAccepted"); BigDecimal orderedQuantity = (BigDecimal) item.get("quantity"); if (acceptedQuantity.intValue() != orderedQuantity.intValue() && acceptedQuantity.intValue() > 0) { @@ -1532,9 +1474,7 @@ public class OrderReadHelper { EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_APPROVED"), EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_COMPLETED")); List items = EntityUtil.filterByOr(getOrderItems(), exprs); - Iterator i = items.iterator(); - while (i.hasNext()) { - GenericValue item = i.next(); + for(GenericValue item : items) { if (item.get("productId") != null) { GenericValue product = null; try { @@ -1580,9 +1520,7 @@ public class OrderReadHelper { if (UtilValidate.isNotEmpty(productContents)) { // make sure we are still within the allowed timeframe and use limits - Iterator pci = productContents.iterator(); - while (pci.hasNext()) { - GenericValue productContent = pci.next(); + for(GenericValue productContent : productContents) { Timestamp fromDate = productContent.getTimestamp("purchaseFromDate"); Timestamp thruDate = productContent.getTimestamp("purchaseThruDate"); if (fromDate == null || item.getTimestamp("orderDate").after(fromDate)) { @@ -1742,8 +1680,7 @@ public class OrderReadHelper { // since we don't have a handy grouped view entity, we'll have to group the return items by hand Map returnMap = FastMap.newInstance(); - for (Iterator iter = this.getValidOrderItems().iterator(); iter.hasNext();) { - GenericValue orderItem = iter.next(); + for(GenericValue orderItem : this.getValidOrderItems()) { List group = EntityUtil.filterByAnd(returnItems, UtilMisc.toList( EntityCondition.makeCondition("orderId", orderItem.get("orderId")), EntityCondition.makeCondition("orderItemSeqId", orderItem.get("orderItemSeqId")), @@ -1751,8 +1688,7 @@ public class OrderReadHelper { // add up the returned quantities for this group TODO: received quantity should be used eventually BigDecimal returned = BigDecimal.ZERO; - for (Iterator groupiter = group.iterator(); groupiter.hasNext();) { - GenericValue returnItem = groupiter.next(); + for(GenericValue returnItem : group) { if (returnItem.getBigDecimal("returnQuantity") != null) { returned = returned.add(returnItem.getBigDecimal("returnQuantity")); } @@ -1788,9 +1724,7 @@ public class OrderReadHelper { returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_COMPLETED"))); BigDecimal returnedQuantity = ZERO; - Iterator i = returnedItems.iterator(); - while (i.hasNext()) { - GenericValue returnedItem = i.next(); + for(GenericValue returnedItem : returnedItems) { if (returnedItem.get("returnQuantity") != null) { returnedQuantity = returnedQuantity.add(returnedItem.getBigDecimal("returnQuantity")).setScale(scale, rounding); } @@ -1821,11 +1755,9 @@ public class OrderReadHelper { UtilMisc.toList(EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "RETURN_CANCELLED")))); } BigDecimal returnedAmount = ZERO; - Iterator i = returnedItems.iterator(); String orderId = orderHeader.getString("orderId"); List returnHeaderList = FastList.newInstance(); - while (i.hasNext()) { - GenericValue returnedItem = i.next(); + for(GenericValue returnedItem : returnedItems) { if ((returnedItem.get("returnPrice") != null) && (returnedItem.get("returnQuantity") != null)) { returnedAmount = returnedAmount.add(returnedItem.getBigDecimal("returnPrice").multiply(returnedItem.getBigDecimal("returnQuantity")).setScale(scale, rounding)); } @@ -1836,9 +1768,7 @@ public class OrderReadHelper { } } //get returnedAmount from returnHeader adjustments whose orderId must equals to current orderHeader.orderId - Iterator returnHeaderIterator = returnHeaderList.iterator(); - while (returnHeaderIterator.hasNext()) { - String returnId = returnHeaderIterator.next(); + for(String returnId : returnHeaderList) { Map returnHeaderAdjFilter = UtilMisc.toMap("returnId", returnId, "returnItemSeqId", "_NA_", "returnTypeId", returnTypeId); returnedAmount =returnedAmount.add(getReturnAdjustmentTotal(orderHeader.getDelegator(), returnHeaderAdjFilter)).setScale(scale, rounding); } @@ -1878,9 +1808,7 @@ public class OrderReadHelper { returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_COMPLETED"))); Map itemReturnedQuantities = FastMap.newInstance(); - Iterator i = returnedItems.iterator(); - while (i.hasNext()) { - GenericValue returnedItem = i.next(); + for(GenericValue returnedItem : returnedItems) { String orderItemSeqId = returnedItem.getString("orderItemSeqId"); BigDecimal returnedQuantity = returnedItem.getBigDecimal("returnQuantity"); if (orderItemSeqId != null && returnedQuantity != null) { @@ -1898,10 +1826,7 @@ public class OrderReadHelper { BigDecimal totalTaxNotReturned = ZERO; BigDecimal totalShippingNotReturned = ZERO; - Iterator orderItems = this.getValidOrderItems().iterator(); - while (orderItems.hasNext()) { - GenericValue orderItem = orderItems.next(); - + for(GenericValue orderItem : this.getValidOrderItems()) { BigDecimal itemQuantityDbl = orderItem.getBigDecimal("quantity"); if (itemQuantityDbl == null || itemQuantityDbl.compareTo(ZERO) == 0) { continue; @@ -1960,8 +1885,7 @@ public class OrderReadHelper { // sum up the return items that have a return item response with a billing account defined try { - for (Iterator iter = returnedItems.iterator(); iter.hasNext();) { - GenericValue returnItem = iter.next(); + for(GenericValue returnItem : returnedItems) { GenericValue returnItemResponse = returnItem.getRelatedOne("ReturnItemResponse"); if (returnItemResponse == null) continue; if (returnItemResponse.get("billingAccountId") == null) continue; @@ -1999,14 +1923,10 @@ public class OrderReadHelper { BigDecimal backorder = ZERO; List items = this.getValidOrderItems(); if (items != null) { - Iterator ii = items.iterator(); - while (ii.hasNext()) { - GenericValue item = ii.next(); + for(GenericValue item : items) { List reses = this.getOrderItemShipGrpInvResList(item); if (reses != null) { - Iterator ri = reses.iterator(); - while (ri.hasNext()) { - GenericValue res = ri.next(); + for(GenericValue res : reses) { BigDecimal nav = res.getBigDecimal("quantityNotAvailable"); if (nav != null) { backorder = backorder.add(nav).setScale(scale, rounding); @@ -2035,9 +1955,7 @@ public class OrderReadHelper { } if (picked != null) { - Iterator i = picked.iterator(); - while (i.hasNext()) { - GenericValue pickedItem = i.next(); + for(GenericValue pickedItem : picked) { BigDecimal issueQty = pickedItem.getBigDecimal("quantity"); if (issueQty != null) { quantityPicked = quantityPicked.add(issueQty).setScale(scale, rounding); @@ -2051,9 +1969,7 @@ public class OrderReadHelper { BigDecimal quantityShipped = ZERO; List issuance = getOrderItemIssuances(orderItem); if (issuance != null) { - Iterator i = issuance.iterator(); - while (i.hasNext()) { - GenericValue issue = i.next(); + for(GenericValue issue : issuance) { BigDecimal issueQty = issue.getBigDecimal("quantity"); BigDecimal cancelQty = issue.getBigDecimal("cancelQuantity"); if (cancelQty == null) { @@ -2073,9 +1989,7 @@ public class OrderReadHelper { List reses = getOrderItemShipGrpInvResList(orderItem); if (reses != null) { - Iterator i = reses.iterator(); - while (i.hasNext()) { - GenericValue res = i.next(); + for(GenericValue res : reses) { BigDecimal quantity = res.getBigDecimal("quantity"); if (quantity != null) { reserved = reserved.add(quantity).setScale(scale, rounding); @@ -2093,9 +2007,7 @@ public class OrderReadHelper { List reses = getOrderItemShipGrpInvResList(orderItem); if (reses != null) { - Iterator i = reses.iterator(); - while (i.hasNext()) { - GenericValue res = i.next(); + for(GenericValue res : reses) { Timestamp promised = res.getTimestamp("currentPromisedDate"); if (promised == null) { promised = res.getTimestamp("promisedDatetime"); @@ -2414,11 +2326,7 @@ public class OrderReadHelper { if (UtilValidate.isNotEmpty(orderHeaderAdjustments)) { List filteredAdjs = filterOrderAdjustments(orderHeaderAdjustments, includeOther, includeTax, includeShipping, false, false); - Iterator adjIt = filteredAdjs.iterator(); - - while (adjIt.hasNext()) { - GenericValue orderAdjustment = adjIt.next(); - + for (GenericValue orderAdjustment : filteredAdjs) { adjTotal = adjTotal.add(OrderReadHelper.calcOrderAdjustment(orderAdjustment, subTotal)).setScale(scale, rounding); } } @@ -2449,17 +2357,12 @@ public class OrderReadHelper { public static BigDecimal getOrderItemsSubTotal(List orderItems, List adjustments, List workEfforts) { BigDecimal result = ZERO; - Iterator itemIter = UtilMisc.toIterator(orderItems); - - while (itemIter != null && itemIter.hasNext()) { - GenericValue orderItem = itemIter.next(); + for(GenericValue orderItem : orderItems) { BigDecimal itemTotal = getOrderItemSubTotal(orderItem, adjustments); // Debug.logInfo("Item : " + orderItem.getString("orderId") + " / " + orderItem.getString("orderItemSeqId") + " = " + itemTotal, module); if (workEfforts != null && orderItem.getString("orderItemTypeId").compareTo("RENTAL_ORDER_ITEM") == 0) { - Iterator weIter = UtilMisc.toIterator(workEfforts); - while (weIter != null && weIter.hasNext()) { - GenericValue workEffort = weIter.next(); + for(GenericValue workEffort : workEfforts) { if (workEffort.getString("workEffortId").compareTo(orderItem.getString("orderItemSeqId")) == 0) { itemTotal = itemTotal.multiply(getWorkEffortRentalQuantity(workEffort)).setScale(scale, rounding); break; @@ -2519,10 +2422,8 @@ public class OrderReadHelper { public static BigDecimal getOrderItemsTotal(List orderItems, List adjustments) { BigDecimal result = ZERO; - Iterator itemIter = UtilMisc.toIterator(orderItems); - - while (itemIter != null && itemIter.hasNext()) { - result = result.add(getOrderItemTotal(itemIter.next(), adjustments)); + for(GenericValue orderItem : orderItems) { + result = result.add(getOrderItemTotal(orderItem, adjustments)); } return result.setScale(scale, rounding); } @@ -2538,9 +2439,7 @@ public class OrderReadHelper { List promoAdjustments = EntityUtil.filterByAnd(allOrderAdjustments, UtilMisc.toMap("orderAdjustmentTypeId", "PROMOTION_ADJUSTMENT")); if (UtilValidate.isNotEmpty(promoAdjustments)) { - Iterator promoAdjIter = promoAdjustments.iterator(); - while (promoAdjIter.hasNext()) { - GenericValue promoAdjustment = promoAdjIter.next(); + for(GenericValue promoAdjustment : promoAdjustments) { if (promoAdjustment != null) { BigDecimal amount = promoAdjustment.getBigDecimal("amount").setScale(taxCalcScale, taxRounding); promoAdjTotal = promoAdjTotal.add(amount); @@ -2593,10 +2492,8 @@ public class OrderReadHelper { public static BigDecimal getAllOrderItemsAdjustmentsTotal(List orderItems, List adjustments, boolean includeOther, boolean includeTax, boolean includeShipping) { BigDecimal result = ZERO; - Iterator itemIter = UtilMisc.toIterator(orderItems); - - while (itemIter != null && itemIter.hasNext()) { - result = result.add(getOrderItemAdjustmentsTotal(itemIter.next(), adjustments, includeOther, includeTax, includeShipping)); + for(GenericValue orderItem : orderItems) { + result = result.add(getOrderItemAdjustmentsTotal(orderItem, adjustments, includeOther, includeTax, includeShipping)); } return result.setScale(scale, rounding); } @@ -2636,11 +2533,7 @@ public class OrderReadHelper { if (UtilValidate.isNotEmpty(adjustments)) { List filteredAdjs = filterOrderAdjustments(adjustments, includeOther, includeTax, includeShipping, forTax, forShipping); - Iterator adjIt = filteredAdjs.iterator(); - - while (adjIt.hasNext()) { - GenericValue orderAdjustment = adjIt.next(); - + for(GenericValue orderAdjustment : filteredAdjs) { adjTotal = adjTotal.add(OrderReadHelper.calcItemAdjustment(orderAdjustment, quantity, unitPrice)); } } @@ -2652,11 +2545,7 @@ public class OrderReadHelper { if (UtilValidate.isNotEmpty(adjustments)) { List filteredAdjs = filterOrderAdjustments(adjustments, includeOther, includeTax, includeShipping, forTax, forShipping); - Iterator adjIt = filteredAdjs.iterator(); - - while (adjIt.hasNext()) { - GenericValue orderAdjustment = adjIt.next(); - + for(GenericValue orderAdjustment : filteredAdjs) { adjTotal = adjTotal.add(OrderReadHelper.calcItemAdjustmentRecurringBd(orderAdjustment, quantity, unitPrice)).setScale(scale, rounding); } } @@ -2693,11 +2582,7 @@ public class OrderReadHelper { List newOrderAdjustmentsList = FastList.newInstance(); if (UtilValidate.isNotEmpty(adjustments)) { - Iterator adjIt = adjustments.iterator(); - - while (adjIt.hasNext()) { - GenericValue orderAdjustment = adjIt.next(); - + for(GenericValue orderAdjustment : newOrderAdjustmentsList) { boolean includeAdjustment = false; if ("SALES_TAX".equals(orderAdjustment.getString("orderAdjustmentTypeId")) || @@ -2746,9 +2631,7 @@ public class OrderReadHelper { } if (UtilValidate.isNotEmpty(openOrders)) { - Iterator i = openOrders.iterator(); - while (i.hasNext()) { - GenericValue order = i.next(); + for(GenericValue order : openOrders) { BigDecimal thisQty = order.getBigDecimal("quantity"); if (thisQty == null) { thisQty = BigDecimal.ZERO; @@ -2802,9 +2685,7 @@ public class OrderReadHelper { List orderHeaderAdjustments = this.getOrderHeaderAdjustments(); List filteredAdjustments = FastList.newInstance(); if (orderHeaderAdjustments != null) { - Iterator orderAdjIterator = orderHeaderAdjustments.iterator(); - while (orderAdjIterator.hasNext()) { - GenericValue orderAdjustment = orderAdjIterator.next(); + for(GenericValue orderAdjustment : orderHeaderAdjustments) { long count = 0; try { count = orderHeader.getDelegator().findCountByCondition("ReturnAdjustment", EntityCondition.makeCondition("orderAdjustmentId", EntityOperator.EQUALS, orderAdjustment.get("orderAdjustmentId")), null, null); @@ -2832,9 +2713,7 @@ public class OrderReadHelper { // TODO: find on a view-entity with a sum is probably more efficient adjustments = delegator.findByAnd("ReturnAdjustment", condition); if (adjustments != null) { - Iterator adjustmentIterator = adjustments.iterator(); - while (adjustmentIterator.hasNext()) { - GenericValue returnAdjustment = adjustmentIterator.next(); + for(GenericValue returnAdjustment : adjustments) { total = total.add(setScaleByType("RET_SALES_TAX_ADJ".equals(returnAdjustment.get("returnAdjustmentTypeId")),returnAdjustment.getBigDecimal("amount"))); } } @@ -2855,8 +2734,7 @@ public class OrderReadHelper { try { // this is simply the sum of quantity billed in all related OrderItemBillings List billings = orderItem.getRelated("OrderItemBilling"); - for (Iterator iter = billings.iterator(); iter.hasNext();) { - GenericValue billing = iter.next(); + for(GenericValue billing : billings) { BigDecimal quantity = billing.getBigDecimal("quantity"); if (quantity != null) { invoiced = invoiced.add(quantity); diff --git a/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java b/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java index f925dce745..2a886cd0db 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java +++ b/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java @@ -429,9 +429,7 @@ public class OrderReturnServices { returnableQuantity = orderQty; } else { BigDecimal returnedQty = BigDecimal.ZERO; - Iterator ri = returnedItems.iterator(); - while (ri.hasNext()) { - GenericValue returnItem = ri.next(); + for(GenericValue returnItem : returnedItems) { GenericValue returnHeader = null; try { returnHeader = returnItem.getRelatedOne("ReturnHeader"); @@ -498,9 +496,7 @@ public class OrderReturnServices { } if (orderItemQuantitiesIssued != null) { - Iterator i = orderItemQuantitiesIssued.iterator(); - while (i.hasNext()) { - GenericValue orderItemQuantityIssued = i.next(); + for(GenericValue orderItemQuantityIssued : orderItemQuantitiesIssued) { GenericValue item = null; try { item = orderItemQuantityIssued.getRelatedOne("OrderItem"); @@ -578,9 +574,7 @@ public class OrderReturnServices { "OrderErrorUnableToGetOrderAdjustmentsFromItem", locale)); } if (UtilValidate.isNotEmpty(itemAdjustments)) { - Iterator itemAdjustmentsIt = itemAdjustments.iterator(); - while (itemAdjustmentsIt.hasNext()) { - GenericValue itemAdjustment = itemAdjustmentsIt.next(); + for(GenericValue itemAdjustment : itemAdjustments) { returnInfo = FastMap.newInstance(); returnInfo.put("returnableQuantity", BigDecimal.ONE); // TODO: the returnablePrice should be set to the amount minus the already returned amount @@ -637,9 +631,7 @@ public class OrderReturnServices { List completedItems = FastList.newInstance(); if (returnHeader != null && UtilValidate.isNotEmpty(returnItems)) { - Iterator itemsIter = returnItems.iterator(); - while (itemsIter.hasNext()) { - GenericValue item = itemsIter.next(); + for(GenericValue item : returnItems) { String itemStatus = item != null ? item.getString("statusId") : null; if (itemStatus != null) { // both completed and cancelled items qualify for completed status change @@ -782,9 +774,8 @@ public class OrderReturnServices { billingAccounts = EntityUtil.filterByDate(billingAccounts); billingAccounts = EntityUtil.orderBy(billingAccounts, UtilMisc.toList("-fromDate")); if (UtilValidate.isNotEmpty(billingAccounts)) { - ListIterator billingAccountItr = billingAccounts.listIterator(); - while (billingAccountItr.hasNext() && billingAccountId == null) { - String thisBillingAccountId = billingAccountItr.next().getString("billingAccountId"); + for(GenericValue billingAccount : billingAccounts) { + String thisBillingAccountId = billingAccount.getString("billingAccountId"); BigDecimal billingAccountBalance = ZERO; try { billingAccountBalance = getBillingAccountBalance(thisBillingAccountId, dctx); @@ -881,8 +872,7 @@ public class OrderReturnServices { // first, compute the total credit from the return items BigDecimal creditTotal = ZERO; - for (Iterator itemsIter = returnItems.iterator(); itemsIter.hasNext();) { - GenericValue item = itemsIter.next(); + for(GenericValue item : returnItems) { BigDecimal quantity = item.getBigDecimal("returnQuantity"); BigDecimal price = item.getBigDecimal("returnPrice"); if (quantity == null) quantity = ZERO; @@ -962,8 +952,7 @@ public class OrderReturnServices { String itemResponseId = (String) serviceResults.get("returnItemResponseId"); // loop through the items again to update them and store a status change history - for (Iterator itemsIter = returnItems.iterator(); itemsIter.hasNext();) { - GenericValue item = itemsIter.next(); + for(GenericValue item : returnItems) { Map returnItemMap = UtilMisc.toMap("returnItemResponseId", itemResponseId, "returnId", item.get("returnId"), "returnItemSeqId", item.get("returnItemSeqId"), "statusId", "RETURN_COMPLETED", "userLogin", userLogin); // store the item changes (attached responseId) try { @@ -1040,16 +1029,14 @@ public class OrderReturnServices { ), EntityOperator.AND); List orderPaymentPreferenceSums = delegator.findList("OrderPurchasePaymentSummary", whereConditions, UtilMisc.toSet("maxAmount"), null, null, false); - for (Iterator oppsi = orderPaymentPreferenceSums.iterator(); oppsi.hasNext();) { - GenericValue orderPaymentPreferenceSum = oppsi.next(); + for(GenericValue orderPaymentPreferenceSum : orderPaymentPreferenceSums) { BigDecimal maxAmount = orderPaymentPreferenceSum.getBigDecimal("maxAmount"); balance = maxAmount != null ? balance.subtract(maxAmount) : balance; } List paymentAppls = delegator.findByAnd("PaymentApplication", UtilMisc.toMap("billingAccountId", billingAccountId)); // TODO: cancelled payments? - for (Iterator pAi = paymentAppls.iterator(); pAi.hasNext();) { - GenericValue paymentAppl = pAi.next(); + for(GenericValue paymentAppl : paymentAppls) { if (paymentAppl.getString("invoiceId") == null) { BigDecimal amountApplied = paymentAppl.getBigDecimal("amountApplied"); balance = balance.add(amountApplied); @@ -1087,8 +1074,7 @@ public class OrderReturnServices { // find the minimum storeCreditValidDays of all the ProductStores associated with all the Orders on the Return, skipping null ones Long storeCreditValidDays = null; - for (Iterator iter = productStores.iterator(); iter.hasNext();) { - GenericValue productStore = iter.next(); + for(GenericValue productStore : productStores) { Long thisStoreValidDays = productStore.getLong("storeCreditValidDays"); if (thisStoreValidDays == null) continue; @@ -1314,9 +1300,7 @@ public class OrderReturnServices { * the intent is to get the refundable amounts per orderPaymentPreference, grouped by payment method type. */ Map>> prefSplitMap = FastMap.newInstance(); - Iterator oppit = orderPayPrefs.iterator(); - while (oppit.hasNext()) { - GenericValue orderPayPref = oppit.next(); + for(GenericValue orderPayPref : orderPayPrefs) { String paymentMethodTypeId = orderPayPref.getString("paymentMethodTypeId"); String orderPayPrefKey = orderPayPref.getString("paymentMethodId") != null ? orderPayPref.getString("paymentMethodId") : orderPayPref.getString("paymentMethodTypeId"); @@ -1484,10 +1468,7 @@ public class OrderReturnServices { String responseId = (String) serviceResults.get("returnItemResponseId"); // Set the response on each item - Iterator itemsIter = items.iterator(); - while (itemsIter.hasNext()) { - GenericValue item = itemsIter.next(); - + for(GenericValue item : items) { Map returnItemMap = UtilMisc.toMap("returnItemResponseId", responseId, "returnId", item.get("returnId"), "returnItemSeqId", item.get("returnItemSeqId"), "statusId", returnItemStatusId, "userLogin", userLogin); //Debug.logInfo("Updating item status", module); try { @@ -1647,11 +1628,9 @@ public class OrderReturnServices { // for each return item in the response, get the list of return item billings and then a list of invoices Map returnInvoices = FastMap.newInstance(); // key is invoiceId, value is Invoice GenericValue List items = response.getRelated("ReturnItem"); - for (Iterator itemIter = items.iterator(); itemIter.hasNext();) { - GenericValue item = itemIter.next(); + for (GenericValue item : items) { List billings = item.getRelated("ReturnItemBilling"); - for (Iterator billIter = billings.iterator(); billIter.hasNext();) { - GenericValue billing = billIter.next(); + for (GenericValue billing : billings) { GenericValue invoice = billing.getRelatedOne("Invoice"); // put the invoice in the map if it doesn't already exist (a very loopy way of doing group by invoiceId without creating a view) @@ -1664,13 +1643,10 @@ public class OrderReturnServices { // for each return invoice found, sum up the related billings Map invoiceTotals = FastMap.newInstance(); // key is invoiceId, value is the sum of all billings for that invoice BigDecimal grandTotal = ZERO; // The sum of all return invoice totals - for (Iterator iter = returnInvoices.values().iterator(); iter.hasNext();) { - GenericValue invoice = iter.next(); - + for (GenericValue invoice : returnInvoices.values()) { List billings = invoice.getRelated("ReturnItemBilling"); BigDecimal runningTotal = ZERO; - for (Iterator billIter = billings.iterator(); billIter.hasNext();) { - GenericValue billing = billIter.next(); + for (GenericValue billing : billings) { runningTotal = runningTotal.add(billing.getBigDecimal("amount").multiply(billing.getBigDecimal("quantity")).setScale(decimals, rounding)); } @@ -1679,8 +1655,7 @@ public class OrderReturnServices { } // now allocate responseAmount * invoiceTotal / grandTotal to each invoice - for (Iterator iter = returnInvoices.values().iterator(); iter.hasNext();) { - GenericValue invoice = iter.next(); + for (GenericValue invoice : returnInvoices.values()) { String invoiceId = invoice.getString("invoiceId"); BigDecimal invoiceTotal = invoiceTotals.get(invoiceId); @@ -1793,9 +1768,7 @@ public class OrderReturnServices { Debug.logError(e, module); } if (orderCm != null) { - Iterator orderCmi = orderCm.iterator(); - while (orderCmi.hasNext()) { - GenericValue v = orderCmi.next(); + for(GenericValue v : orderCm) { contactMechs.add(GenericValue.create(v)); } orderMap.put("orderContactMechs", contactMechs); @@ -1829,10 +1802,8 @@ public class OrderReturnServices { List orderItemShipGroupIds = FastList.newInstance(); // this is used to store the ship group ids of the groups already added to the orderItemShipGroupInfo list List orderItemAssocs = FastList.newInstance(); if (returnItemList != null) { - Iterator returnItemIter = returnItemList.iterator(); int itemCount = 1; - while (returnItemIter.hasNext()) { - GenericValue returnItem = returnItemIter.next(); + for(GenericValue returnItem : returnItemList) { GenericValue orderItem = null; GenericValue product = null; try { @@ -1946,9 +1917,7 @@ public class OrderReturnServices { continue; } if (UtilValidate.isNotEmpty(repairItems)) { - Iterator repairItemIt = repairItems.iterator(); - while (repairItemIt.hasNext()) { - GenericValue repairItem = repairItemIt.next(); + for(GenericValue repairItem : repairItems) { GenericValue repairItemProduct = null; try { repairItemProduct = repairItem.getRelatedOne("AssocProduct"); @@ -2094,9 +2063,7 @@ public class OrderReturnServices { List orderRoles = orderHeader.getRelated("OrderRole"); Map> orderRolesMap = FastMap.newInstance(); if (orderRoles != null) { - Iterator orderRolesIt = orderRoles.iterator(); - while (orderRolesIt.hasNext()) { - GenericValue orderRole = orderRolesIt.next(); + for(GenericValue orderRole : orderRoles) { List parties = orderRolesMap.get(orderRole.getString("roleTypeId")); if (parties == null) { parties = FastList.newInstance(); @@ -2173,9 +2140,7 @@ public class OrderReturnServices { "OrderProblemCreatingReturnItemResponseRecord", locale)); } - Iterator updateReturnItemIter = returnItemList.iterator(); - while (updateReturnItemIter.hasNext()) { - GenericValue returnItem = updateReturnItemIter.next(); + for(GenericValue returnItem : returnItemList) { Map updateReturnItemCtx = FastMap.newInstance(); updateReturnItemCtx.put("returnId", returnId); updateReturnItemCtx.put("returnItemSeqId", returnItem.get("returnItemSeqId")); @@ -2233,9 +2198,7 @@ public class OrderReturnServices { } if (returnItems != null) { - Iterator ri = returnItems.iterator(); - while (ri.hasNext()) { - GenericValue returnItem = ri.next(); + for(GenericValue returnItem : returnItems) { String orderItemSeqId = returnItem.getString("orderItemSeqId"); String orderId = returnItem.getString("orderId"); @@ -2250,9 +2213,7 @@ public class OrderReturnServices { // cancel all current subscriptions if (subscriptions != null) { - Iterator si = subscriptions.iterator(); - while (si.hasNext()) { - GenericValue subscription = si.next(); + for(GenericValue subscription : subscriptions) { Timestamp thruDate = subscription.getTimestamp("thruDate"); if (thruDate == null || thruDate.after(now)) { subscription.set("thruDate", now); @@ -2281,9 +2242,7 @@ public class OrderReturnServices { * @param returnTypeId the return type id */ public static void groupReturnItemsByOrder(List returnItems, Map> returnItemsByOrderId, Map totalByOrder, Delegator delegator, String returnId, String returnTypeId) { - Iterator itemIt = returnItems.iterator(); - while (itemIt.hasNext()) { - GenericValue returnItem = itemIt.next(); + for(GenericValue returnItem : returnItems) { String orderId = returnItem.getString("orderId"); if (orderId != null) { if (returnItemsByOrderId != null) { @@ -2326,9 +2285,7 @@ public class OrderReturnServices { // We may also have some order-level adjustments, so we need to go through each order again and add those as well if ((totalByOrder != null) && (totalByOrder.keySet() != null)) { - Iterator orderIterator = totalByOrder.keySet().iterator(); - while (orderIterator.hasNext()) { - String orderId = orderIterator.next(); + for(String orderId : totalByOrder.keySet()) { // find returnAdjustment for returnHeader Map condition = UtilMisc.toMap("returnId", returnId, "returnItemSeqId", org.ofbiz.common.DataModelConstants.SEQ_ID_NA, @@ -2355,20 +2312,14 @@ public class OrderReturnServices { "OrderErrorGettingReturnHeaderItemInformation", locale)); } if ((returnItems != null) && (returnItems.size() > 0)) { - Iterator returnItemIterator = returnItems.iterator(); - GenericValue returnItem = null; - GenericValue returnItemResponse = null; - GenericValue payment = null; - String orderId; List paymentList = FastList.newInstance(); - while (returnItemIterator.hasNext()) { - returnItem = returnItemIterator.next(); - orderId = returnItem.getString("orderId"); + for(GenericValue returnItem : returnItems) { + String orderId = returnItem.getString("orderId"); try { - returnItemResponse = returnItem.getRelatedOne("ReturnItemResponse"); + GenericValue returnItemResponse = returnItem.getRelatedOne("ReturnItemResponse"); if ((returnItemResponse != null) && (orderId != null)) { // TODO should we filter on payment's status (PMNT_SENT,PMNT_RECEIVED) - payment = returnItemResponse.getRelatedOne("Payment"); + GenericValue payment = returnItemResponse.getRelatedOne("Payment"); if ((payment != null) && (payment.getBigDecimal("amount") != null) && !paymentList.contains(payment.get("paymentId"))) { UtilMisc.addToBigDecimalInMap(returnAmountByOrder, orderId, payment.getBigDecimal("amount")); @@ -2407,9 +2358,7 @@ public class OrderReturnServices { } if ((returnAmountByOrder != null) && (returnAmountByOrder.keySet() != null)) { - Iterator orderIterator = returnAmountByOrder.keySet().iterator(); - while (orderIterator.hasNext()) { - String orderId = orderIterator.next(); + for(String orderId : returnAmountByOrder.keySet()) { BigDecimal returnAmount = returnAmountByOrder.get(orderId); if (returnAmount.abs().compareTo(new BigDecimal("0.000001")) < 0) { Debug.logError("Order [" + orderId + "] refund amount[ " + returnAmount + "] less than zero", module); @@ -2662,9 +2611,7 @@ public class OrderReturnServices { // TODO: find on a view-entity with a sum is probably more efficient adjustments = delegator.findByAnd("ReturnAdjustment", condition); if (adjustments != null) { - Iterator adjustmentIterator = adjustments.iterator(); - while (adjustmentIterator.hasNext()) { - GenericValue returnAdjustment = adjustmentIterator.next(); + for(GenericValue returnAdjustment : adjustments) { if ((returnAdjustment != null) && (returnAdjustment.get("amount") != null)) { total = total.add(returnAdjustment.getBigDecimal("amount")); } diff --git a/applications/order/src/org/ofbiz/order/order/OrderServices.java b/applications/order/src/org/ofbiz/order/order/OrderServices.java index d445b907e2..a1aaea72b5 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderServices.java +++ b/applications/order/src/org/ofbiz/order/order/OrderServices.java @@ -925,11 +925,10 @@ public class OrderServices { Set orderProductPromoCodes = UtilGenerics.checkSet(context.get("orderProductPromoCodes")); if (UtilValidate.isNotEmpty(orderProductPromoCodes)) { GenericValue orderProductPromoCode = delegator.makeValue("OrderProductPromoCode"); - Iterator orderProductPromoCodeIter = orderProductPromoCodes.iterator(); - while (orderProductPromoCodeIter.hasNext()) { + for(String productPromoCodeId : orderProductPromoCodes) { orderProductPromoCode.clear(); orderProductPromoCode.set("orderId", orderId); - orderProductPromoCode.set("productPromoCodeId", orderProductPromoCodeIter.next()); + orderProductPromoCode.set("productPromoCodeId", productPromoCodeId); toBeStored.add(orderProductPromoCode); } } @@ -4891,8 +4890,7 @@ public class OrderServices { // the original method did a "\d+" regexp to decide which is the case, this version is more explicit with its lookup of PaymentMethodType if (checkOutPaymentId != null) { List paymentMethodTypes = delegator.findList("PaymentMethodType", null, null, null, null, true); - for (Iterator iter = paymentMethodTypes.iterator(); iter.hasNext();) { - GenericValue type = iter.next(); + for (GenericValue type : paymentMethodTypes) { if (type.get("paymentMethodTypeId").equals(checkOutPaymentId)) { paymentMethodTypeId = (String) type.get("paymentMethodTypeId"); break; diff --git a/applications/order/src/org/ofbiz/order/quote/QuoteServices.java b/applications/order/src/org/ofbiz/order/quote/QuoteServices.java index 3431f2fa9b..6ea79390a0 100644 --- a/applications/order/src/org/ofbiz/order/quote/QuoteServices.java +++ b/applications/order/src/org/ofbiz/order/quote/QuoteServices.java @@ -19,7 +19,6 @@ package org.ofbiz.order.quote; import java.sql.Timestamp; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -192,9 +191,7 @@ public class QuoteServices { // create Quote Items if (UtilValidate.isNotEmpty(quoteItems)) { - Iterator quoteIt = quoteItems.iterator(); - while (quoteIt.hasNext()) { - GenericValue quoteItem = quoteIt.next(); + for(GenericValue quoteItem : quoteItems) { quoteItem.set("quoteId", quoteId); Map quoteItemIn = quoteItem.getAllFields(); quoteItemIn.put("userLogin", userLogin); @@ -205,9 +202,7 @@ public class QuoteServices { // create Quote Attributes if (UtilValidate.isNotEmpty(quoteAttributes)) { - Iterator quoteAttrIt = quoteAttributes.iterator(); - while (quoteAttrIt.hasNext()) { - GenericValue quoteAttr = quoteAttrIt.next(); + for(GenericValue quoteAttr : quoteAttributes) { quoteAttr.set("quoteId", quoteId); Map quoteAttrIn = quoteAttr.getAllFields(); quoteAttrIn.put("userLogin", userLogin); @@ -218,9 +213,7 @@ public class QuoteServices { // create Quote Coefficients if (UtilValidate.isNotEmpty(quoteCoefficients)) { - Iterator quoteCoefficientIt = quoteCoefficients.iterator(); - while (quoteCoefficientIt.hasNext()) { - GenericValue quoteCoefficient = quoteCoefficientIt.next(); + for(GenericValue quoteCoefficient : quoteCoefficients) { quoteCoefficient.set("quoteId", quoteId); Map quoteCoefficientIn = quoteCoefficient.getAllFields(); quoteCoefficientIn.put("userLogin", userLogin); @@ -231,9 +224,7 @@ public class QuoteServices { // create Quote Roles if (UtilValidate.isNotEmpty(quoteRoles)) { - Iterator quoteRoleIt = quoteRoles.iterator(); - while (quoteRoleIt.hasNext()) { - GenericValue quoteRole = quoteRoleIt.next(); + for(GenericValue quoteRole : quoteRoles) { quoteRole.set("quoteId", quoteId); Map quoteRoleIn = quoteRole.getAllFields(); quoteRoleIn.put("userLogin", userLogin); @@ -244,9 +235,7 @@ public class QuoteServices { // create Quote WorkEfforts if (UtilValidate.isNotEmpty(quoteWorkEfforts)) { - Iterator quoteWorkEffortIt = quoteWorkEfforts.iterator(); - while (quoteWorkEffortIt.hasNext()) { - GenericValue quoteWorkEffort = quoteWorkEffortIt.next(); + for(GenericValue quoteWorkEffort : quoteWorkEfforts) { quoteWorkEffort.set("quoteId", quoteId); Map quoteWorkEffortIn = quoteWorkEffort.getAllFields(); quoteWorkEffortIn.put("userLogin", userLogin); @@ -257,9 +246,7 @@ public class QuoteServices { // create Quote Adjustments if (UtilValidate.isNotEmpty(quoteAdjustments)) { - Iterator quoteAdjustmentIt = quoteAdjustments.iterator(); - while (quoteAdjustmentIt.hasNext()) { - GenericValue quoteAdjustment = quoteAdjustmentIt.next(); + for(GenericValue quoteAdjustment : quoteAdjustments) { quoteAdjustment.set("quoteId", quoteId); Map quoteAdjustmentIn = quoteAdjustment.getAllFields(); quoteAdjustmentIn.put("userLogin", userLogin); diff --git a/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java b/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java index f4410b2e5a..32304b6541 100644 --- a/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java +++ b/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java @@ -99,9 +99,8 @@ public class RequirementServices { // join in fields with extra data about the suppliers and products List> requirements = FastList.newInstance(); - for (Iterator iter = requirementAndRoles.iterator(); iter.hasNext();) { + for(GenericValue requirement : requirementAndRoles) { Map union = FastMap.newInstance(); - GenericValue requirement = iter.next(); String productId = requirement.getString("productId"); partyId = requirement.getString("partyId"); String facilityId = requirement.getString("facilityId"); @@ -217,8 +216,7 @@ public class RequirementServices { } String facilityId = productStore.getString("inventoryFacilityId"); List orderItems = order.getRelated("OrderItem"); - for (Iterator iter = orderItems.iterator(); iter.hasNext();) { - GenericValue item = iter.next(); + for(GenericValue item : orderItems) { GenericValue product = item.getRelatedOne("Product"); if (product == null) continue; if ((!"PRODRQM_AUTO".equals(product.get("requirementMethodEnumId")) && @@ -277,8 +275,7 @@ public class RequirementServices { } String facilityId = productStore.getString("inventoryFacilityId"); List orderItems = order.getRelated("OrderItem"); - for (Iterator iter = orderItems.iterator(); iter.hasNext();) { - GenericValue item = iter.next(); + for(GenericValue item : orderItems) { GenericValue product = item.getRelatedOne("Product"); if (product == null) continue; @@ -312,8 +309,7 @@ public class RequirementServices { EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "REQ_REJECTED")), EntityOperator.AND); List requirements = delegator.findList("Requirement", ecl, null, null, null, false); - for (Iterator riter = requirements.iterator(); riter.hasNext();) { - GenericValue requirement = riter.next(); + for(GenericValue requirement : requirements) { pendingRequirements = pendingRequirements.add(requirement.get("quantity") == null ? BigDecimal.ZERO : requirement.getBigDecimal("quantity")); } diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java b/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java index c589c9618a..5070042213 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/CartEventListener.java @@ -18,8 +18,6 @@ *******************************************************************************/ package org.ofbiz.order.shoppingcart; -import java.util.Iterator; - import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; @@ -78,10 +76,8 @@ public class CartEventListener implements HttpSessionListener { } Debug.logInfo("Saving abandoned cart", module); - Iterator cartItems = cart.iterator(); int seqId = 1; - while (cartItems.hasNext()) { - ShoppingCartItem cartItem = cartItems.next(); + for(ShoppingCartItem cartItem : cart) { GenericValue cartAbandonedLine = delegator.makeValue("CartAbandonedLine"); cartAbandonedLine.set("visitId", visit.get("visitId")); diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java b/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java index 8bba6f3f6d..f21142883f 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java @@ -266,9 +266,7 @@ public class CheckOutHelper { try { List billingAccountTerms = delegator.findByAnd("BillingAccountTerm", UtilMisc.toMap("billingAccountId", billingAccountId)); if (UtilValidate.isNotEmpty(billingAccountTerms)) { - Iterator billingAccountTermsIt = billingAccountTerms.iterator(); - while (billingAccountTermsIt.hasNext()) { - GenericValue billingAccountTerm = billingAccountTermsIt.next(); + for(GenericValue billingAccountTerm : billingAccountTerms) { // the term is not copied if in the cart a term of the same type is already set if (!cart.hasOrderTerm(billingAccountTerm.getString("termTypeId"))) { cart.addOrderTerm(billingAccountTerm.getString("termTypeId"), billingAccountTerm.getBigDecimal("termValue"), billingAccountTerm.getLong("termDays")); @@ -318,10 +316,7 @@ public class CheckOutHelper { } } - Set paymentMethods = selectedPaymentMethods.keySet(); - Iterator i = paymentMethods.iterator(); - while (i.hasNext()) { - String checkOutPaymentId = i.next(); + for(String checkOutPaymentId : selectedPaymentMethods.keySet()) { String finAccountId = null; if (checkOutPaymentId.indexOf("|") > -1) { @@ -633,10 +628,8 @@ public class CheckOutHelper { // If needed, the production runs are created and linked to the order lines. // List orderItems = UtilGenerics.checkList(context.get("orderItems")); - Iterator orderItemsIt = orderItems.iterator(); int counter = 0; - while (orderItemsIt.hasNext()) { - GenericValue orderItem = orderItemsIt.next(); + for(GenericValue orderItem : orderItems) { String productId = orderItem.getString("productId"); if (productId != null) { try { @@ -675,9 +668,7 @@ public class CheckOutHelper { // ---------- // The status of the requirement associated to the shopping cart lines is set to "ordered". // - Iterator shoppingCartItems = this.cart.items().iterator(); - while (shoppingCartItems.hasNext()) { - ShoppingCartItem shoppingCartItem = shoppingCartItems.next(); + for(ShoppingCartItem shoppingCartItem : this.cart.items()) { String requirementId = shoppingCartItem.getRequirementId(); if (requirementId != null) { try { @@ -731,9 +722,7 @@ public class CheckOutHelper { String additionalEmails = this.cart.getOrderAdditionalEmails(); List emailList = StringUtil.split(additionalEmails, ","); if (emailList == null) emailList = new ArrayList(); - Iterator eli = emailList.iterator(); - while (eli.hasNext()) { - String email = eli.next(); + for(String email : emailList) { String contactMechId = this.delegator.getNextSeqId("ContactMech"); GenericValue contactMech = this.delegator.makeValue("ContactMech", UtilMisc.toMap("contactMechId", contactMechId, "contactMechTypeId", "EMAIL_ADDRESS", "infoString", email)); @@ -956,9 +945,7 @@ public class CheckOutHelper { List exprs = UtilMisc.toList(EntityCondition.makeCondition("manualRefNum", EntityOperator.NOT_EQUAL, null)); List manualRefPaymentPrefs = EntityUtil.filterByAnd(allPaymentPreferences, exprs); if (UtilValidate.isNotEmpty(manualRefPaymentPrefs)) { - Iterator i = manualRefPaymentPrefs.iterator(); - while (i.hasNext()) { - GenericValue opp = i.next(); + for(GenericValue opp : manualRefPaymentPrefs) { Map authCtx = new HashMap(); authCtx.put("orderPaymentPreference", opp); if (opp.get("paymentMethodId") == null) { @@ -1176,9 +1163,7 @@ public class CheckOutHelper { public static void adjustFaceToFacePayment(String orderId, BigDecimal cartTotal, List allPaymentPrefs, GenericValue userLogin, Delegator delegator) throws GeneralException { BigDecimal prefTotal = BigDecimal.ZERO; if (allPaymentPrefs != null) { - Iterator i = allPaymentPrefs.iterator(); - while (i.hasNext()) { - GenericValue pref = i.next(); + for(GenericValue pref : allPaymentPrefs) { BigDecimal maxAmount = pref.getBigDecimal("maxAmount"); if (maxAmount == null) maxAmount = BigDecimal.ZERO; prefTotal = prefTotal.add(maxAmount); @@ -1217,9 +1202,7 @@ public class CheckOutHelper { String errMsg=null; List paymentMethods = this.cart.getPaymentMethods(); - Iterator i = paymentMethods.iterator(); - while (i.hasNext()) { - GenericValue paymentMethod = i.next(); + for(GenericValue paymentMethod : paymentMethods) { if ((paymentMethod != null) && ("CREDIT_CARD".equals(paymentMethod.getString("paymentMethodTypeId")))) { GenericValue creditCard = null; GenericValue billingAddress = null; @@ -1518,9 +1501,7 @@ public class CheckOutHelper { public Map makeBillingAccountMap(List paymentPrefs) { Map accountMap = new HashMap(); if (paymentPrefs != null) { - Iterator i = paymentPrefs.iterator(); - while (i.hasNext()) { - GenericValue pp = i.next(); + for(GenericValue pp : paymentPrefs) { if (pp.get("billingAccountId") != null) { accountMap.put(pp.getString("billingAccountId"), pp.getBigDecimal("maxAmount")); } @@ -1557,18 +1538,14 @@ public class CheckOutHelper { // update the selected payment methods amount with valid numbers if (paymentMethods != null) { List nullPaymentIds = new ArrayList(); - Iterator i = paymentMethods.iterator(); - while (i.hasNext()) { - String paymentMethodId = i.next(); + for(String paymentMethodId : paymentMethods) { BigDecimal paymentAmount = cart.getPaymentAmount(paymentMethodId); if (paymentAmount == null || paymentAmount.compareTo(BigDecimal.ZERO) == 0) { if (Debug.verboseOn()) Debug.logVerbose("Found null paymentMethodId - " + paymentMethodId, module); nullPaymentIds.add(paymentMethodId); } } - Iterator npi = nullPaymentIds.iterator(); - while (npi.hasNext()) { - String paymentMethodId = npi.next(); + for(String paymentMethodId : nullPaymentIds) { BigDecimal selectedPaymentTotal = cart.getPaymentTotal(); BigDecimal requiredAmount = cart.getGrandTotal(); BigDecimal newAmount = requiredAmount.subtract(selectedPaymentTotal); @@ -1636,9 +1613,7 @@ public class CheckOutHelper { String balanceField = null; // get the gift card objects to check - Iterator i = cart.getGiftCards().iterator(); - while (i.hasNext()) { - GenericValue gc = i.next(); + for(GenericValue gc : cart.getGiftCards()) { Map gcBalanceMap = null; BigDecimal gcBalance = BigDecimal.ZERO; try { diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java index e04bf50624..846f63d41b 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java @@ -218,9 +218,7 @@ public class ShoppingCart implements Iterable, Serializable { } // clone the groups - Iterator groupIt = cart.itemGroupByNumberMap.values().iterator(); - while (groupIt.hasNext()) { - ShoppingCartItemGroup itemGroup = groupIt.next(); + for(ShoppingCartItemGroup itemGroup : cart.itemGroupByNumberMap.values()) { // get the new parent group by number from the existing set; as before the parent must come before all children to work... ShoppingCartItemGroup parentGroup = null; if (itemGroup.getParentGroup() != null) parentGroup = this.getItemGroupByNumber(itemGroup.getParentGroup().getGroupNumber()); @@ -229,12 +227,10 @@ public class ShoppingCart implements Iterable, Serializable { } // clone the items - List items = cart.items(); - Iterator itIt = items.iterator(); - while (itIt.hasNext()) { - cartLines.add(new ShoppingCartItem(itIt.next())); + for(ShoppingCartItem item : cart.items()) { + cartLines.add(new ShoppingCartItem(item)); } - + this.facilityId = cart.facilityId; this.webSiteId = cart.webSiteId; } @@ -429,9 +425,7 @@ public class ShoppingCart implements Iterable, Serializable { String previousCurrency = this.currencyUom; this.currencyUom = currencyUom; if (!previousCurrency.equals(this.currencyUom)) { - Iterator itemIterator = this.iterator(); - while (itemIterator.hasNext()) { - ShoppingCartItem item = itemIterator.next(); + for(ShoppingCartItem item : this) { item.updatePrice(dispatcher, this); } } @@ -758,18 +752,14 @@ public class ShoppingCart implements Iterable, Serializable { localList.addAll(multipleItems); // the ones to keep... for (int i=0; i localIter = localList.iterator(); - while (localIter.hasNext()) { - ShoppingCartItem item = localIter.next(); + for(ShoppingCartItem item : localList) { this.removeCartItem(item, dispatcher); } } public static BigDecimal getItemsTotalQuantity(List cartItems) { BigDecimal totalQuantity = BigDecimal.ZERO; - Iterator localIter = cartItems.iterator(); - while (localIter.hasNext()) { - ShoppingCartItem item = localIter.next(); + for(ShoppingCartItem item : cartItems) { totalQuantity = totalQuantity.add(item.getQuantity()); } return totalQuantity; @@ -777,9 +767,7 @@ public class ShoppingCart implements Iterable, Serializable { public static List getItemsProducts(List cartItems) { List productList = FastList.newInstance(); - Iterator localIter = cartItems.iterator(); - while (localIter.hasNext()) { - ShoppingCartItem item = localIter.next(); + for(ShoppingCartItem item : cartItems) { GenericValue product = item.getProduct(); if (product != null) { productList.add(product); @@ -789,9 +777,7 @@ public class ShoppingCart implements Iterable, Serializable { } public void ensureItemsQuantity(List cartItems, LocalDispatcher dispatcher, BigDecimal quantity) throws CartItemModifyException { - Iterator localIter = cartItems.iterator(); - while (localIter.hasNext()) { - ShoppingCartItem item = localIter.next(); + for(ShoppingCartItem item : cartItems) { if (item.getQuantity() != quantity) { item.setQuantity(quantity, dispatcher, this); } @@ -802,10 +788,7 @@ public class ShoppingCart implements Iterable, Serializable { BigDecimal quantityRemoved = BigDecimal.ZERO; // go through the items and reduce quantityToKeep by the item quantities until it is 0, then remove the remaining... BigDecimal quantityToKeep = quantity; - Iterator localIter = cartItems.iterator(); - while (localIter.hasNext()) { - ShoppingCartItem item = localIter.next(); - + for(ShoppingCartItem item : cartItems) { if (quantityToKeep.compareTo(item.getQuantity()) >= 0) { // quantityToKeep sufficient to keep it all... just reduce quantityToKeep and move on quantityToKeep = quantityToKeep.subtract(item.getQuantity()); @@ -829,8 +812,7 @@ public class ShoppingCart implements Iterable, Serializable { // ============== WorkEffort related methods =============== public boolean containAnyWorkEffortCartItems() { // Check for existing cart item. - for (int i = 0; i < this.cartLines.size(); i++) { - ShoppingCartItem cartItem = cartLines.get(i); + for(ShoppingCartItem cartItem : this.cartLines) { if (cartItem.getItemType().equals("RENTAL_ORDER_ITEM")) { // create workeffort items? return true; } @@ -840,8 +822,7 @@ public class ShoppingCart implements Iterable, Serializable { public boolean containAllWorkEffortCartItems() { // Check for existing cart item. - for (int i = 0; i < this.cartLines.size(); i++) { - ShoppingCartItem cartItem = cartLines.get(i); + for(ShoppingCartItem cartItem : this.cartLines) { if (!cartItem.getItemType().equals("RENTAL_ORDER_ITEM")) { // not a item to create workefforts? return false; } @@ -854,8 +835,7 @@ public class ShoppingCart implements Iterable, Serializable { * This is determined by making sure no Product has a type where ProductType.isPhysical!=N. */ public boolean containOnlyDigitalGoods() { - for (int i = 0; i < this.cartLines.size(); i++) { - ShoppingCartItem cartItem = cartLines.get(i); + for(ShoppingCartItem cartItem : this.cartLines) { GenericValue product = cartItem.getProduct(); try { GenericValue productType = product.getRelatedOneCache("ProductType"); @@ -1024,16 +1004,12 @@ public class ShoppingCart implements Iterable, Serializable { if (itemGroup != null) { // go through all cart items and remove from group if they are in it List cartItemList = this.getCartItemsInGroup(groupNumber); - Iterator cartItemIter = cartItemList.iterator(); - while (cartItemIter.hasNext()) { - ShoppingCartItem cartItem = cartItemIter.next(); + for(ShoppingCartItem cartItem : cartItemList) { cartItem.setItemGroup(null); } // if this is a parent of any set them to this group's parent (or null) - Iterator itemGroupIter = this.itemGroupByNumberMap.values().iterator(); - while (itemGroupIter.hasNext()) { - ShoppingCartItemGroup otherItemGroup = itemGroupIter.next(); + for(ShoppingCartItemGroup otherItemGroup : this.itemGroupByNumberMap.values()) { if (itemGroup.equals(otherItemGroup.getParentGroup())) { otherItemGroup.inheritParentsParent(); } @@ -1089,9 +1065,7 @@ public class ShoppingCart implements Iterable, Serializable { String partyId = this.getPartyId(); if (UtilValidate.isNotEmpty(partyId)) { // recalculate all prices - Iterator cartItemIter = this.iterator(); - while (cartItemIter.hasNext()) { - ShoppingCartItem cartItem = cartItemIter.next(); + for(ShoppingCartItem cartItem : this) { cartItem.updatePrice(dispatcher, this); } @@ -1576,9 +1550,7 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the CartPaymentInfo objects which have matching fields */ public List getPaymentInfos(boolean isPaymentMethod, boolean isPaymentMethodType, boolean hasRefNum) { List foundRecords = new LinkedList(); - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (isPaymentMethod && inf.paymentMethodId != null) { if (hasRefNum && inf.refNum != null) { foundRecords.add(inf); @@ -1604,9 +1576,7 @@ public class ShoppingCart implements Iterable, Serializable { /** Locates an existing (or creates a new) CartPaymentInfo object */ public CartPaymentInfo getPaymentInfo(String id, String refNum, String authCode, BigDecimal amount, boolean update) { CartPaymentInfo thisInf = this.makePaymentInfo(id, refNum, authCode, amount); - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (inf.compareTo(thisInf) == 0) { // update the info if (update) { @@ -1642,9 +1612,7 @@ public class ShoppingCart implements Iterable, Serializable { // this payment method will set the billing address for the order; // before it is set we have to verify if the billing address is // compatible with the ProductGeos - Iterator products = (ShoppingCart.getItemsProducts(this.cartLines)).iterator(); - while (products.hasNext()) { - GenericValue product = products.next(); + for(GenericValue product : ShoppingCart.getItemsProducts(this.cartLines)) { if (!ProductWorker.isBillableToAddress(product, billingAddress)) { throw new IllegalArgumentException("The billing address is not compatible with ProductGeos rules."); } @@ -1687,9 +1655,7 @@ public class ShoppingCart implements Iterable, Serializable { } public String getPaymentRef(String id) { - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (inf.paymentMethodId.equals(id) || inf.paymentMethodTypeId.equals(id)) { return inf.refNum[0]; } @@ -1700,9 +1666,7 @@ public class ShoppingCart implements Iterable, Serializable { /** returns the total payment amounts */ public BigDecimal getPaymentTotal() { BigDecimal total = BigDecimal.ZERO; - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (inf.amount != null) { total = total.add(inf.amount); } @@ -1755,8 +1719,7 @@ public class ShoppingCart implements Iterable, Serializable { List declinedPaymentMethods = delegator.findByAnd("OrderPaymentPreference", UtilMisc.toMap("orderId", orderId, "statusId", "PAYMENT_DECLINED")); if (!UtilValidate.isEmpty(declinedPaymentMethods)) { List paymentMethodIdsToRemove = new ArrayList(); - for (Iterator iter = declinedPaymentMethods.iterator(); iter.hasNext();) { - GenericValue opp = iter.next(); + for(GenericValue opp : declinedPaymentMethods) { paymentMethodIdsToRemove.add(opp.getString("paymentMethodId")); } clearPaymentMethodsById(paymentMethodIdsToRemove); @@ -1770,9 +1733,7 @@ public class ShoppingCart implements Iterable, Serializable { private void expireSingleUsePayments() { Timestamp now = UtilDateTime.nowTimestamp(); - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (inf.paymentMethodId == null || !inf.singleUse) { continue; } @@ -1799,9 +1760,7 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the Payment Method Ids */ public List getPaymentMethodIds() { List pmi = new LinkedList(); - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (inf.paymentMethodId != null) { pmi.add(inf.paymentMethodId); } @@ -1812,9 +1771,7 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the Payment Method Ids */ public List getPaymentMethodTypeIds() { List pmt = FastList.newInstance(); - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (inf.paymentMethodTypeId != null) { pmt.add(inf.paymentMethodTypeId); } @@ -1826,9 +1783,7 @@ public class ShoppingCart implements Iterable, Serializable { public List getPaymentMethods() { List methods = FastList.newInstance(); if (UtilValidate.isNotEmpty(paymentInfo)) { - Iterator paymentMethodIdIter = getPaymentMethodIds().iterator(); - while (paymentMethodIdIter.hasNext()) { - String paymentMethodId = paymentMethodIdIter.next(); + for(String paymentMethodId : getPaymentMethodIds()) { try { GenericValue paymentMethod = this.getDelegator().findByPrimaryKeyCache("PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId)); if (paymentMethod != null) { @@ -1849,9 +1804,7 @@ public class ShoppingCart implements Iterable, Serializable { public List getPaymentMethodTypes() { List types = new LinkedList(); if (UtilValidate.isNotEmpty(paymentInfo)) { - Iterator i = getPaymentMethodTypeIds().iterator(); - while (i.hasNext()) { - String id = i.next(); + for(String id : getPaymentMethodIds()) { try { types.add(this.getDelegator().findByPrimaryKeyCache("PaymentMethodType", UtilMisc.toMap("paymentMethodTypeId", id))); } catch (GenericEntityException e) { @@ -1867,9 +1820,7 @@ public class ShoppingCart implements Iterable, Serializable { List paymentMethods = this.getPaymentMethods(); List creditCards = new LinkedList(); if (paymentMethods != null) { - Iterator i = paymentMethods.iterator(); - while (i.hasNext()) { - GenericValue pm = i.next(); + for(GenericValue pm : paymentMethods) { if ("CREDIT_CARD".equals(pm.getString("paymentMethodTypeId"))) { try { GenericValue cc = pm.getRelatedOne("CreditCard"); @@ -1888,9 +1839,7 @@ public class ShoppingCart implements Iterable, Serializable { List paymentMethods = this.getPaymentMethods(); List giftCards = new LinkedList(); if (paymentMethods != null) { - Iterator i = paymentMethods.iterator(); - while (i.hasNext()) { - GenericValue pm = i.next(); + for(GenericValue pm : paymentMethods) { if ("GIFT_CARD".equals(pm.getString("paymentMethodTypeId"))) { try { GenericValue gc = pm.getRelatedOne("GiftCard"); @@ -1922,9 +1871,7 @@ public class ShoppingCart implements Iterable, Serializable { public GenericValue getBillingAddress() { GenericValue billingAddress = null; - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { billingAddress = inf.getBillingAddress(this.getDelegator()); if (billingAddress != null) { break; @@ -2109,8 +2056,7 @@ public class ShoppingCart implements Iterable, Serializable { Map shipGroups = this.getShipGroups(item); if ((shipGroups != null) && (shipGroups.keySet() != null)) { - for (Iterator shipGroupKeys = shipGroups.keySet().iterator(); shipGroupKeys.hasNext();) { - Integer shipGroup = shipGroupKeys.next(); + for(Integer shipGroup : shipGroups.keySet()) { CartShipInfo cartShipInfo = this.getShipInfo(shipGroup.intValue()); cartShipInfo.resetShipAfterDateIfBefore(item.getShipAfterDate()); @@ -2258,9 +2204,7 @@ public class ShoppingCart implements Iterable, Serializable { if (shippingAddress != null) { Set shipItems = csi.getShipItems(); if (UtilValidate.isNotEmpty(shipItems)) { - Iterator siit = shipItems.iterator(); - while (siit.hasNext()) { - ShoppingCartItem cartItem = siit.next(); + for(ShoppingCartItem cartItem : shipItems) { GenericValue product = cartItem.getProduct(); if (UtilValidate.isNotEmpty(product)) { if (!ProductWorker.isShippableToAddress(product, shippingAddress)) { @@ -2607,11 +2551,8 @@ public class ShoppingCart implements Iterable, Serializable { public BigDecimal getTotalShipping() { BigDecimal tempShipping = BigDecimal.ZERO; - Iterator shipIter = this.shipInfo.iterator(); - while (shipIter.hasNext()) { - CartShipInfo csi = shipIter.next(); + for(CartShipInfo csi : this.shipInfo) { tempShipping = tempShipping.add(csi.shipEstimate); - } return tempShipping; @@ -2620,10 +2561,8 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the item-total in the cart (not including discount/tax/shipping). */ public BigDecimal getItemTotal() { BigDecimal itemTotal = BigDecimal.ZERO; - Iterator i = iterator(); - - while (i.hasNext()) { - itemTotal = itemTotal.add((i.next()).getBasePrice()); + for(ShoppingCartItem cartItem : this.cartLines) { + itemTotal = itemTotal.add(cartItem.getBasePrice()); } return itemTotal; } @@ -2631,10 +2570,8 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the sub-total in the cart (item-total - discount). */ public BigDecimal getSubTotal() { BigDecimal itemsTotal = BigDecimal.ZERO; - Iterator i = iterator(); - - while (i.hasNext()) { - itemsTotal = itemsTotal.add((i.next()).getItemSubTotal()); + for(ShoppingCartItem cartItem : this.cartLines) { + itemsTotal = itemsTotal.add(cartItem.getItemSubTotal()); } return itemsTotal; } @@ -2651,9 +2588,8 @@ public class ShoppingCart implements Iterable, Serializable { public BigDecimal getDisplaySubTotal() { BigDecimal itemsTotal = BigDecimal.ZERO; - Iterator i = iterator(); - while (i.hasNext()) { - itemsTotal = itemsTotal.add((i.next()).getDisplayItemSubTotal()); + for(ShoppingCartItem cartItem : this.cartLines) { + itemsTotal = itemsTotal.add(cartItem.getDisplayItemSubTotal()); } return itemsTotal; } @@ -2665,9 +2601,8 @@ public class ShoppingCart implements Iterable, Serializable { public BigDecimal getDisplayRecurringSubTotal() { BigDecimal itemsTotal = BigDecimal.ZERO; - Iterator i = iterator(); - while (i.hasNext()) { - itemsTotal = itemsTotal.add((i.next()).getDisplayItemRecurringSubTotal()); + for(ShoppingCartItem cartItem : this.cartLines) { + itemsTotal = itemsTotal.add(cartItem.getDisplayItemRecurringSubTotal()); } return itemsTotal; } @@ -2684,10 +2619,7 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the sub-total in the cart (item-total - discount). */ public BigDecimal getSubTotalForPromotions() { BigDecimal itemsTotal = BigDecimal.ZERO; - Iterator i = iterator(); - - while (i.hasNext()) { - ShoppingCartItem cartItem = i.next(); + for(ShoppingCartItem cartItem : this.cartLines) { GenericValue product = cartItem.getProduct(); if (product != null && "N".equals(product.getString("includeInPromotions"))) { // don't include in total if this is the case... @@ -2705,8 +2637,7 @@ public class ShoppingCart implements Iterable, Serializable { public BigDecimal getOrderPaymentPreferenceTotalByType(String paymentMethodTypeId) { BigDecimal total = BigDecimal.ZERO; String thisPaymentMethodTypeId = null; - for (Iterator iter = paymentInfo.iterator(); iter.hasNext();) { - CartPaymentInfo payment = iter.next(); + for(CartPaymentInfo payment : paymentInfo) { if (payment.amount == null) continue; if (payment.paymentMethodId != null) { try { @@ -2852,9 +2783,7 @@ public class ShoppingCart implements Iterable, Serializable { if (termTypeId == null) { return false; } - Iterator orderTermsIt = orderTerms.iterator(); - while (orderTermsIt.hasNext()) { - GenericValue orderTerm = orderTermsIt.next(); + for(GenericValue orderTerm : orderTerms) { if (termTypeId.equals(orderTerm.getString("termTypeId"))) { return true; } @@ -2878,11 +2807,8 @@ public class ShoppingCart implements Iterable, Serializable { List> adjsLists = FastList.newInstance(); adjsLists.add(this.getAdjustments()); - Iterator cartIterator = this.iterator(); - - while (cartIterator.hasNext()) { - ShoppingCartItem item = cartIterator.next(); + for(ShoppingCartItem item : this) { if (item.getAdjustments() != null) { adjsLists.add(item.getAdjustments()); } @@ -2907,11 +2833,8 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the total weight in the cart. */ public BigDecimal getTotalWeight() { BigDecimal weight = BigDecimal.ZERO; - Iterator i = iterator(); - - while (i.hasNext()) { - ShoppingCartItem item = i.next(); + for(ShoppingCartItem item : this.cartLines) { weight = weight.add(item.getWeight().multiply(item.getQuantity())); } return weight; @@ -2920,10 +2843,9 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns the total quantity in the cart. */ public BigDecimal getTotalQuantity() { BigDecimal count = BigDecimal.ZERO; - Iterator i = iterator(); - while (i.hasNext()) { - count = count.add((i.next()).getQuantity()); + for(ShoppingCartItem item : this.cartLines) { + count = count.add(item.getQuantity()); } return count; } @@ -3018,9 +2940,7 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns true when there are shippable items in the cart */ public boolean shippingApplies() { boolean shippingApplies = false; - Iterator i = this.iterator(); - while (i.hasNext()) { - ShoppingCartItem item = i.next(); + for(ShoppingCartItem item : this) { if (item.shippingApplies()) { shippingApplies = true; break; @@ -3032,9 +2952,7 @@ public class ShoppingCart implements Iterable, Serializable { /** Returns true when there are taxable items in the cart */ public boolean taxApplies() { boolean taxApplies = false; - Iterator i = this.iterator(); - while (i.hasNext()) { - ShoppingCartItem item = i.next(); + for(ShoppingCartItem item : this) { if (item.taxApplies()) { taxApplies = true; break; @@ -3152,9 +3070,7 @@ public class ShoppingCart implements Iterable, Serializable { public void clearCartItemUseInPromoInfo() { // clear out info about which cart items have been used in promos - Iterator cartLineIter = this.iterator(); - while (cartLineIter.hasNext()) { - ShoppingCartItem cartLine = cartLineIter.next(); + for(ShoppingCartItem cartLine : this) { cartLine.clearPromoRuleUseInfo(); } } @@ -3167,9 +3083,7 @@ public class ShoppingCart implements Iterable, Serializable { BigDecimal totalDiscount = BigDecimal.ZERO; List cartAdjustments = this.getAdjustments(); if (cartAdjustments != null) { - Iterator cartAdjustmentIter = cartAdjustments.iterator(); - while (cartAdjustmentIter.hasNext()) { - GenericValue checkOrderAdjustment = cartAdjustmentIter.next(); + for(GenericValue checkOrderAdjustment : cartAdjustments) { if (UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoId")) && UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoRuleId")) && UtilValidate.isNotEmpty(checkOrderAdjustment.getString("productPromoActionSeqId"))) { @@ -3181,9 +3095,7 @@ public class ShoppingCart implements Iterable, Serializable { } // add cart line adjustments from promo actions - Iterator cartItemIter = this.iterator(); - while (cartItemIter.hasNext()) { - ShoppingCartItem checkItem = cartItemIter.next(); + for(ShoppingCartItem checkItem : this) { Iterator checkOrderAdjustments = UtilMisc.toIterator(checkItem.getAdjustments()); while (checkOrderAdjustments != null && checkOrderAdjustments.hasNext()) { GenericValue checkOrderAdjustment = checkOrderAdjustments.next(); @@ -3287,17 +3199,13 @@ public class ShoppingCart implements Iterable, Serializable { // remove all cart adjustments this.adjustments.clear(); // remove all cart item adjustments - Iterator cartItemIter = this.iterator(); - while (cartItemIter.hasNext()) { - ShoppingCartItem checkItem = cartItemIter.next(); + for(ShoppingCartItem checkItem : this) { checkItem.getAdjustments().clear(); } } public void clearAllItemStatus() { - Iterator lineIter = this.iterator(); - while (lineIter.hasNext()) { - ShoppingCartItem item = lineIter.next(); + for(ShoppingCartItem item : this) { item.setStatusId(null); } } @@ -3331,17 +3239,13 @@ public class ShoppingCart implements Iterable, Serializable { } public synchronized void resetPromoRuleUse(String productPromoId, String productPromoRuleId) { - Iterator lineIter = this.iterator(); - while (lineIter.hasNext()) { - ShoppingCartItem cartItem = lineIter.next(); + for(ShoppingCartItem cartItem : this) { cartItem.resetPromoRuleUse(productPromoId, productPromoRuleId); } } public synchronized void confirmPromoRuleUse(String productPromoId, String productPromoRuleId) { - Iterator lineIter = this.iterator(); - while (lineIter.hasNext()) { - ShoppingCartItem cartItem = lineIter.next(); + for(ShoppingCartItem cartItem : this) { cartItem.confirmPromoRuleUse(productPromoId, productPromoRuleId); } } @@ -3355,9 +3259,8 @@ public class ShoppingCart implements Iterable, Serializable { // search if there is an existing entry List parties = additionalPartyRole.get(roleTypeId); if (parties != null) { - Iterator it = parties.iterator(); - while (it.hasNext()) { - if ((it.next()).equals(partyId)) { + for(String pi : parties) { + if (pi.equals(partyId)) { return; } } @@ -3491,9 +3394,7 @@ public class ShoppingCart implements Iterable, Serializable { public List makeOrderItemGroups() { List result = FastList.newInstance(); - Iterator groupValueIter = this.itemGroupByNumberMap.values().iterator(); - while (groupValueIter.hasNext()) { - ShoppingCart.ShoppingCartItemGroup itemGroup = groupValueIter.next(); + for(ShoppingCart.ShoppingCartItemGroup itemGroup : this.itemGroupByNumberMap.values()) { result.add(itemGroup.makeOrderItemGroup(this.getDelegator())); } return result; @@ -3503,11 +3404,7 @@ public class ShoppingCart implements Iterable, Serializable { if (dispatcher == null) return; synchronized (cartLines) { List cartLineItems = new LinkedList(cartLines); - Iterator itemIter = cartLineItems.iterator(); - - while (itemIter.hasNext()) { - ShoppingCartItem item = itemIter.next(); - + for(ShoppingCartItem item : cartLineItems) { //Debug.logInfo("Item qty: " + item.getQuantity(), module); try { item.explodeItem(this, dispatcher); @@ -3528,10 +3425,7 @@ public class ShoppingCart implements Iterable, Serializable { public void explodeItems(List shoppingCartItems, LocalDispatcher dispatcher) { if (dispatcher == null) return; synchronized (cartLines) { - Iterator itemIter = shoppingCartItems.iterator(); - while (itemIter.hasNext()) { - ShoppingCartItem item = itemIter.next(); - + for(ShoppingCartItem item : shoppingCartItems) { //Debug.logInfo("Item qty: " + item.getQuantity(), module); try { item.explodeItem(this, dispatcher); @@ -3805,9 +3699,7 @@ public class ShoppingCart implements Iterable, Serializable { remainingAmount = BigDecimal.ZERO; } } - Iterator i = paymentInfo.iterator(); - while (i.hasNext()) { - CartPaymentInfo inf = i.next(); + for(CartPaymentInfo inf : paymentInfo) { if (inf.amount == null) { inf.amount = remainingAmount; remainingAmount = BigDecimal.ZERO; @@ -3826,11 +3718,7 @@ public class ShoppingCart implements Iterable, Serializable { Collection infos = item.getOrderItemPriceInfos(); if (infos != null) { - Iterator infosIter = infos.iterator(); - - while (infosIter.hasNext()) { - GenericValue orderItemPriceInfo = infosIter.next(); - + for(GenericValue orderItemPriceInfo : infos) { orderItemPriceInfo.set("orderItemSeqId", item.getOrderItemSeqId()); allInfos.add(orderItemPriceInfo); } @@ -3861,15 +3749,11 @@ public class ShoppingCart implements Iterable, Serializable { /** make a list of SurveyResponse object to update with order information set */ public List makeAllOrderItemSurveyResponses() { List allInfos = new LinkedList(); - Iterator itemIter = this.iterator(); - while (itemIter.hasNext()) { - ShoppingCartItem item = itemIter.next(); + for(ShoppingCartItem item : this) { List responses = UtilGenerics.checkList(item.getAttribute("surveyResponses")); GenericValue response = null; if (responses != null) { - Iterator ri = responses.iterator(); - while (ri.hasNext()) { - String responseId = ri.next(); + for(String responseId : responses) { try { response = this.getDelegator().findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", responseId)); } catch (GenericEntityException e) { @@ -3935,10 +3819,8 @@ public class ShoppingCart implements Iterable, Serializable { public List makeAllShipGroupInfos() { List groups = new LinkedList(); - Iterator grpIterator = this.shipInfo.iterator(); long seqId = 1; - while (grpIterator.hasNext()) { - CartShipInfo csi = grpIterator.next(); + for(CartShipInfo csi : this.shipInfo) { groups.addAll(csi.makeItemShipGroupAndAssoc(this.getDelegator(), this, seqId)); seqId++; } @@ -3961,9 +3843,7 @@ public class ShoppingCart implements Iterable, Serializable { for (ShoppingCartItem item : cartLines) { Map orderItemAttributes = item.getOrderItemAttributes(); - Iterator attributesIter = orderItemAttributes.keySet().iterator(); - while (attributesIter.hasNext()) { - String key = attributesIter.next(); + for(String key : orderItemAttributes.keySet()) { String value = orderItemAttributes.get(key); GenericValue orderItemAttribute = getDelegator().makeValue("OrderItemAttribute"); @@ -4200,11 +4080,7 @@ public class ShoppingCart implements Iterable, Serializable { Set shipItems = shipInfo.getShipItems(); if (UtilValidate.isEmpty(shipItems)) continue; - Iterator siit = shipItems.iterator(); - while (siit.hasNext()) { - - ShoppingCartItem cartItem = siit.next(); - + for(ShoppingCartItem cartItem : shipItems) { BigDecimal itemQuantity = cartItem.getQuantity(); BigDecimal dropShipQuantity = BigDecimal.ZERO; @@ -4276,10 +4152,7 @@ public class ShoppingCart implements Iterable, Serializable { } // Reassign the drop-shippable item quantities to new or existing drop-ship groups - Iterator dsit = dropShipItems.keySet().iterator(); - while (dsit.hasNext()) { - String supplierPartyId = dsit.next(); - + for (String supplierPartyId : dropShipItems.keySet()) { CartShipInfo shipInfo = null; int newShipGroupIndex = -1 ; @@ -4296,15 +4169,9 @@ public class ShoppingCart implements Iterable, Serializable { shipInfo.supplierPartyId = supplierPartyId; Map> supplierCartItems = UtilGenerics.checkMap(dropShipItems.get(supplierPartyId)); - Iterator itit = supplierCartItems.keySet().iterator(); - while (itit.hasNext()) { - - ShoppingCartItem cartItem = itit.next(); + for(ShoppingCartItem cartItem : supplierCartItems.keySet()) { Map cartItemGroupQuantities = UtilGenerics.checkMap(supplierCartItems.get(cartItem)); - Iterator cigit = cartItemGroupQuantities.keySet().iterator(); - while (cigit.hasNext()) { - - Integer previousShipGroupIndex = cigit.next(); + for(Integer previousShipGroupIndex : cartItemGroupQuantities.keySet()) { BigDecimal dropShipQuantity = cartItemGroupQuantities.get(previousShipGroupIndex); positionItemToGroup(cartItem, dropShipQuantity, previousShipGroupIndex.intValue(), newShipGroupIndex, true); } @@ -4508,9 +4375,7 @@ public class ShoppingCart implements Iterable, Serializable { public void clearAllTaxInfo() { this.shipTaxAdj.clear(); - Iterator i = shipItemInfo.values().iterator(); - while (i.hasNext()) { - CartShipItemInfo itemInfo = i.next(); + for(CartShipItemInfo itemInfo : shipItemInfo.values()) { itemInfo.itemTaxAdj.clear(); } } @@ -4595,17 +4460,13 @@ public class ShoppingCart implements Iterable, Serializable { } // create the top level tax adjustments - Iterator ti = shipTaxAdj.iterator(); - while (ti.hasNext()) { - GenericValue taxAdj = ti.next(); + for(GenericValue taxAdj : shipTaxAdj) { taxAdj.set("shipGroupSeqId", shipGroupSeqId); values.add(taxAdj); } // create the ship group item associations - Iterator i = shipItemInfo.keySet().iterator(); - while (i.hasNext()) { - ShoppingCartItem item = i.next(); + for(ShoppingCartItem item : shipItemInfo.keySet()) { CartShipItemInfo itemInfo = shipItemInfo.get(item); GenericValue assoc = delegator.makeValue("OrderItemShipGroupAssoc"); @@ -4615,9 +4476,7 @@ public class ShoppingCart implements Iterable, Serializable { values.add(assoc); // create the item tax adjustment - Iterator iti = itemInfo.itemTaxAdj.iterator(); - while (iti.hasNext()) { - GenericValue taxAdj = iti.next(); + for(GenericValue taxAdj : itemInfo.itemTaxAdj) { taxAdj.set("orderItemSeqId", item.getOrderItemSeqId()); taxAdj.set("shipGroupSeqId", shipGroupSeqId); values.add(taxAdj); @@ -4871,9 +4730,7 @@ public class ShoppingCart implements Iterable, Serializable { throw new GeneralRuntimeException("Split Payment Preference per Ship Group does not yet support multiple Payment Methods"); } if ("Y".equals(splitPayPrefPerShpGrp) && cart.paymentInfo.size() == 1) { - Iterator shipIter = cart.getShipGroups().iterator(); - while (shipIter.hasNext()) { - CartShipInfo csi = shipIter.next(); + for(CartShipInfo csi : cart.getShipGroups()) { maxAmount = csi.getTotal().add(cart.getOrderOtherAdjustmentTotal().divide(new BigDecimal(cart.getShipGroupSize()), generalRounding)).add(csi.getShipEstimate().add(csi.getTotalTax(cart))); maxAmount = maxAmount.setScale(scale, rounding); @@ -5065,10 +4922,8 @@ public class ShoppingCart implements Iterable, Serializable { } if (itemBasePrice == null) { List productPriceList = EntityUtil.filterByDate(delegator.findList("ProductPrice", EntityCondition.makeCondition("productId", itemProductId), null, null, null, false)); - Iterator it = productPriceList.iterator(); Map productPriceMap = FastMap.newInstance(); - while (it.hasNext()) { - GenericValue productPrice = it.next(); + for(GenericValue productPrice : productPriceList) { productPriceMap.put(productPrice.getString("productPriceTypeId"), productPrice.getBigDecimal("price")); } if (UtilValidate.isNotEmpty(productPriceMap.get("SPECIAL_PROMO_PRICE"))) { diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java index d6019b8fd1..1a7b8d453d 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java @@ -522,9 +522,7 @@ public class ShoppingCartEvents { productAssocs = delegator.findList("ProductAssoc", cond, null, null, null, false); productAssocs = EntityUtil.filterByDate(productAssocs); List productList = FastList.newInstance(); - Iterator iter = productAssocs.iterator(); - while (iter.hasNext()) { - GenericValue productAssoc = iter.next(); + for(GenericValue productAssoc : productAssocs) { if (productId.equals(productAssoc.getString("productId"))) { productList.add(productAssoc.getString("productIdTo")); continue; @@ -534,9 +532,7 @@ public class ShoppingCartEvents { continue; } } - Iterator sciIter = cart.iterator(); - while (sciIter.hasNext()) { - ShoppingCartItem sci = sciIter.next(); + for(ShoppingCartItem sci : cart) { if (productList.contains(sci.getProductId())) { try { cart.removeCartItem(sci, dispatcher); @@ -553,9 +549,7 @@ public class ShoppingCartEvents { EntityCondition.makeCondition("productAssocTypeId", EntityOperator.EQUALS, "PRODUCT_UPGRADE")), EntityOperator.AND); productList = delegator.findList("ProductAssoc", cond, UtilMisc.toSet("productId"), null, null, false); if (productList != null) { - Iterator sciIter = cart.iterator(); - while (sciIter.hasNext()) { - ShoppingCartItem sci = sciIter.next(); + for(ShoppingCartItem sci : cart) { if (productList.contains(sci.getProductId())) { try { cart.removeCartItem(sci, dispatcher); diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java index c0e6796a99..3318585217 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java @@ -209,10 +209,8 @@ public class ShoppingCartHelper { // Get the additional features selected for the product (if any) Map selectedFeatures = UtilHttp.makeParamMapWithPrefix(context, null, "FT", null); - Iterator selectedFeaturesTypes = selectedFeatures.keySet().iterator(); Map additionalFeaturesMap = FastMap.newInstance(); - while (selectedFeaturesTypes.hasNext()) { - String selectedFeatureType = selectedFeaturesTypes.next(); + for(String selectedFeatureType : selectedFeatures.keySet()) { String selectedFeatureValue = (String)selectedFeatures.get(selectedFeatureType); if (UtilValidate.isNotEmpty(selectedFeatureValue)) { GenericValue productFeatureAndAppl = null; @@ -588,10 +586,7 @@ public class ShoppingCartHelper { } BigDecimal totalQuantity = BigDecimal.ZERO; - Iterator pcmIter = prodCatMemberCol.iterator(); - - while (pcmIter.hasNext()) { - GenericValue productCategoryMember = pcmIter.next(); + for(GenericValue productCategoryMember : prodCatMemberCol) { BigDecimal quantity = productCategoryMember.getBigDecimal("quantity"); if (quantity != null && quantity.compareTo(BigDecimal.ZERO) > 0) { @@ -621,13 +616,8 @@ public class ShoppingCartHelper { /** Delete an item from the shopping cart. */ public Map deleteFromCart(Map context) { Map result = null; - Set names = context.keySet(); - Iterator i = names.iterator(); ArrayList errorMsgs = new ArrayList(); - - while (i.hasNext()) { - String o = i.next(); - + for(String o : context.keySet()) { if (o.toUpperCase().startsWith("DELETE")) { try { String indexStr = o.substring(o.lastIndexOf('_') + 1); @@ -662,9 +652,6 @@ public class ShoppingCartHelper { ArrayList deleteList = new ArrayList(); ArrayList errorMsgs = new ArrayList(); - Set parameterNames = context.keySet(); - Iterator parameterNameIter = parameterNames.iterator(); - BigDecimal oldQuantity = BigDecimal.ONE.negate(); String oldDescription = ""; BigDecimal oldPrice = BigDecimal.ONE.negate(); @@ -677,8 +664,7 @@ public class ShoppingCartHelper { } // TODO: This should be refactored to use UtilHttp.parseMultiFormData(parameters) - while (parameterNameIter.hasNext()) { - String parameterName = parameterNameIter.next(); + for(String parameterName : context.keySet()) { int underscorePos = parameterName.lastIndexOf('_'); if (underscorePos >= 0) { @@ -881,10 +867,7 @@ public class ShoppingCartHelper { } } - Iterator di = deleteList.iterator(); - - while (di.hasNext()) { - ShoppingCartItem item = di.next(); + for(ShoppingCartItem item : deleteList) { int itemIndex = this.cart.getItemIndex(item); if (Debug.infoOn()) diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java index 1f6f1016f4..dae651c129 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java @@ -1181,9 +1181,7 @@ public class ShoppingCartItem implements java.io.Serializable { if (UtilValidate.isNotEmpty(productSurvey) && UtilValidate.isNotEmpty(attributes)) { List surveyResponses = UtilGenerics.checkList(attributes.get("surveyResponses")); if (UtilValidate.isNotEmpty(surveyResponses)) { - Iterator surveyItr = surveyResponses.iterator(); - while (surveyItr.hasNext()) { - String surveyResponseId = surveyItr.next(); + for(String surveyResponseId : surveyResponses) { // TODO: implement multiple survey per product if (UtilValidate.isNotEmpty(surveyResponseId)) { priceContext.put("surveyResponseId", surveyResponseId); @@ -1860,17 +1858,13 @@ public class ShoppingCartItem implements java.io.Serializable { Debug.logError(e, "Unable to get features from product : " + product.get("productId"), module); } if (featureAppls != null) { - Iterator fai = featureAppls.iterator(); - while (fai.hasNext()) { - GenericValue appl = fai.next(); + for(GenericValue appl : featureAppls) { featureSet.add(appl.getString("productFeatureId")); } } } if (this.additionalProductFeatureAndAppls != null) { - Iterator aapi = this.additionalProductFeatureAndAppls.values().iterator(); - while (aapi.hasNext()) { - GenericValue appl = aapi.next(); + for(GenericValue appl : this.additionalProductFeatureAndAppls.values()) { featureSet.add(appl.getString("productFeatureId")); } } @@ -2111,9 +2105,7 @@ public class ShoppingCartItem implements java.io.Serializable { public void addAllProductFeatureAndAppls(Map productFeatureAndApplsToAdd) { if (productFeatureAndApplsToAdd == null) return; - Iterator productFeatureAndApplsToAddIter = productFeatureAndApplsToAdd.values().iterator(); - while (productFeatureAndApplsToAddIter.hasNext()) { - GenericValue additionalProductFeatureAndAppl = productFeatureAndApplsToAddIter.next(); + for (GenericValue additionalProductFeatureAndAppl : productFeatureAndApplsToAdd.values()) { this.putAdditionalProductFeatureAndAppl(additionalProductFeatureAndAppl); } } @@ -2187,9 +2179,7 @@ public class ShoppingCartItem implements java.io.Serializable { Debug.logError(e, "Unable to get features from product : " + product.get("productId"), module); } if (featureAppls != null) { - Iterator fai = featureAppls.iterator(); - while (fai.hasNext()) { - GenericValue appl = fai.next(); + for(GenericValue appl : featureAppls) { BigDecimal lastQuantity = featureMap.get(appl.getString("productFeatureId")); if (lastQuantity == null) { lastQuantity = BigDecimal.ZERO; @@ -2200,9 +2190,7 @@ public class ShoppingCartItem implements java.io.Serializable { } } if (this.additionalProductFeatureAndAppls != null) { - Iterator aapi = this.additionalProductFeatureAndAppls.values().iterator(); - while (aapi.hasNext()) { - GenericValue appl = aapi.next(); + for(GenericValue appl : this.additionalProductFeatureAndAppls.values()) { BigDecimal lastQuantity = featureMap.get(appl.getString("productFeatureId")); if (lastQuantity == null) { lastQuantity = BigDecimal.ZERO; @@ -2575,10 +2563,8 @@ public class ShoppingCartItem implements java.io.Serializable { } // add the cloned item(s) to the cart - Iterator newItemsItr = newItems.iterator(); - - while (newItemsItr.hasNext()) { - cart.addItem(thisIndex, newItemsItr.next()); + for(ShoppingCartItem sci : newItems) { + cart.addItem(thisIndex, sci); } } } diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java index df0719a509..1f5602d1f5 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java @@ -904,9 +904,7 @@ public class ShoppingCartServices { // The cart item adjustments, derived from quote item adjustments, are added to the cart if (quoteItems != null) { - Iterator i = cart.iterator(); - while (i.hasNext()) { - ShoppingCartItem item = i.next(); + for(ShoppingCartItem item : cart) { String orderItemSeqId = item.getOrderItemSeqId(); if (orderItemSeqId != null) { adjs = orderAdjsMap.get(orderItemSeqId); @@ -1108,10 +1106,8 @@ public class ShoppingCartServices { result.put("displayGrandTotalCurrencyFormatted",org.ofbiz.base.util.UtilFormatOut.formatCurrency(shoppingCart.getDisplayGrandTotal(), isoCode, locale)); BigDecimal orderAdjustmentsTotal = OrderReadHelper.calcOrderAdjustments(OrderReadHelper.getOrderHeaderAdjustments(shoppingCart.getAdjustments(), null), shoppingCart.getSubTotal(), true, true, true); result.put("displayOrderAdjustmentsTotalCurrencyFormatted", org.ofbiz.base.util.UtilFormatOut.formatCurrency(orderAdjustmentsTotal, isoCode, locale)); - Iterator i = shoppingCart.iterator(); Map cartItemData = FastMap.newInstance(); - while (i.hasNext()) { - ShoppingCartItem cartLine = i.next(); + for(ShoppingCartItem cartLine : shoppingCart) { int cartLineIndex = shoppingCart.getItemIndex(cartLine); cartItemData.put("displayItemQty_" + cartLineIndex, cartLine.getQuantity()); cartItemData.put("displayItemPrice_" + cartLineIndex, org.ofbiz.base.util.UtilFormatOut.formatCurrency(cartLine.getDisplayPrice(), isoCode, locale)); @@ -1142,9 +1138,7 @@ public class ShoppingCartServices { public static MapresetShipGroupItems(DispatchContext dctx, Map context) { Map result = ServiceUtil.returnSuccess(); ShoppingCart cart = (ShoppingCart) context.get("shoppingCart"); - Iterator sciIter = cart.iterator(); - while (sciIter.hasNext()) { - ShoppingCartItem item = sciIter.next(); + for(ShoppingCartItem item : cart) { cart.clearItemShipInfo(item); cart.setItemShipGroupQty(item, item.getQuantity(), 0); } @@ -1166,9 +1160,7 @@ public class ShoppingCartServices { return ServiceUtil.returnError(e.toString()); } Map vendorMap = FastMap.newInstance(); - Iterator sciIter = cart.iterator(); - while (sciIter.hasNext()) { - ShoppingCartItem item = sciIter.next(); + for(ShoppingCartItem item : cart) { GenericValue vendorProduct = null; String productId = item.getParentProductId(); if (productId == null) { diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java b/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java index b24fbfef62..b59c5998d8 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductDisplayWorker.java @@ -81,16 +81,12 @@ public class ProductDisplayWorker { List productsCategories = delegator.findByAndCache("ProductCategoryMember", UtilMisc.toMap("productId", item.getProductId()), null); productsCategories = EntityUtil.filterByDate(productsCategories, true); if (productsCategories != null) { - Iterator productsCategoriesIter = productsCategories.iterator(); - while (productsCategoriesIter.hasNext()) { - GenericValue productsCategoryMember = productsCategoriesIter.next(); + for(GenericValue productsCategoryMember : productsCategories) { GenericValue productsCategory = productsCategoryMember.getRelatedOneCache("ProductCategory"); if ("CROSS_SELL_CATEGORY".equals(productsCategory.getString("productCategoryTypeId"))) { List curPcms = productsCategory.getRelatedCache("ProductCategoryMember"); if (curPcms != null) { - Iterator curPcmsIter = curPcms.iterator(); - while (curPcmsIter.hasNext()) { - GenericValue curPcm = curPcmsIter.next(); + for(GenericValue curPcm : curPcms) { if (!products.containsKey(curPcm.getString("productId"))) { GenericValue product = curPcm.getRelatedOneCache("Product"); products.put(product.getString("productId"), product); @@ -102,9 +98,7 @@ public class ProductDisplayWorker { } if (UtilValidate.isNotEmpty(complementProducts)) { - Iterator complIter = complementProducts.iterator(); - while (complIter.hasNext()) { - GenericValue productAssoc = complIter.next(); + for(GenericValue productAssoc : complementProducts) { if (!products.containsKey(productAssoc.getString("productIdTo"))) { GenericValue product = productAssoc.getRelatedOneCache("AssocProduct"); products.put(product.getString("productId"), product); @@ -238,9 +232,7 @@ public class ProductDisplayWorker { // remove all products that are already in the cart ShoppingCart cart = (ShoppingCart) httpRequest.getSession().getAttribute("shoppingCart"); if (UtilValidate.isNotEmpty(cart)) { - Iterator cartiter = cart.iterator(); - while (cartiter.hasNext()) { - ShoppingCartItem item = cartiter.next(); + for(ShoppingCartItem item : cart) { String productId = item.getProductId(); products.remove(productId); productQuantities.remove(productId); diff --git a/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java b/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java index 462c6eb129..9763f5673e 100644 --- a/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java +++ b/applications/order/src/org/ofbiz/order/shoppingcart/product/ProductPromoWorker.java @@ -328,9 +328,7 @@ public class ProductPromoWorker { // before sorting split into two lists and sort each list; one list for promos that have a order total condition, and the other list for all promos that don't; then we'll always run the ones that have no condition on the order total first List> productPromoDiscountMapList = FastList.newInstance(); List> productPromoDiscountMapListOrderTotal = FastList.newInstance(); - Iterator productPromoIter = productPromoList.iterator(); - while (productPromoIter.hasNext()) { - GenericValue productPromo = productPromoIter.next(); + for(GenericValue productPromo : productPromoList) { Map productPromoDiscountMap = UtilGenerics.checkMap(UtilMisc.toMap("productPromo", productPromo, "totalDiscountAmount", cart.getProductPromoUseTotalDiscount(productPromo.getString("productPromoId")))); if (hasOrderTotalCondition(productPromo, delegator)) { productPromoDiscountMapListOrderTotal.add(productPromoDiscountMap); @@ -370,9 +368,7 @@ public class ProductPromoWorker { protected static boolean hasOrderTotalCondition(GenericValue productPromo, Delegator delegator) throws GenericEntityException { boolean hasOtCond = false; List productPromoConds = delegator.findByAndCache("ProductPromoCond", UtilMisc.toMap("productPromoId", productPromo.get("productPromoId")), UtilMisc.toList("productPromoCondSeqId")); - Iterator productPromoCondIter = productPromoConds.iterator(); - while (productPromoCondIter.hasNext()) { - GenericValue productPromoCond = productPromoCondIter.next(); + for(GenericValue productPromoCond : productPromoConds) { String inputParamEnumId = productPromoCond.getString("inputParamEnumId"); if ("PPIP_ORDER_TOTAL".equals(inputParamEnumId)) { hasOtCond = true; @@ -405,9 +401,7 @@ public class ProductPromoWorker { break; } - Iterator productPromoIter = productPromoList.iterator(); - while (productPromoIter.hasNext()) { - GenericValue productPromo = productPromoIter.next(); + for(GenericValue productPromo : productPromoList) { String productPromoId = productPromo.getString("productPromoId"); List productPromoRules = productPromo.getRelatedCache("ProductPromoRule", null, null); @@ -742,7 +736,7 @@ public class ProductPromoWorker { } protected static boolean runProductPromoRules(ShoppingCart cart, boolean cartChanged, Long useLimit, boolean requireCode, String productPromoCodeId, Long codeUseLimit, long maxUseLimit, - GenericValue productPromo, List productPromoRules, LocalDispatcher dispatcher, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException, UseLimitException { + GenericValue productPromo, List productPromoRules, LocalDispatcher dispatcher, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException, UseLimitException { String productPromoId = productPromo.getString("productPromoId"); while ((useLimit == null || useLimit.longValue() > cart.getProductPromoUseCount(productPromoId)) && (!requireCode || UtilValidate.isNotEmpty(productPromoCodeId)) && @@ -920,9 +914,7 @@ public class ProductPromoWorker { Set productIds = ProductPromoWorker.getPromoRuleCondProductIds(productPromoCond, delegator, nowTimestamp); List lineOrderedByBasePriceList = cart.getLineListOrderedByBasePrice(false); - Iterator lineOrderedByBasePriceIter = lineOrderedByBasePriceList.iterator(); - while (lineOrderedByBasePriceIter.hasNext()) { - ShoppingCartItem cartItem = lineOrderedByBasePriceIter.next(); + for(ShoppingCartItem cartItem : lineOrderedByBasePriceList) { // only include if it is in the productId Set for this check and if it is not a Promo (GWP) item GenericValue product = cartItem.getProduct(); String parentProductId = cartItem.getParentProductId(); @@ -1408,9 +1400,7 @@ public class ProductPromoWorker { if ("Y".equals(productPromoAction.get("useCartQuantity"))) { quantity = BigDecimal.ZERO; List used = getCartItemsUsed(cart, productPromoAction); - Iterator usedIt = used.iterator(); - while (usedIt.hasNext()) { - ShoppingCartItem item = usedIt.next(); + for(ShoppingCartItem item : used) { BigDecimal available = item.getPromoQuantityAvailable(); quantity = quantity.add(available).add(item.getPromoQuantityCandidateUseActionAndAllConds(productPromoAction)); item.addPromoQuantityCandidateUse(available, productPromoAction, false); @@ -1435,9 +1425,7 @@ public class ProductPromoWorker { if ("Y".equals(product.getString("isVirtual"))) { List productAssocs = EntityUtil.filterByDate(product.getRelatedCache("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("sequenceNum"))); - Iterator productAssocIter = productAssocs.iterator(); - while (productAssocIter.hasNext()) { - GenericValue productAssoc = productAssocIter.next(); + for(GenericValue productAssoc : productAssocs) { optionProductIds.add(productAssoc.getString("productIdTo")); } productId = null; @@ -1729,9 +1717,7 @@ public class ProductPromoWorker { Set productIds = ProductPromoWorker.getPromoRuleActionProductIds(productPromoAction, delegator, nowTimestamp); // go through the cart items and for each product that has a specialPromoPrice use that price - Iterator cartItemIter = cart.items().iterator(); - while (cartItemIter.hasNext()) { - ShoppingCartItem cartItem = cartItemIter.next(); + for(ShoppingCartItem cartItem : cart.items()) { String itemProductId = cartItem.getProductId(); if (UtilValidate.isEmpty(itemProductId)) { continue; @@ -1797,9 +1783,7 @@ public class ProductPromoWorker { protected static List getCartItemsUsed(ShoppingCart cart, GenericValue productPromoAction) { List cartItemsUsed = FastList.newInstance(); - Iterator cartItemsIter = cart.iterator(); - while (cartItemsIter.hasNext()) { - ShoppingCartItem cartItem = cartItemsIter.next(); + for(ShoppingCartItem cartItem : cart) { BigDecimal quantityUsed = cartItem.getPromoQuantityCandidateUseActionAndAllConds(productPromoAction); if (quantityUsed.compareTo(BigDecimal.ZERO) > 0) { cartItemsUsed.add(cartItem); @@ -1810,9 +1794,7 @@ public class ProductPromoWorker { protected static BigDecimal getCartItemsUsedTotalAmount(ShoppingCart cart, GenericValue productPromoAction) { BigDecimal totalAmount = BigDecimal.ZERO; - Iterator cartItemsIter = cart.iterator(); - while (cartItemsIter.hasNext()) { - ShoppingCartItem cartItem = cartItemsIter.next(); + for(ShoppingCartItem cartItem : cart) { BigDecimal quantityUsed = cartItem.getPromoQuantityCandidateUseActionAndAllConds(productPromoAction); if (quantityUsed.compareTo(BigDecimal.ZERO) > 0) { totalAmount = totalAmount.add(quantityUsed.multiply(cartItem.getBasePrice())); @@ -1994,9 +1976,7 @@ public class ProductPromoWorker { List productPromoProductsAction = FastList.newInstance(); List productPromoCategoriesAction = FastList.newInstance(); - Iterator productPromoProductsAllIter = productPromoProductsAll.iterator(); - while (productPromoProductsAllIter.hasNext()) { - GenericValue productPromoProduct = productPromoProductsAllIter.next(); + for(GenericValue productPromoProduct : productPromoProductsAll) { // if the rule id is null then this is a global promo one, so always include if (!"_NA_".equals(productPromoProduct.getString("productPromoCondSeqId")) || "_NA_".equals(productPromoProduct.getString("productPromoRuleId"))) { productPromoProductsCond.add(productPromoProduct); @@ -2005,9 +1985,7 @@ public class ProductPromoWorker { productPromoProductsAction.add(productPromoProduct); } } - Iterator productPromoCategoriesAllIter = productPromoCategoriesAll.iterator(); - while (productPromoCategoriesAllIter.hasNext()) { - GenericValue productPromoCategory = productPromoCategoriesAllIter.next(); + for(GenericValue productPromoCategory : productPromoCategoriesAll) { if (!"_NA_".equals(productPromoCategory.getString("productPromoCondSeqId")) || "_NA_".equals(productPromoCategory.getString("productPromoRuleId"))) { productPromoCategoriesCond.add(productPromoCategory); } @@ -2054,9 +2032,7 @@ public class ProductPromoWorker { Set productCategoryIds = FastSet.newInstance(); Map>> productCategoryGroupSetListMap = FastMap.newInstance(); - Iterator productPromoCategoryIter = productPromoCategories.iterator(); - while (productPromoCategoryIter.hasNext()) { - GenericValue productPromoCategory = productPromoCategoryIter.next(); + for(GenericValue productPromoCategory : productPromoCategories) { if (productPromoApplEnumId.equals(productPromoCategory.getString("productPromoApplEnumId"))) { Set tempCatIdSet = FastSet.newInstance(); if ("Y".equals(productPromoCategory.getString("includeSubCategories"))) { @@ -2104,17 +2080,13 @@ public class ProductPromoWorker { // now handle the productCategoryGroupSetListMap // if a set has more than one category (because of an include sub-cats) then do an or // all lists will have more than category because of the pre-pass that was done, so and them together - Iterator>>> pcgslmIter = productCategoryGroupSetListMap.entrySet().iterator(); - while (pcgslmIter.hasNext()) { - Map.Entry>> entry = pcgslmIter.next(); + for(Map.Entry>> entry : productCategoryGroupSetListMap.entrySet()) { List> catIdSetList = entry.getValue(); // get all productIds for this catIdSetList List> productIdSetList = FastList.newInstance(); - Iterator> cidslIter = catIdSetList.iterator(); - while (cidslIter.hasNext()) { + for(Set catIdSet : catIdSetList) { // make a Set of productIds including all ids from all categories - Set catIdSet = cidslIter.next(); Set groupProductIdSet = FastSet.newInstance(); getAllProductIds(catIdSet, groupProductIdSet, delegator, nowTimestamp, true); productIdSetList.add(groupProductIdSet); @@ -2123,9 +2095,7 @@ public class ProductPromoWorker { // now go through all productId sets and only include IDs that are in all sets // by definition if each id must be in all categories, then it must be in the first, so go through the first and drop each one that is not in all others Set firstProductIdSet = productIdSetList.remove(0); - Iterator> productIdSetIter = productIdSetList.iterator(); - while (productIdSetIter.hasNext()) { - Set productIdSet = productIdSetIter.next(); + for(Set productIdSet : productIdSetList) { firstProductIdSet.retainAll(productIdSet); } @@ -2161,15 +2131,11 @@ public class ProductPromoWorker { } protected static void getAllProductIds(Set productCategoryIdSet, Set productIdSet, Delegator delegator, Timestamp nowTimestamp, boolean include) throws GenericEntityException { - Iterator productCategoryIdIter = productCategoryIdSet.iterator(); - while (productCategoryIdIter.hasNext()) { - String productCategoryId = productCategoryIdIter.next(); + for(String productCategoryId : productCategoryIdSet) { // get all product category memebers, filter by date List productCategoryMembers = delegator.findByAndCache("ProductCategoryMember", UtilMisc.toMap("productCategoryId", productCategoryId)); productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, nowTimestamp); - Iterator productCategoryMemberIter = productCategoryMembers.iterator(); - while (productCategoryMemberIter.hasNext()) { - GenericValue productCategoryMember = productCategoryMemberIter.next(); + for(GenericValue productCategoryMember : productCategoryMembers) { String productId = productCategoryMember.getString("productId"); if (include) { productIdSet.add(productId); @@ -2182,9 +2148,7 @@ public class ProductPromoWorker { protected static void handleProductPromoProducts(Set productIds, List productPromoProducts, String productPromoApplEnumId) throws GenericEntityException { boolean include = !"PPPA_EXCLUDE".equals(productPromoApplEnumId); - Iterator productPromoProductIter = productPromoProducts.iterator(); - while (productPromoProductIter.hasNext()) { - GenericValue productPromoProduct = productPromoProductIter.next(); + for(GenericValue productPromoProduct : productPromoProducts) { if (productPromoApplEnumId.equals(productPromoProduct.getString("productPromoApplEnumId"))) { String productId = productPromoProduct.getString("productId"); if (include) { diff --git a/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListEvents.java b/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListEvents.java index 2d91b27d39..6aa21a85e6 100644 --- a/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListEvents.java +++ b/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListEvents.java @@ -20,7 +20,6 @@ package org.ofbiz.order.shoppinglist; import java.math.BigDecimal; import java.sql.Timestamp; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -228,9 +227,7 @@ public class ShoppingListEvents { // include all items of child lists if flagged to do so if (includeChild) { List childShoppingLists = shoppingList.getRelated("ChildShoppingList"); - Iterator ci = childShoppingLists.iterator(); - while (ci.hasNext()) { - GenericValue v = ci.next(); + for(GenericValue v : childShoppingLists) { List items = v.getRelated("ShoppingListItem"); shoppingListItems.addAll(items); } @@ -260,9 +257,7 @@ public class ShoppingListEvents { // add the items StringBuilder eventMessage = new StringBuilder(); - Iterator i = shoppingListItems.iterator(); - while (i.hasNext()) { - GenericValue shoppingListItem = i.next(); + for(GenericValue shoppingListItem : shoppingListItems) { String productId = shoppingListItem.getString("productId"); BigDecimal quantity = shoppingListItem.getBigDecimal("quantity"); Timestamp reservStart = shoppingListItem.getTimestamp("reservStart"); @@ -556,10 +551,8 @@ public class ShoppingListEvents { */ public static int makeListItemSurveyResp(Delegator delegator, GenericValue item, List surveyResps) throws GenericEntityException { if (UtilValidate.isNotEmpty(surveyResps)) { - Iterator i = surveyResps.iterator(); int count = 0; - while (i.hasNext()) { - String responseId = i.next(); + for(String responseId : surveyResps) { GenericValue listResp = delegator.makeValue("ShoppingListItemSurvey"); listResp.set("shoppingListId", item.getString("shoppingListId")); listResp.set("shoppingListItemSeqId", item.getString("shoppingListItemSeqId")); @@ -578,9 +571,7 @@ public class ShoppingListEvents { public static Map> getItemSurveyInfos(List items) { Map> surveyInfos = FastMap.newInstance(); if (UtilValidate.isNotEmpty(items)) { - Iterator itemIt = items.iterator(); - while (itemIt.hasNext()) { - GenericValue item = itemIt.next(); + for(GenericValue item : items) { String listId = item.getString("shoppingListId"); String itemId = item.getString("shoppingListItemSeqId"); surveyInfos.put(listId + "." + itemId, getItemSurveyInfo(item)); @@ -603,9 +594,7 @@ public class ShoppingListEvents { } if (UtilValidate.isNotEmpty(surveyResp)) { - Iterator respIt = surveyResp.iterator(); - while (respIt.hasNext()) { - GenericValue resp = respIt.next(); + for(GenericValue resp : surveyResp) { responseIds.add(resp.getString("surveyResponseId")); } } diff --git a/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java b/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java index db414782d4..d68905114b 100644 --- a/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java +++ b/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java @@ -20,7 +20,6 @@ package org.ofbiz.order.shoppinglist; import java.math.BigDecimal; import java.sql.Timestamp; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Date; @@ -326,11 +325,8 @@ public class ShoppingListServices { } List orderItems = orh.getOrderItems(); - Iterator i = orderItems.iterator(); - String productId = null; - while (i.hasNext()) { - GenericValue orderItem = i.next(); - productId = orderItem.getString("productId"); + for(GenericValue orderItem : orderItems) { + String productId = orderItem.getString("productId"); if (UtilValidate.isNotEmpty(productId)) { Map ctx = UtilMisc.toMap("userLogin", userLogin, "shoppingListId", shoppingListId, "productId", orderItem.get("productId"), "quantity", orderItem.get("quantity")); @@ -471,10 +467,8 @@ public class ShoppingListServices { } - Iterator i = items.iterator(); ProductConfigWrapper configWrapper = null; - while (i.hasNext()) { - GenericValue shoppingListItem = i.next(); + for(GenericValue shoppingListItem : items) { String productId = shoppingListItem.getString("productId"); BigDecimal quantity = shoppingListItem.getBigDecimal("quantity"); Timestamp reservStart = shoppingListItem.getTimestamp("reservStart"); @@ -565,9 +559,7 @@ public class ShoppingListServices { String orderId = (String) context.get("orderId"); try { List orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", orderId)); - Iterator iter = orderItems.iterator(); - while (iter.hasNext()) { - GenericValue orderItem = iter.next(); + for(GenericValue orderItem : orderItems) { String shoppingListId = orderItem.getString("shoppingListId"); String shoppingListItemSeqId = orderItem.getString("shoppingListItemSeqId"); if (UtilValidate.isNotEmpty(shoppingListId)) { diff --git a/applications/order/src/org/ofbiz/order/test/OrderTestServices.java b/applications/order/src/org/ofbiz/order/test/OrderTestServices.java index e680712653..f3c84d219a 100644 --- a/applications/order/src/org/ofbiz/order/test/OrderTestServices.java +++ b/applications/order/src/org/ofbiz/order/test/OrderTestServices.java @@ -19,7 +19,6 @@ package org.ofbiz.order.test; import java.math.BigDecimal; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -96,9 +95,7 @@ public class OrderTestServices { if (result.get("categoryMembers") != null) { List productCategoryMembers = UtilGenerics.checkList(result.get("categoryMembers")); if (productCategoryMembers != null) { - Iterator i = productCategoryMembers.iterator(); - while (i.hasNext()) { - GenericValue prodCatMemb = i.next(); + for(GenericValue prodCatMemb : productCategoryMembers) { if (prodCatMemb != null) { productsList.add(prodCatMemb.getString("productId")); } diff --git a/applications/order/src/org/ofbiz/order/thirdparty/zipsales/ZipSalesServices.java b/applications/order/src/org/ofbiz/order/thirdparty/zipsales/ZipSalesServices.java index 87fb6e5f39..47ec3d4ae6 100644 --- a/applications/order/src/org/ofbiz/order/thirdparty/zipsales/ZipSalesServices.java +++ b/applications/order/src/org/ofbiz/order/thirdparty/zipsales/ZipSalesServices.java @@ -362,13 +362,11 @@ public class ZipSalesServices { } if (ruleLookup != null) { - Iterator ruleIterator = ruleLookup.iterator(); - while (ruleIterator.hasNext()) { + for(GenericValue rule : ruleLookup) { if (!taxShipping) { // if we found an rule which passes no need to contine (all rules are ||) break; } - GenericValue rule = ruleIterator.next(); String idCode = rule.getString("idCode"); String taxable = rule.getString("taxable"); String condition = rule.getString("shipCond");