svn commit: r721986 [12/13] - in /ofbiz/branches/typecheckcleanup200810: applications/accounting/script/org/ofbiz/accounting/olap/ applications/order/entitydef/ applications/order/script/org/ofbiz/order/order/ applications/order/script/org/ofbiz/order/...

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

svn commit: r721986 [12/13] - in /ofbiz/branches/typecheckcleanup200810: applications/accounting/script/org/ofbiz/accounting/olap/ applications/order/entitydef/ applications/order/script/org/ofbiz/order/order/ applications/order/script/org/ofbiz/order/...

lektran
Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java Sun Nov 30 22:51:11 2008
@@ -88,13 +88,13 @@
         estimate.set("featurePercent", context.get("featurePercent"));
         estimate.set("featurePrice", context.get("featurePrice"));
         estimate.set("weightBreakId", context.get("weightBreakId"));
-        estimate.set("weightUnitPrice", (Double)context.get("wprice"));
+        estimate.set("weightUnitPrice", (BigDecimal)context.get("wprice"));
         estimate.set("weightUomId", context.get("wuom"));
         estimate.set("quantityBreakId", context.get("quantityBreakId"));
-        estimate.set("quantityUnitPrice", (Double)context.get("qprice"));
+        estimate.set("quantityUnitPrice", (BigDecimal)context.get("qprice"));
         estimate.set("quantityUomId", context.get("quom"));
         estimate.set("priceBreakId", context.get("priceBreakId"));
-        estimate.set("priceUnitPrice", (Double)context.get("pprice"));
+        estimate.set("priceUnitPrice", (BigDecimal)context.get("pprice"));
         estimate.set("priceUomId", context.get("puom"));
         storeAll.add(estimate);
 
@@ -162,11 +162,11 @@
 
     private static boolean applyQuantityBreak(Map context, Map result, List storeAll, GenericDelegator delegator,
                                               GenericValue estimate, String prefix, String breakType, String breakTypeString) {
-        Double min = (Double) context.get(prefix + "min");
-        Double max = (Double) context.get(prefix + "max");
+        BigDecimal min = (BigDecimal) context.get(prefix + "min");
+        BigDecimal max = (BigDecimal) context.get(prefix + "max");
         if (min != null || max != null) {
             if (min != null && max != null) {
-                if (min.doubleValue() <= max.doubleValue() || max.doubleValue() == 0) {
+                if (min.compareTo(max) <= 0 || max.compareTo(BigDecimal.ZERO) == 0) {
                     try {
                         String newSeqId = delegator.getNextSeqId("QuantityBreak");
                         GenericValue weightBreak = delegator.makeValue("QuantityBreak");
@@ -175,7 +175,7 @@
                         weightBreak.set("fromQuantity", min);
                         weightBreak.set("thruQuantity", max);
                         estimate.set(breakType + "BreakId", newSeqId);
-                        estimate.set(breakType + "UnitPrice", (Double) context.get(prefix + "price"));
+                        estimate.set(breakType + "UnitPrice", (BigDecimal) context.get(prefix + "price"));
                         if (context.containsKey(prefix + "uom")) {
                             estimate.set(breakType + "UomId", (String) context.get(prefix + "uom"));
                         }
@@ -218,22 +218,22 @@
         //Map shippableFeatureMap = (Map) context.get("shippableFeatureMap");
         //List shippableItemSizes = (List) context.get("shippableItemSizes");
 
-        Double shippableTotal = (Double) context.get("shippableTotal");
-        Double shippableQuantity = (Double) context.get("shippableQuantity");
-        Double shippableWeight = (Double) context.get("shippableWeight");
-        Double initialEstimateAmt = (Double) context.get("initialEstimateAmt");
+        BigDecimal shippableTotal = (BigDecimal) context.get("shippableTotal");
+        BigDecimal shippableQuantity = (BigDecimal) context.get("shippableQuantity");
+        BigDecimal shippableWeight = (BigDecimal) context.get("shippableWeight");
+        BigDecimal initialEstimateAmt = (BigDecimal) context.get("initialEstimateAmt");
 
         if (shippableTotal == null) {
-            shippableTotal = new Double(0.00);
+            shippableTotal = BigDecimal.ZERO;
         }
         if (shippableQuantity == null) {
-            shippableQuantity = new Double(0.00);
+            shippableQuantity = BigDecimal.ZERO;
         }
         if (shippableWeight == null) {
-            shippableWeight = new Double(0.00);
+            shippableWeight = BigDecimal.ZERO;
         }
         if (initialEstimateAmt == null) {
-            initialEstimateAmt = new Double(0.00);
+            initialEstimateAmt = BigDecimal.ZERO;
         }
 
         // get the ShipmentCostEstimate(s)
@@ -248,13 +248,13 @@
             return ServiceUtil.returnError("Unable to locate estimates from database");
         }
         if (estimates == null || estimates.size() < 1) {
-            if (initialEstimateAmt.doubleValue() == 0.00) {
+            if (initialEstimateAmt.compareTo(BigDecimal.ZERO) == 0) {
                 Debug.logWarning("Using the passed context : " + context, module);
                 Debug.logWarning("No shipping estimates found; the shipping amount returned is 0!", module);
             }
 
             Map respNow = ServiceUtil.returnSuccess();
-            respNow.put("shippingEstimateAmount", new Double(0.00));
+            respNow.put("shippingEstimateAmount", BigDecimal.ZERO);
             return respNow;
         }
 
@@ -331,41 +331,41 @@
 
                     if (wv != null) {
                         useWeight = true;
-                        double min = 0.0001;
-                        double max = 0.0001;
+                        BigDecimal min = BigDecimal.ONE.movePointLeft(4);
+                        BigDecimal max = BigDecimal.ONE.movePointLeft(4);
 
                         try {
-                            min = wv.getDouble("fromQuantity").doubleValue();
-                            max = wv.getDouble("thruQuantity").doubleValue();
+                            min = wv.getBigDecimal("fromQuantity");
+                            max = wv.getBigDecimal("thruQuantity");
                         } catch (Exception e) {
                         }
-                        if (shippableWeight.doubleValue() >= min && (max == 0 || shippableWeight.doubleValue() <= max))
+                        if (shippableWeight.compareTo(min) >= 0 && (max.compareTo(BigDecimal.ZERO) == 0 || shippableWeight.compareTo(max) <= 0))
                             weightValid = true;
                     }
                     if (qv != null) {
                         useQty = true;
-                        double min = 0.0001;
-                        double max = 0.0001;
+                        BigDecimal min = BigDecimal.ONE.movePointLeft(4);
+                        BigDecimal max = BigDecimal.ONE.movePointLeft(4);
 
                         try {
-                            min = qv.getDouble("fromQuantity").doubleValue();
-                            max = qv.getDouble("thruQuantity").doubleValue();
+                            min = qv.getBigDecimal("fromQuantity");
+                            max = qv.getBigDecimal("thruQuantity");
                         } catch (Exception e) {
                         }
-                        if (shippableQuantity.doubleValue() >= min && (max == 0 || shippableQuantity.doubleValue() <= max))
+                        if (shippableQuantity.compareTo(min) >= 0 && (max.compareTo(BigDecimal.ZERO) == 0 || shippableQuantity.compareTo(max) <= 0))
                             qtyValid = true;
                     }
                     if (pv != null) {
                         usePrice = true;
-                        double min = 0.0001;
-                        double max = 0.0001;
+                        BigDecimal min = BigDecimal.ONE.movePointLeft(4);
+                        BigDecimal max = BigDecimal.ONE.movePointLeft(4);
 
                         try {
-                            min = pv.getDouble("fromQuantity").doubleValue();
-                            max = pv.getDouble("thruQuantity").doubleValue();
+                            min = pv.getBigDecimal("fromQuantity");
+                            max = pv.getBigDecimal("thruQuantity");
                         } catch (Exception e) {
                         }
-                        if (shippableTotal.doubleValue() >= min && (max == 0 || shippableTotal.doubleValue() <= max))
+                        if (shippableTotal.compareTo(min) >= 0 && (max.compareTo(BigDecimal.ZERO) == 0 || shippableTotal.compareTo(max) <= 0))
                             priceValid = true;
                     }
                     // Now check the tests.
@@ -389,23 +389,23 @@
                 Map itemMap = (Map) sii.next();
 
                 // add the item sizes
-                Double itemSize = (Double) itemMap.get("size");
+                BigDecimal itemSize = (BigDecimal) itemMap.get("size");
                 if (itemSize != null) {
                     shippableItemSizes.add(itemSize);
                 }
 
                 // add the feature quantities
-                Double quantity = (Double) itemMap.get("quantity");
+                BigDecimal quantity = (BigDecimal) itemMap.get("quantity");
                 Set featureSet = (Set) itemMap.get("featureSet");
                 if (UtilValidate.isNotEmpty(featureSet)) {
                     Iterator fi = featureSet.iterator();
                     while (fi.hasNext()) {
                         String featureId = (String) fi.next();
-                        Double featureQuantity = (Double) shippableFeatureMap.get(featureId);
+                        BigDecimal featureQuantity = (BigDecimal) shippableFeatureMap.get(featureId);
                         if (featureQuantity == null) {
-                            featureQuantity = new Double(0.00);
+                            featureQuantity = BigDecimal.ZERO;
                         }
-                        featureQuantity = new Double(featureQuantity.doubleValue() + quantity.doubleValue());
+                        featureQuantity = featureQuantity.add(quantity);
                         shippableFeatureMap.put(featureId, featureQuantity);
                     }
                 }
@@ -459,61 +459,61 @@
         //Debug.log("[ShippingEvents.getShipEstimate] Working with estimate [" + estimateIndex + "]: " + estimate, module);
 
         // flat fees
-        double orderFlat = 0.00;
-        if (estimate.getDouble("orderFlatPrice") != null)
-            orderFlat = estimate.getDouble("orderFlatPrice").doubleValue();
-
-        double orderItemFlat = 0.00;
-        if (estimate.getDouble("orderItemFlatPrice") != null)
-            orderItemFlat = estimate.getDouble("orderItemFlatPrice").doubleValue();
-
-        double orderPercent = 0.00;
-        if (estimate.getDouble("orderPricePercent") != null)
-            orderPercent = estimate.getDouble("orderPricePercent").doubleValue();
+        BigDecimal orderFlat = BigDecimal.ZERO;
+        if (estimate.getBigDecimal("orderFlatPrice") != null)
+            orderFlat = estimate.getBigDecimal("orderFlatPrice");
+
+        BigDecimal orderItemFlat = BigDecimal.ZERO;
+        if (estimate.getBigDecimal("orderItemFlatPrice") != null)
+            orderItemFlat = estimate.getBigDecimal("orderItemFlatPrice");
+
+        BigDecimal orderPercent = BigDecimal.ZERO;
+        if (estimate.getBigDecimal("orderPricePercent") != null)
+            orderPercent = estimate.getBigDecimal("orderPricePercent");
 
-        double itemFlatAmount = shippableQuantity.doubleValue() * orderItemFlat;
-        double orderPercentage = shippableTotal.doubleValue() * (orderPercent / 100);
+        BigDecimal itemFlatAmount = shippableQuantity.multiply(orderItemFlat);
+        BigDecimal orderPercentage = shippableTotal.multiply(orderPercent.movePointLeft(2));
 
         // flat total
-        double flatTotal = orderFlat + itemFlatAmount + orderPercentage;        
+        BigDecimal flatTotal = orderFlat.add(itemFlatAmount).add(orderPercentage);        
 
         // spans
-        double weightUnit = 0.00;
-        if (estimate.getDouble("weightUnitPrice") != null)
-            weightUnit = estimate.getDouble("weightUnitPrice").doubleValue();
-
-        double qtyUnit = 0.00;
-        if (estimate.getDouble("quantityUnitPrice") != null)
-            qtyUnit = estimate.getDouble("quantityUnitPrice").doubleValue();
-
-        double priceUnit = 0.00;
-        if (estimate.getDouble("priceUnitPrice") != null)
-            priceUnit = estimate.getDouble("priceUnitPrice").doubleValue();
-
-        double weightAmount = shippableWeight.doubleValue() * weightUnit;
-        double quantityAmount = shippableQuantity.doubleValue() * qtyUnit;
-        double priceAmount = shippableTotal.doubleValue() * priceUnit;
+        BigDecimal weightUnit = BigDecimal.ZERO;
+        if (estimate.getBigDecimal("weightUnitPrice") != null)
+            weightUnit = estimate.getBigDecimal("weightUnitPrice");
+
+        BigDecimal qtyUnit = BigDecimal.ZERO;
+        if (estimate.getBigDecimal("quantityUnitPrice") != null)
+            qtyUnit = estimate.getBigDecimal("quantityUnitPrice");
+
+        BigDecimal priceUnit = BigDecimal.ZERO;
+        if (estimate.getBigDecimal("priceUnitPrice") != null)
+            priceUnit = estimate.getBigDecimal("priceUnitPrice");
+
+        BigDecimal weightAmount = shippableWeight.multiply(weightUnit);
+        BigDecimal quantityAmount = shippableQuantity.multiply(qtyUnit);
+        BigDecimal priceAmount = shippableTotal.multiply(priceUnit);
 
         // span total
-        double spanTotal = weightAmount + quantityAmount + priceAmount;
+        BigDecimal spanTotal = weightAmount.add(quantityAmount).add(priceAmount);
 
         // feature surcharges
-        double featureSurcharge = 0.00;
+        BigDecimal featureSurcharge = BigDecimal.ZERO;
         String featureGroupId = estimate.getString("productFeatureGroupId");
-        Double featurePercent = estimate.getDouble("featurePercent");
-        Double featurePrice = estimate.getDouble("featurePrice");
+        BigDecimal featurePercent = estimate.getBigDecimal("featurePercent");
+        BigDecimal featurePrice = estimate.getBigDecimal("featurePrice");
         if (featurePercent == null) {
-            featurePercent = new Double(0);
+            featurePercent = BigDecimal.ZERO;
         }
         if (featurePrice == null) {
-            featurePrice = new Double(0.00);
+            featurePrice = BigDecimal.ZERO;
         }
 
         if (featureGroupId != null && featureGroupId.length() > 0 && shippableFeatureMap != null) {
             Iterator fii = shippableFeatureMap.keySet().iterator();
             while (fii.hasNext()) {
                 String featureId = (String) fii.next();
-                Double quantity = (Double) shippableFeatureMap.get(featureId);
+                BigDecimal quantity = (BigDecimal) shippableFeatureMap.get(featureId);
                 GenericValue appl = null;
                 Map fields = UtilMisc.toMap("productFeatureGroupId", featureGroupId, "productFeatureId", featureId);
                 try {
@@ -524,45 +524,45 @@
                     Debug.logError(e, "Unable to lookup feature/group" + fields, module);
                 }
                 if (appl != null) {
-                    featureSurcharge += (shippableTotal.doubleValue() * (featurePercent.doubleValue() / 100) * quantity.doubleValue());
-                    featureSurcharge += featurePrice.doubleValue() * quantity.doubleValue();
+                    featureSurcharge = featureSurcharge.add( shippableTotal.multiply( featurePercent.movePointLeft(2) ).multiply(quantity) );
+                    featureSurcharge = featureSurcharge.add(featurePrice.multiply(quantity));
                 }
             }
         }
 
         // size surcharges
-        double sizeSurcharge = 0.00;
-        Double sizeUnit = estimate.getDouble("oversizeUnit");
-        Double sizePrice = estimate.getDouble("oversizePrice");
-        if (sizeUnit != null && sizeUnit.doubleValue() > 0) {
+        BigDecimal sizeSurcharge = BigDecimal.ZERO;
+        BigDecimal sizeUnit = estimate.getBigDecimal("oversizeUnit");
+        BigDecimal sizePrice = estimate.getBigDecimal("oversizePrice");
+        if (sizeUnit != null && sizeUnit.compareTo(BigDecimal.ZERO) > 0) {
             if (shippableItemSizes != null) {
                 Iterator isi = shippableItemSizes.iterator();
                 while (isi.hasNext()) {
-                    Double size = (Double) isi.next();
-                    if (size != null && size.doubleValue() >= sizeUnit.doubleValue()) {
-                        sizeSurcharge += sizePrice.doubleValue();
+                 BigDecimal size = (BigDecimal) isi.next();
+                    if (size != null && size.compareTo(sizeUnit) >= 0) {
+                        sizeSurcharge = sizeSurcharge.add(sizePrice);
                     }
                 }
             }
         }
 
         // surcharges total
-        double surchargeTotal = featureSurcharge + sizeSurcharge;
+        BigDecimal surchargeTotal = featureSurcharge.add(sizeSurcharge);
 
         // shipping subtotal
-        double subTotal = spanTotal + flatTotal + surchargeTotal;
+        BigDecimal subTotal = spanTotal.add(flatTotal).add(surchargeTotal);
 
         // percent add-on
-        double shippingPricePercent = 0.00;
-        if (estimate.getDouble("shippingPricePercent") != null)
-            shippingPricePercent = estimate.getDouble("shippingPricePercent").doubleValue();
+        BigDecimal shippingPricePercent = BigDecimal.ZERO;
+        if (estimate.getBigDecimal("shippingPricePercent") != null)
+            shippingPricePercent = estimate.getBigDecimal("shippingPricePercent");
 
         // shipping total
-        double shippingTotal = subTotal + ((subTotal + initialEstimateAmt.doubleValue()) * (shippingPricePercent / 100));
+        BigDecimal shippingTotal = subTotal.add((subTotal.add(initialEstimateAmt)).multiply(shippingPricePercent.movePointLeft(2)));
 
         // prepare the return result
         Map responseResult = ServiceUtil.returnSuccess();
-        responseResult.put("shippingEstimateAmount", new Double(shippingTotal));
+        responseResult.put("shippingEstimateAmount", shippingTotal);
         return responseResult;
     }
 
@@ -880,9 +880,9 @@
             Iterator iter = shipmentAndItems.iterator();
             while (iter.hasNext()) {
                 GenericValue item = (GenericValue) iter.next();
-                double shippedQuantity = item.getDouble("quantity").doubleValue();
-                Double quantity = (Double) shippedCountMap.get(item.getString("productId"));
-                quantity = new Double(quantity == null ? shippedQuantity : shippedQuantity + quantity.doubleValue());
+                BigDecimal shippedQuantity = item.getBigDecimal("quantity");
+                BigDecimal quantity = (BigDecimal) shippedCountMap.get(item.getString("productId"));
+                quantity = quantity == null ? shippedQuantity : shippedQuantity.add(quantity);
                 shippedCountMap.put(item.getString("productId"), quantity);
             }
 
@@ -891,9 +891,9 @@
             iter = shipmentReceipts.iterator();
             while (iter.hasNext()) {
                 GenericValue item = (GenericValue) iter.next();
-                double receivedQuantity = item.getDouble("quantityAccepted").doubleValue();
-                Double quantity = (Double) receivedCountMap.get(item.getString("productId"));
-                quantity = new Double(quantity == null ? receivedQuantity : receivedQuantity + quantity.doubleValue());
+                BigDecimal receivedQuantity = item.getBigDecimal("quantityAccepted");
+                BigDecimal quantity = (BigDecimal) receivedCountMap.get(item.getString("productId"));
+                quantity = quantity == null ? receivedQuantity : receivedQuantity.add(quantity);
                 receivedCountMap.put(item.getString("productId"), quantity);
             }
 
@@ -1054,10 +1054,10 @@
             
                 // Convert the value to the shipment currency, if necessary
                 GenericValue orderHeader = packageContent.getRelatedOne("OrderHeader");
-                Map convertUomResult = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", orderHeader.getString("currencyUom"), "uomIdTo", currencyUomId, "originalValue", new Double(packageContentValue.doubleValue())));
+                Map convertUomResult = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", orderHeader.getString("currencyUom"), "uomIdTo", currencyUomId, "originalValue", packageContentValue));
                 if (ServiceUtil.isError(convertUomResult)) return convertUomResult;
                 if (convertUomResult.containsKey("convertedValue")) {
-                    packageContentValue = new BigDecimal(((Double) convertUomResult.get("convertedValue")).doubleValue()).setScale(decimals, rounding);
+                    packageContentValue = ((BigDecimal) convertUomResult.get("convertedValue")).setScale(decimals, rounding);
                 }
                 
                 // Add the value of the packed item to the package's total value

Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/dhl/DhlServices.java Sun Nov 30 22:51:11 2008
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -157,9 +158,9 @@
         String shipmentMethodTypeId = (String) context.get("shipmentMethodTypeId");
         String shippingContactMechId = (String) context.get("shippingContactMechId");
         List shippableItemInfo = (List) context.get("shippableItemInfo");
-        Double shippableTotal = (Double) context.get("shippableTotal");
-        Double shippableQuantity = (Double) context.get("shippableQuantity");
-        Double shippableWeight = (Double) context.get("shippableWeight");
+        BigDecimal shippableTotal = (BigDecimal) context.get("shippableTotal");
+        BigDecimal shippableQuantity = (BigDecimal) context.get("shippableQuantity");
+        BigDecimal shippableWeight = (BigDecimal) context.get("shippableWeight");
         
         if (shipmentMethodTypeId.equals("NO_SHIPPING")) {
             Map result = ServiceUtil.returnSuccess();
@@ -203,11 +204,11 @@
             }
         }
 
-        if ((shippableWeight == null) || (shippableWeight.doubleValue() <= 0.0)) {
+        if ((shippableWeight == null) || (shippableWeight.compareTo(BigDecimal.ZERO) <= 0)) {
             String tmpValue = UtilProperties.getPropertyValue(shipmentPropertiesFile, "shipment.default.weight.value");
             if (tmpValue != null) {
                 try {
-                    shippableWeight = new Double(tmpValue);
+                    shippableWeight = new BigDecimal(tmpValue);
                 } catch (Exception e) {
                     return ServiceUtil.returnError("Cannot get DHL Estimate: Default shippable weight not configured (shipment.default.weight.value)");
                 }
@@ -215,11 +216,11 @@
         }
 
         // TODO: if a weight UOM is passed in, use convertUom service to convert it here
-        if (shippableWeight.doubleValue() < 1.0) {
+        if (shippableWeight.compareTo(BigDecimal.ONE) < 0) {
             Debug.logWarning("DHL Estimate: Weight is less than 1 lb, submitting DHL minimum of 1 lb for estimate.", module);
-            shippableWeight = new Double(1.0);
+            shippableWeight = BigDecimal.ONE;
         }
-        if ((dhlShipmentDetailCode.equals("G") && shippableWeight.doubleValue() > 999) || (shippableWeight.doubleValue() > 150)) {
+        if ((dhlShipmentDetailCode.equals("G") && shippableWeight.compareTo(new BigDecimal("999")) > 0) || (shippableWeight.compareTo(new BigDecimal("150")) > 0)) {
             return ServiceUtil.returnError("Cannot get DHL Estimate: Shippable weight cannot be greater than 999 lbs for ground or 150 lbs for all other services.");
         }
         String weight = (new Integer((int) shippableWeight.longValue())).toString();
@@ -363,7 +364,7 @@
                 chargeList.add(charge);
             }
         }
-        Double shippingEstimateAmount = new Double(responseTotalChargeEstimate);
+        BigDecimal shippingEstimateAmount = new BigDecimal(responseTotalChargeEstimate);
         dhlRateCodeMap.put("dateGenerated", dateGenerated);
         dhlRateCodeMap.put("serviceLevelCommitment",
                 responseServiceLevelCommitmentDescription);
@@ -587,9 +588,9 @@
 
             // get the weight from the ShipmentRouteSegment first, which overrides all later weight computations
             boolean hasBillingWeight = false;  // for later overrides
-            Double billingWeight = shipmentRouteSegment.getDouble("billingWeight");
+            BigDecimal billingWeight = shipmentRouteSegment.getBigDecimal("billingWeight");
             String billingWeightUomId = shipmentRouteSegment.getString("billingWeightUomId");
-            if ((billingWeight != null) && (billingWeight.doubleValue() > 0)) {
+            if ((billingWeight != null) && (billingWeight.compareTo(BigDecimal.ZERO) > 0)) {
                 hasBillingWeight = true;
                 if (billingWeightUomId == null) {
                     Debug.logWarning("Shipment Route Segment missing billingWeightUomId in shipmentId " + shipmentId,  module);
@@ -602,7 +603,7 @@
                     // try getting the weight from package instead
                     hasBillingWeight = false;
                 } else {
-                    billingWeight = (Double) results.get("convertedValue");
+                    billingWeight = (BigDecimal) results.get("convertedValue");
                 }
             }
 
@@ -610,7 +611,7 @@
             String length = null;
             String width = null;
             String height = null;
-            Double packageWeight = null;
+            BigDecimal packageWeight = null;
             Iterator shipmentPackageRouteSegIter = shipmentPackageRouteSegs.iterator();
             while (shipmentPackageRouteSegIter.hasNext()) {
                 GenericValue shipmentPackageRouteSeg = (GenericValue) shipmentPackageRouteSegIter.next();
@@ -635,14 +636,14 @@
 
                 // compute total packageWeight (for now, just one package)
                 if (shipmentPackage.getString("weight") != null) {
-                    packageWeight = Double.valueOf(shipmentPackage.getString("weight"));
+                    packageWeight = new BigDecimal(shipmentPackage.getString("weight"));
                 } else {
                     // use default weight if available
                     try {
-                        packageWeight = Double.valueOf(UtilProperties.getPropertyValue(shipmentPropertiesFile, "shipment.default.weight.value"));
+                        packageWeight = new BigDecimal(UtilProperties.getPropertyValue(shipmentPropertiesFile, "shipment.default.weight.value"));
                     } catch (NumberFormatException ne) {
                         Debug.logWarning("Default shippable weight not configured (shipment.default.weight.value)", module);
-                        packageWeight = new Double(1.0);
+                        packageWeight = BigDecimal.ONE;
                     }
                 }
                 // convert weight
@@ -654,21 +655,21 @@
                 results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", DHL_WEIGHT_UOM_ID, "originalValue", packageWeight));
                 if ((results == null) || (results.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR)) || (results.get("convertedValue") == null)) {
                     Debug.logWarning("Unable to convert weights for shipmentId " + shipmentId , module);
-                    packageWeight = new Double(1.0);
+                    packageWeight = BigDecimal.ONE;
                 } else {
-                    packageWeight = (Double) results.get("convertedValue");
+                    packageWeight = (BigDecimal) results.get("convertedValue");
                 }
             }
 
             // pick which weight to use and round it
-            Double weight = null;
+            BigDecimal weight = null;
             if (hasBillingWeight) {
                 weight = billingWeight;
             } else {
                 weight = packageWeight;
             }
             // want the rounded weight as a string, so we use the "" + int shortcut
-            String roundedWeight = "" + Math.round(weight.doubleValue());
+            String roundedWeight = weight.setScale(0, BigDecimal.ROUND_HALF_UP).toPlainString();
             
             // translate shipmentMethodTypeId to DHL service code
             String shipmentMethodTypeId = shipmentRouteSegment.getString("shipmentMethodTypeId");
@@ -841,14 +842,14 @@
         return ServiceUtil.returnSuccess("DHL Shipment Confirmed.");
     }
 
-    private static double getWeight(List shippableItemInfo) {
-        double totalWeight = 0;
+    private static BigDecimal getWeight(List shippableItemInfo) {
+        BigDecimal totalWeight = BigDecimal.ZERO;
         if (shippableItemInfo != null) {
             Iterator sii = shippableItemInfo.iterator();
             while (sii.hasNext()) {
                 Map itemInfo = (Map) sii.next();
-                double weight = ((Double) itemInfo.get("weight")).doubleValue();
-                totalWeight = totalWeight + weight;
+                BigDecimal weight = ((BigDecimal) itemInfo.get("weight"));
+                totalWeight = totalWeight.add(weight);
             }
         }
         return totalWeight;

Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/fedex/FedexServices.java Sun Nov 30 22:51:11 2008
@@ -661,9 +661,9 @@
 
             // Get the weight from the ShipmentRouteSegment first, which overrides all later weight computations
             boolean hasBillingWeight = false;
-            Double billingWeight = shipmentRouteSegment.getDouble("billingWeight");
+            BigDecimal billingWeight = shipmentRouteSegment.getBigDecimal("billingWeight");
             String billingWeightUomId = shipmentRouteSegment.getString("billingWeightUomId");
-            if ((billingWeight != null) && (billingWeight.doubleValue() > 0)) {
+            if ((billingWeight != null) && (billingWeight.compareTo(BigDecimal.ZERO) > 0)) {
                 hasBillingWeight = true;
                 if (billingWeightUomId == null) {
                     Debug.logWarning("Shipment Route Segment missing billingWeightUomId in shipmentId " + shipmentId + ", assuming default shipment.fedex.weightUomId of " + weightUomId + " from " + shipmentPropertiesFile,  module);
@@ -679,7 +679,7 @@
                         // Try getting the weight from package instead
                         hasBillingWeight = false;
                     } else {
-                        billingWeight = (Double) results.get("convertedValue");
+                        billingWeight = (BigDecimal) results.get("convertedValue");
                     }
                 }
             }
@@ -716,13 +716,13 @@
                 packaging = carrierShipmentBoxType.getString("packagingTypeCode");
                 
                 // Determine the dimensions of the package
-                Double dimensionsLength = null;
-                Double dimensionsWidth = null;
-                Double dimensionsHeight = null;
+                BigDecimal dimensionsLength = null;
+                BigDecimal dimensionsWidth = null;
+                BigDecimal dimensionsHeight = null;
                 if (shipmentBoxType != null) {
-                    dimensionsLength = shipmentBoxType.getDouble("boxLength");
-                    dimensionsWidth = shipmentBoxType.getDouble("boxWidth");
-                    dimensionsHeight = shipmentBoxType.getDouble("boxHeight");
+                    dimensionsLength = shipmentBoxType.getBigDecimal("boxLength");
+                    dimensionsWidth = shipmentBoxType.getBigDecimal("boxWidth");
+                    dimensionsHeight = shipmentBoxType.getBigDecimal("boxHeight");
 
                     String boxDimensionsUomId = null;
                     GenericValue boxDimensionsUom = shipmentBoxType.getRelatedOne("DimensionUom");
@@ -732,38 +732,38 @@
                         Debug.logWarning("Packaging type for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId + " is missing dimensionUomId, assuming default shipment.default.dimension.uom of " + dimensionsUomId + " from " + shipmentPropertiesFile,  module);
                         boxDimensionsUomId = dimensionsUomId;
                     }
-                    if (dimensionsLength != null && dimensionsLength.doubleValue() > 0) {
+                    if (dimensionsLength != null && dimensionsLength.compareTo(BigDecimal.ZERO) > 0) {
                         if (! boxDimensionsUomId.equals(dimensionsUomId)) {
                             Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsLength));
                             if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) {
                                 Debug.logWarning("Unable to convert length for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId , module);
                                 dimensionsLength = null;
                             } else {
-                                dimensionsLength = (Double) results.get("convertedValue");
+                                dimensionsLength = (BigDecimal) results.get("convertedValue");
                             }
                         }
                         
                     }
-                    if (dimensionsWidth != null && dimensionsWidth.doubleValue() > 0) {
+                    if (dimensionsWidth != null && dimensionsWidth.compareTo(BigDecimal.ZERO) > 0) {
                         if (! boxDimensionsUomId.equals(dimensionsUomId)) {
                             Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsWidth));
                             if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) {
                                 Debug.logWarning("Unable to convert width for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId , module);
                                 dimensionsWidth = null;
                             } else {
-                                dimensionsWidth = (Double) results.get("convertedValue");
+                                dimensionsWidth = (BigDecimal) results.get("convertedValue");
                             }
                         }
                         
                     }
-                    if (dimensionsHeight != null && dimensionsHeight.doubleValue() > 0) {
+                    if (dimensionsHeight != null && dimensionsHeight.compareTo(BigDecimal.ZERO) > 0) {
                         if (! boxDimensionsUomId.equals(dimensionsUomId)) {
                             Map results = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", boxDimensionsUomId, "uomIdTo", dimensionsUomId, "originalValue", dimensionsHeight));
                             if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) {
                                 Debug.logWarning("Unable to convert height for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId , module);
                                 dimensionsHeight = null;
                             } else {
-                                dimensionsHeight = (Double) results.get("convertedValue");
+                                dimensionsHeight = (BigDecimal) results.get("convertedValue");
                             }
                         }
                         
@@ -771,18 +771,18 @@
                 }
 
                 // Determine the package weight (possibly overriden by route segment billing weight)
-                Double packageWeight = null;
+                BigDecimal packageWeight = null;
                 if (! hasBillingWeight) {
                     if (UtilValidate.isNotEmpty(shipmentPackage.getString("weight"))) {
-                        packageWeight = shipmentPackage.getDouble("weight");
+                        packageWeight = shipmentPackage.getBigDecimal("weight");
                     } else {
 
                         // Use default weight if available
                         try {
-                            packageWeight = Double.valueOf(UtilProperties.getPropertyValue(shipmentPropertiesFile, "shipment.default.weight.value"));
+                            packageWeight = new BigDecimal(UtilProperties.getPropertyValue(shipmentPropertiesFile, "shipment.default.weight.value"));
                         } catch (NumberFormatException ne) {
                             Debug.logWarning("Default shippable weight not configured (shipment.default.weight.value), assuming 1.0" + weightUomId , module);
-                            packageWeight = new Double(1.0);
+                            packageWeight = BigDecimal.ONE;
                         }
                     }
                     
@@ -797,12 +797,12 @@
                         if (ServiceUtil.isError(results) || (results.get("convertedValue") == null)) {
                             ServiceUtil.returnError("Unable to convert weight for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId);
                         } else {
-                            packageWeight = (Double) results.get("convertedValue");
+                            packageWeight = (BigDecimal) results.get("convertedValue");
                         }
                     }
                 }
-                Double weight = hasBillingWeight ? billingWeight : packageWeight;
-                if (weight == null || weight.doubleValue() < 0) {
+                BigDecimal weight = hasBillingWeight ? billingWeight : packageWeight;
+                if (weight == null || weight.compareTo(BigDecimal.ZERO) < 0) {
                     ServiceUtil.returnError("Unable to determine weight for package " + shipmentPackage.getString("shipmentPackageSeqId") + " of shipmentRouteSegment " + shipmentRouteSegmentId + " of shipment " + shipmentId);
                 }
                 
@@ -811,15 +811,15 @@
                 shipRequestContext.put("DropoffType", dropoffType);
                 shipRequestContext.put("Packaging", packaging);
                 if (UtilValidate.isNotEmpty(dimensionsUomId) &&
-                    dimensionsLength != null && Math.round(dimensionsLength.doubleValue()) > 0 &&
-                    dimensionsWidth != null && Math.round(dimensionsWidth.doubleValue()) > 0   &&
-                    dimensionsHeight != null && Math.round(dimensionsHeight.doubleValue()) > 0 ) {
+                    dimensionsLength != null && dimensionsLength.setScale(0, BigDecimal.ROUND_HALF_UP).compareTo(BigDecimal.ZERO) > 0 &&
+                    dimensionsWidth != null && dimensionsWidth.setScale(0, BigDecimal.ROUND_HALF_UP).compareTo(BigDecimal.ZERO) > 0   &&
+                    dimensionsHeight != null && dimensionsHeight.setScale(0, BigDecimal.ROUND_HALF_UP).compareTo(BigDecimal.ZERO) > 0 ) {
                         shipRequestContext.put("DimensionsUnits", dimensionsUomId.equals("LEN_in") ? "IN" : "CM");
-                        shipRequestContext.put("DimensionsLength", "" + Math.round(dimensionsLength.doubleValue()));
-                        shipRequestContext.put("DimensionsWidth", "" + Math.round(dimensionsWidth.doubleValue()));
-                        shipRequestContext.put("DimensionsHeight", "" + Math.round(dimensionsHeight.doubleValue()));
+                        shipRequestContext.put("DimensionsLength", dimensionsLength.setScale(0, BigDecimal.ROUND_HALF_UP).toString());
+                        shipRequestContext.put("DimensionsWidth", dimensionsWidth.setScale(0, BigDecimal.ROUND_HALF_UP).toString());
+                        shipRequestContext.put("DimensionsHeight", dimensionsHeight.setScale(0, BigDecimal.ROUND_HALF_UP).toString());
                 }
-                shipRequestContext.put("Weight", new BigDecimal(weight.doubleValue()).setScale(1, BigDecimal.ROUND_UP).toString());
+                shipRequestContext.put("Weight", weight.setScale(1, BigDecimal.ROUND_UP).toString());
             }
         
             StringWriter outWriter = new StringWriter();

Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java Sun Nov 30 22:51:11 2008
@@ -22,6 +22,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.math.MathContext;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -82,6 +83,7 @@
     }
     public static final int decimals = UtilNumber.getBigDecimalScale("order.decimals");
     public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");
+    public static final MathContext generalRounding = new MathContext(10);
 
     public static Map upsShipmentConfirm(DispatchContext dctx, Map context) {
         Map result = new HashMap();
@@ -430,9 +432,9 @@
                         // I guess we'll default to inches...
                         UtilXml.addChildElementValue(unitOfMeasurementElement, "Code", "IN", shipmentConfirmRequestDoc);
                     }
-                    Double boxLength = shipmentBoxType.getDouble("boxLength");
-                    Double boxWidth = shipmentBoxType.getDouble("boxWidth");
-                    Double boxHeight = shipmentBoxType.getDouble("boxHeight");
+                    BigDecimal boxLength = shipmentBoxType.getBigDecimal("boxLength");
+                    BigDecimal boxWidth = shipmentBoxType.getBigDecimal("boxWidth");
+                    BigDecimal boxHeight = shipmentBoxType.getBigDecimal("boxHeight");
                     UtilXml.addChildElementValue(dimensionsElement, "Length", UtilValidate.isNotEmpty(boxLength) ? ""+boxLength.intValue() : "", shipmentConfirmRequestDoc);
                     UtilXml.addChildElementValue(dimensionsElement, "Width", UtilValidate.isNotEmpty(boxWidth) ? ""+boxWidth.intValue() : "", shipmentConfirmRequestDoc);
                     UtilXml.addChildElementValue(dimensionsElement, "Height", UtilValidate.isNotEmpty(boxHeight) ? ""+boxHeight.intValue() : "", shipmentConfirmRequestDoc);
@@ -451,7 +453,7 @@
                 if (shipmentPackage.getString("weight") == null) {
                     return ServiceUtil.returnError("Weight value not found for ShipmentRouteSegment with shipmentId " + shipmentId + ", shipmentRouteSegmentId " + shipmentRouteSegmentId + ", and shipmentPackageSeqId " + shipmentPackage.getString("shipmentPackageSeqId"));
                 }
-                Double boxWeight = shipmentPackage.getDouble("weight");
+                BigDecimal boxWeight = shipmentPackage.getBigDecimal("weight");
                 UtilXml.addChildElementValue(packageWeightElement, "Weight", UtilValidate.isNotEmpty(boxWeight) ? ""+boxWeight.intValue() : "", shipmentConfirmRequestDoc);
                 
                 Element referenceNumberElement = UtilXml.addChildElement(packageElement, "ReferenceNumber", shipmentConfirmRequestDoc);
@@ -496,10 +498,10 @@
                     BigDecimal packageValue = (BigDecimal) getPackageValueResult.get("packageValue");
                     
                     // Convert the value of the COD surcharge to the shipment currency, if necessary
-                    Map convertUomResult = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", codSurchargeCurrencyUomId, "uomIdTo", currencyCode, "originalValue", new Double(codSurchargePackageAmount.doubleValue())));
+                    Map convertUomResult = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", codSurchargeCurrencyUomId, "uomIdTo", currencyCode, "originalValue", codSurchargePackageAmount));
                     if (ServiceUtil.isError(convertUomResult)) return convertUomResult;
                     if (convertUomResult.containsKey("convertedValue")) {
-                        codSurchargePackageAmount = new BigDecimal(((Double) convertUomResult.get("convertedValue")).doubleValue()).setScale(decimals, rounding);
+                        codSurchargePackageAmount = ((BigDecimal) convertUomResult.get("convertedValue")).setScale(decimals, rounding);
                     }
                     
                     // Add the amount of the surcharge for the package, if the surcharge should be on all packages or the first and this is the first package
@@ -646,21 +648,21 @@
             }
             
             try {
-                shipmentRouteSegment.set("actualTransportCost", Double.valueOf(transportationMonetaryValue));
+                shipmentRouteSegment.set("actualTransportCost", new BigDecimal(transportationMonetaryValue));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the transportationMonetaryValue [" + transportationMonetaryValue + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
                 errorList.add(excErrMsg);
             }
             try {
-                shipmentRouteSegment.set("actualServiceCost", Double.valueOf(serviceOptionsMonetaryValue));
+                shipmentRouteSegment.set("actualServiceCost", new BigDecimal(serviceOptionsMonetaryValue));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the serviceOptionsMonetaryValue [" + serviceOptionsMonetaryValue + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
                 errorList.add(excErrMsg);
             }
             try {
-                shipmentRouteSegment.set("actualCost", Double.valueOf(totalMonetaryValue));
+                shipmentRouteSegment.set("actualCost", new BigDecimal(totalMonetaryValue));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the totalMonetaryValue [" + totalMonetaryValue + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
@@ -673,7 +675,7 @@
             String billingWeightUnitOfMeasurement = UtilXml.childElementValue(billingWeightUnitOfMeasurementElement, "Code");
             String billingWeight = UtilXml.childElementValue(billingWeightElement, "Weight");
             try {
-                shipmentRouteSegment.set("billingWeight", Double.valueOf(billingWeight));
+                shipmentRouteSegment.set("billingWeight", new BigDecimal(billingWeight));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the billingWeight [" + billingWeight + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
@@ -914,21 +916,21 @@
             }
             
             try {
-                shipmentRouteSegment.set("actualTransportCost", Double.valueOf(transportationMonetaryValue));
+                shipmentRouteSegment.set("actualTransportCost", new BigDecimal(transportationMonetaryValue));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the transportationMonetaryValue [" + transportationMonetaryValue + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
                 errorList.add(excErrMsg);
             }
             try {
-                shipmentRouteSegment.set("actualServiceCost", Double.valueOf(serviceOptionsMonetaryValue));
+                shipmentRouteSegment.set("actualServiceCost", new BigDecimal(serviceOptionsMonetaryValue));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the serviceOptionsMonetaryValue [" + serviceOptionsMonetaryValue + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
                 errorList.add(excErrMsg);
             }
             try {
-                shipmentRouteSegment.set("actualCost", Double.valueOf(totalMonetaryValue));
+                shipmentRouteSegment.set("actualCost", new BigDecimal(totalMonetaryValue));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the totalMonetaryValue [" + totalMonetaryValue + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
@@ -941,7 +943,7 @@
             String billingWeightUnitOfMeasurement = UtilXml.childElementValue(billingWeightUnitOfMeasurementElement, "Code");
             String billingWeight = UtilXml.childElementValue(billingWeightElement, "Weight");
             try {
-                shipmentRouteSegment.set("billingWeight", Double.valueOf(billingWeight));
+                shipmentRouteSegment.set("billingWeight", new BigDecimal(billingWeight));
             } catch (NumberFormatException e) {
                 String excErrMsg = "Error parsing the billingWeight [" + billingWeight + "]: " + e.toString();
                 Debug.logError(e, excErrMsg, module);
@@ -994,7 +996,7 @@
                 shipmentPackageRouteSeg.set("boxNumber", "");
                 shipmentPackageRouteSeg.set("currencyUomId", packageServiceOptionsCurrencyCode);
                 try {
-                    shipmentPackageRouteSeg.set("packageServiceCost", Double.valueOf(packageServiceOptionsMonetaryValue));
+                    shipmentPackageRouteSeg.set("packageServiceCost", new BigDecimal(packageServiceOptionsMonetaryValue));
                 } catch (NumberFormatException e) {
                     String excErrMsg = "Error parsing the packageServiceOptionsMonetaryValue [" + packageServiceOptionsMonetaryValue + "] for Package [" + shipmentPackageRouteSeg.getString("shipmentPackageSeqId") + "]: " + e.toString();
                     Debug.logError(e, excErrMsg, module);
@@ -1561,7 +1563,7 @@
         }
     }
 
-    private static void splitEstimatePackages(Document requestDoc, Element shipmentElement, List shippableItemInfo, double maxWeight, double minWeight) {
+    private static void splitEstimatePackages(Document requestDoc, Element shipmentElement, List shippableItemInfo, BigDecimal maxWeight, BigDecimal minWeight) {
         List packages = getPackageSplit(shippableItemInfo, maxWeight);
         if (UtilValidate.isNotEmpty(packages)) {
             Iterator i = packages.iterator();
@@ -1573,9 +1575,9 @@
             
             // Add a dummy package
             String totalWeightStr = UtilProperties.getPropertyValue("shipment", "shipment.ups.min.estimate.weight", "1");
-            double packageWeight = 1;
+            BigDecimal packageWeight = BigDecimal.ONE;
             try {
-                packageWeight = Double.parseDouble(totalWeightStr);
+                packageWeight = new BigDecimal(totalWeightStr);
             } catch (NumberFormatException e) {
                 Debug.logError(e, module);
             }
@@ -1587,15 +1589,15 @@
         }
     }
 
-    private static void addPackageElement(Document requestDoc, Element shipmentElement, List shippableItemInfo, Map packageMap, double minWeight) {
-        double packageWeight = checkForDefaultPackageWeight(calcPackageWeight(packageMap, shippableItemInfo, 0),minWeight);
+    private static void addPackageElement(Document requestDoc, Element shipmentElement, List shippableItemInfo, Map packageMap, BigDecimal minWeight) {
+        BigDecimal packageWeight = checkForDefaultPackageWeight(calcPackageWeight(packageMap, shippableItemInfo, BigDecimal.ZERO), minWeight);
         Element packageElement = UtilXml.addChildElement(shipmentElement, "Package", requestDoc);
         Element packagingTypeElement = UtilXml.addChildElement(packageElement, "PackagingType", requestDoc);
         UtilXml.addChildElementValue(packagingTypeElement, "Code", "00", requestDoc);
         UtilXml.addChildElementValue(packagingTypeElement, "Description", "Unknown PackagingType", requestDoc);
         UtilXml.addChildElementValue(packageElement, "Description", "Package Description", requestDoc);
         Element packageWeightElement = UtilXml.addChildElement(packageElement, "PackageWeight", requestDoc);
-        UtilXml.addChildElementValue(packageWeightElement, "Weight", Double.toString(packageWeight), requestDoc);
+        UtilXml.addChildElementValue(packageWeightElement, "Weight", packageWeight.toPlainString(), requestDoc);
         //If product is in shippable Package then it we should have one product per packagemap
         if (packageMap.size() ==1) {
             Iterator i = packageMap.keySet().iterator();
@@ -1612,7 +1614,7 @@
         
     }
 
-    private static void addPackageElement(Document requestDoc, Element shipmentElement, Double packageWeight) {        
+    private static void addPackageElement(Document requestDoc, Element shipmentElement, BigDecimal packageWeight) {        
         Element packageElement = UtilXml.addChildElement(shipmentElement, "Package", requestDoc);
         Element packagingTypeElement = UtilXml.addChildElement(packageElement, "PackagingType", requestDoc);
         UtilXml.addChildElementValue(packagingTypeElement, "Code", "00", requestDoc);
@@ -1623,11 +1625,11 @@
     }
     
     
-    private static double checkForDefaultPackageWeight(double weight, double minWeight) {
-        return (weight > 0 && weight > minWeight ? weight : minWeight);
+    private static BigDecimal checkForDefaultPackageWeight(BigDecimal weight, BigDecimal minWeight) {
+        return (weight.compareTo(BigDecimal.ZERO) > 0 && weight.compareTo(minWeight) > 0 ? weight : minWeight);
     }
     
-    private static List getPackageSplit(List shippableItemInfo, double maxWeight) {
+    private static List getPackageSplit(List shippableItemInfo, BigDecimal maxWeight) {
         // create the package list w/ the first package
         List packages = new LinkedList();
 
@@ -1636,28 +1638,28 @@
             while (sii.hasNext()) {
                 Map itemInfo = (Map) sii.next();
                 long pieces = ((Long) itemInfo.get("piecesIncluded")).longValue();
-                double totalQuantity = ((Double) itemInfo.get("quantity")).doubleValue();
-                double totalWeight = ((Double) itemInfo.get("weight")).doubleValue();
+                BigDecimal totalQuantity = (BigDecimal) itemInfo.get("quantity");
+                BigDecimal totalWeight = (BigDecimal) itemInfo.get("weight");
                 String productId = (String) itemInfo.get("productId");
 
                 // sanity check
                 if (pieces < 1) {
                     pieces = 1; // can NEVER be less than one
                 }
-                double weight = totalWeight / pieces;
+                BigDecimal weight = totalWeight.divide(BigDecimal.valueOf(pieces), generalRounding);
 
-                for (int z = 1; z <= totalQuantity; z++) {
-                    double partialQty = pieces > 1 ? 1.000 / pieces : 1;
+                for (int z = 1; z <= totalQuantity.intValue(); z++) {
+                 BigDecimal partialQty = pieces > 1 ? BigDecimal.ONE.divide(BigDecimal.valueOf(pieces), generalRounding) : BigDecimal.ONE;
                     for (long x = 0; x < pieces; x++) {
                         if(itemInfo.get("inShippingBox") != null &&  ((String) itemInfo.get("inShippingBox")).equalsIgnoreCase("Y")) {
                             Map newPackage = new HashMap();
-                            newPackage.put(productId, new Double(partialQty));
+                            newPackage.put(productId, partialQty);
                             packages.add(newPackage);
-                        } else if (weight >= maxWeight) {
+                        } else if (weight.compareTo(maxWeight) >= 0) {
                             Map newPackage = new HashMap();
-                            newPackage.put(productId, new Double(partialQty));
+                            newPackage.put(productId, partialQty);
                             packages.add(newPackage);
-                        } else if (totalWeight > 0) {
+                        } else if (totalWeight.compareTo(BigDecimal.ZERO) > 0) {
                             // create the first package
                             if (packages.size() == 0) {
                                 packages.add(new HashMap());
@@ -1669,18 +1671,18 @@
                             for (int pi = 0; pi < packageSize; pi++) {
                                 if (!addedToPackage) {
                                     Map packageMap = (Map) packages.get(pi);
-                                    double packageWeight = calcPackageWeight(packageMap, shippableItemInfo, weight);
-                                    if (packageWeight <= maxWeight) {
-                                        Double qtyD = (Double) packageMap.get(productId);
-                                        double qty = qtyD == null ? 0 : qtyD.doubleValue();
-                                        packageMap.put(productId, new Double(qty + partialQty));
+                                    BigDecimal packageWeight = calcPackageWeight(packageMap, shippableItemInfo, weight);
+                                    if (packageWeight.compareTo(maxWeight) <= 0) {
+                                     BigDecimal qty = (BigDecimal) packageMap.get(productId);
+                                        qty = qty == null ? BigDecimal.ZERO : qty;
+                                        packageMap.put(productId, qty.add(partialQty));
                                         addedToPackage = true;
                                     }
                                 }
                             }
                             if (!addedToPackage) {
                                 Map packageMap = new HashMap();
-                                packageMap.put(productId, new Double(partialQty));
+                                packageMap.put(productId, partialQty);
                                 packages.add(packageMap);
                             }
                         }
@@ -1691,17 +1693,17 @@
         return packages;
     }
 
-    private static double calcPackageWeight(Map packageMap, List shippableItemInfo, double additionalWeight) {
-        double totalWeight = 0.00;
+    private static BigDecimal calcPackageWeight(Map packageMap, List shippableItemInfo, BigDecimal additionalWeight) {
+        BigDecimal totalWeight = BigDecimal.ZERO;
         Iterator i = packageMap.keySet().iterator();
         while (i.hasNext()) {
             String productId = (String) i.next();
             Map productInfo = getProductItemInfo(shippableItemInfo, productId);
-            double productWeight = ((Double) productInfo.get("weight")).doubleValue();
-            double quantity = ((Double) packageMap.get(productId)).doubleValue();
-            totalWeight += (productWeight * quantity);
+            BigDecimal productWeight = (BigDecimal) productInfo.get("weight");
+            BigDecimal quantity = (BigDecimal) packageMap.get(productId);
+            totalWeight = totalWeight.add(productWeight.multiply(quantity));
         }
-        return totalWeight + additionalWeight;
+        return totalWeight.add(additionalWeight);
     }
 
     private static Map getProductItemInfo(List shippableItemInfo, String productId) {
@@ -1736,7 +1738,7 @@
         if ("1".equals(responseStatusCode)) {
             List rates = UtilXml.childElementList(rateResponseElement, "RatedShipment");
             Map rateMap = new HashMap();
-            Double firstRate = null;
+            BigDecimal firstRate = null;
             if (rates == null || rates.size() == 0) {
                 return ServiceUtil.returnError("No rates available at this time");
             } else {
@@ -1752,9 +1754,9 @@
                     Element totalCharges = UtilXml.firstChildElement(element, "TotalCharges");
                     String totalString = UtilXml.childElementValue(totalCharges, "MonetaryValue");
 
-                    rateMap.put(serviceCode, new Double(totalString));
+                    rateMap.put(serviceCode, new BigDecimal(totalString));
                     if (firstRate == null) {
-                        firstRate = (Double) rateMap.get(serviceCode);
+                        firstRate = (BigDecimal) rateMap.get(serviceCode);
                     }
                 }
             }
@@ -1918,9 +1920,9 @@
         String shippingCountryCode = (String) context.get("shippingCountryCode");
         List packageWeights = (List) context.get("packageWeights");
         List shippableItemInfo = (List) context.get("shippableItemInfo");
-        Double shippableTotal = (Double) context.get("shippableTotal");
-        Double shippableQuantity = (Double) context.get("shippableQuantity");
-        Double shippableWeight = (Double) context.get("shippableWeight");
+        BigDecimal shippableTotal = (BigDecimal) context.get("shippableTotal");
+        BigDecimal shippableQuantity = (BigDecimal) context.get("shippableQuantity");
+        BigDecimal shippableWeight = (BigDecimal) context.get("shippableWeight");
         String isResidentialAddress = (String)context.get("isResidentialAddress");
 
         // Important: DO NOT returnError here or you could trigger a transaction rollback and break other services.
@@ -1929,13 +1931,13 @@
         }
 
         if (shippableTotal == null) {
-            shippableTotal = new Double(0.00);
+            shippableTotal = BigDecimal.ZERO;
         }
         if (shippableQuantity == null) {
-            shippableQuantity = new Double(0.00);
+            shippableQuantity = BigDecimal.ZERO;
         }
         if (shippableWeight == null) {
-            shippableWeight = new Double(0.00);
+            shippableWeight = BigDecimal.ZERO;
         }
         if (serviceConfigProps == null) {
             serviceConfigProps = "shipment.properties";
@@ -2036,18 +2038,18 @@
 
         // package info
         String maxWeightStr = UtilProperties.getPropertyValue(serviceConfigProps, "shipment.ups.max.estimate.weight", "99");
-        double maxWeight = 99;
+        BigDecimal maxWeight = new BigDecimal("99");
         try {
-            maxWeight = Double.parseDouble(maxWeightStr);
+            maxWeight = new BigDecimal(maxWeightStr);
         } catch (NumberFormatException e) {
-            maxWeight = 99;
+            maxWeight = new BigDecimal("99");
         }
         String minWeightStr = UtilProperties.getPropertyValue(serviceConfigProps, "shipment.ups.min.estimate.weight", ".1");
-        double minWeight = .1;
+        BigDecimal minWeight = new BigDecimal("0.1");
         try {
-            minWeight = Double.parseDouble(minWeightStr);
+            minWeight = new BigDecimal(minWeightStr);
         } catch (NumberFormatException e) {
-            minWeight = .1;
+            minWeight = new BigDecimal("0.1");
         }
         
         // Passing in a list of package weights overrides the calculation of same via shippableItemInfo
@@ -2057,7 +2059,7 @@
         } else {
             Iterator i = packageWeights.iterator();
             while (i.hasNext()) {
-                Double packageWeight = (Double) i.next();
+                BigDecimal packageWeight = (BigDecimal) i.next();
                 addPackageElement(rateRequestDoc,  shipmentElement, packageWeight);
             }
         }

Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServices.java Sun Nov 30 22:51:11 2008
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.math.BigDecimal;
+import java.math.MathContext;
 import java.text.DecimalFormat;
 import java.util.*;
 
@@ -58,13 +59,15 @@
     public final static String module = UspsServices.class.getName();
     public final static String errorResource = "ProductErrorUiLabels";
 
+    public static final MathContext generalRounding = new MathContext(10);
+
     public static Map uspsRateInquire(DispatchContext dctx, Map context) {
 
         GenericDelegator delegator = dctx.getDelegator();
 
         // check for 0 weight
-        Double shippableWeight = (Double) context.get("shippableWeight");
-        if (shippableWeight.doubleValue() == 0) {
+        BigDecimal shippableWeight = (BigDecimal) context.get("shippableWeight");
+        if (shippableWeight.compareTo(BigDecimal.ZERO) == 0) {
             // TODO: should we return an error, or $0.00 ?
             return ServiceUtil.returnFailure("shippableWeight must be greater than 0");
         }
@@ -127,14 +130,14 @@
         Document requestDocument = createUspsRequestDocument("RateV2Request");
 
         // TODO: 70 lb max is valid for Express, Priority and Parcel only - handle other methods
-        double maxWeight = 70;
+        BigDecimal maxWeight = new BigDecimal("70");
         String maxWeightStr = UtilProperties.getPropertyValue((String) context.get("serviceConfigProps"),
                 "shipment.usps.max.estimate.weight", "70");
         try {
-            maxWeight = Double.parseDouble(maxWeightStr);
+            maxWeight = new BigDecimal(maxWeightStr);
         } catch (NumberFormatException e) {
             Debug.logWarning("Error parsing max estimate weight string [" + maxWeightStr + "], using default instead", module);
-            maxWeight = 70;
+            maxWeight = new BigDecimal("70");
         }
 
         List shippableItemInfo = (List) context.get("shippableItemInfo");
@@ -144,8 +147,8 @@
         for (ListIterator li = packages.listIterator(); li.hasNext();) {
             Map packageMap = (Map) li.next();
 
-            double packageWeight = isOnePackage ? shippableWeight.doubleValue() : calcPackageWeight(dctx, packageMap, shippableItemInfo, 0);
-            if (packageWeight == 0) {
+            BigDecimal packageWeight = isOnePackage ? shippableWeight : calcPackageWeight(dctx, packageMap, shippableItemInfo, BigDecimal.ZERO);
+            if (packageWeight.compareTo(BigDecimal.ZERO) == 0) {
                 continue;
             }
 
@@ -156,13 +159,13 @@
             UtilXml.addChildElementValue(packageElement, "ZipOrigination", originationZip.substring(0,5), requestDocument);
             UtilXml.addChildElementValue(packageElement, "ZipDestination", destinationZip.substring(0,5), requestDocument);
 
-            double weightPounds = Math.floor(packageWeight);
+            BigDecimal weightPounds = packageWeight.setScale(0, BigDecimal.ROUND_FLOOR);
             // for Parcel post, the weight must be at least 1 lb
-            if ("PARCEL".equals(serviceCode.toUpperCase()) && (weightPounds < 1.0)) {
-                weightPounds = 1.0;
-                packageWeight = 0.0;
+            if ("PARCEL".equals(serviceCode.toUpperCase()) && (weightPounds.compareTo(BigDecimal.ONE) < 0)) {
+                weightPounds = BigDecimal.ONE;
+                packageWeight = BigDecimal.ZERO;
             }
-            double weightOunces = Math.ceil(packageWeight * 16 % 16);
+            BigDecimal weightOunces = packageWeight.multiply(new BigDecimal("16")).remainder(new BigDecimal("16")).setScale(0, BigDecimal.ROUND_CEILING);
             DecimalFormat df = new DecimalFormat("#");  // USPS only accepts whole numbers like 1 and not 1.0
             UtilXml.addChildElementValue(packageElement, "Pounds", df.format(weightPounds), requestDocument);
             UtilXml.addChildElementValue(packageElement, "Ounces", df.format(weightOunces), requestDocument);
@@ -199,24 +202,24 @@
             return ServiceUtil.returnError("No rate available at this time");
         }
 
-        double estimateAmount = 0.00;
+        BigDecimal estimateAmount = BigDecimal.ZERO;
         for (Iterator i = rates.iterator(); i.hasNext();) {
             Element packageElement = (Element) i.next();
             try {
                 Element postageElement = UtilXml.firstChildElement(packageElement, "Postage");
-                double packageAmount = Double.parseDouble(UtilXml.childElementValue(postageElement, "Rate"));
-                estimateAmount += packageAmount;
+                BigDecimal packageAmount = new BigDecimal(UtilXml.childElementValue(postageElement, "Rate"));
+                estimateAmount = estimateAmount.add(packageAmount);
             } catch (NumberFormatException e) {
                 Debug.log(e, module);
             }
         }
 
         Map result = ServiceUtil.returnSuccess();
-        result.put("shippingEstimateAmount", new Double(estimateAmount));
+        result.put("shippingEstimateAmount", estimateAmount);
         return result;
     }
 
-    private static List getPackageSplit(DispatchContext dctx, List shippableItemInfo, double maxWeight) {
+    private static List getPackageSplit(DispatchContext dctx, List shippableItemInfo, BigDecimal maxWeight) {
         // create the package list w/ the first pacakge
         List packages = FastList.newInstance();
 
@@ -225,24 +228,24 @@
             while (sii.hasNext()) {
                 Map itemInfo = (Map) sii.next();
                 long pieces = ((Long) itemInfo.get("piecesIncluded")).longValue();
-                double totalQuantity = ((Double) itemInfo.get("quantity")).doubleValue();
-                double totalWeight = ((Double) itemInfo.get("weight")).doubleValue();
+                BigDecimal totalQuantity = (BigDecimal) itemInfo.get("quantity");
+                BigDecimal totalWeight = (BigDecimal) itemInfo.get("weight");
                 String productId = (String) itemInfo.get("productId");
 
                 // sanity check
                 if (pieces < 1) {
                     pieces = 1; // can NEVER be less than one
                 }
-                double weight = totalWeight / pieces;
+                BigDecimal weight = totalWeight.divide(BigDecimal.valueOf(pieces), generalRounding);
 
-                for (int z = 1; z <= totalQuantity; z++) {
-                    double partialQty = pieces > 1 ? 1.000 / pieces : 1;
+                for (int z = 1; z <= totalQuantity.intValue(); z++) {
+                 BigDecimal partialQty = pieces > 1 ? BigDecimal.ONE.divide(BigDecimal.valueOf(pieces), generalRounding) : BigDecimal.ONE;
                     for (long x = 0; x < pieces; x++) {
-                        if (weight >= maxWeight) {
+                        if (weight.compareTo(maxWeight) >= 0) {
                             Map newPackage = new HashMap();
-                            newPackage.put(productId, new Double(partialQty));
+                            newPackage.put(productId, partialQty);
                             packages.add(newPackage);
-                        } else if (totalWeight > 0) {
+                        } else if (totalWeight.compareTo(BigDecimal.ZERO) > 0) {
                             // create the first package
                             if (packages.size() == 0) {
                                 packages.add(new HashMap());
@@ -254,18 +257,18 @@
                             for (int pi = 0; pi < packageSize; pi++) {
                                 if (!addedToPackage) {
                                     Map packageMap = (Map) packages.get(pi);
-                                    double packageWeight = calcPackageWeight(dctx, packageMap, shippableItemInfo, weight);
-                                    if (packageWeight <= maxWeight) {
-                                        Double qtyD = (Double) packageMap.get(productId);
-                                        double qty = qtyD == null ? 0 : qtyD.doubleValue();
-                                        packageMap.put(productId, new Double(qty + partialQty));
+                                    BigDecimal packageWeight = calcPackageWeight(dctx, packageMap, shippableItemInfo, weight);
+                                    if (packageWeight.compareTo(maxWeight) <= 0) {
+                                     BigDecimal qty = (BigDecimal) packageMap.get(productId);
+                                        qty = qty == null ? BigDecimal.ZERO : qty;
+                                        packageMap.put(productId, qty.add(partialQty));
                                         addedToPackage = true;
                                     }
                                 }
                             }
                             if (!addedToPackage) {
                                 Map packageMap = new HashMap();
-                                packageMap.put(productId, new Double(partialQty));
+                                packageMap.put(productId, partialQty);
                                 packages.add(packageMap);
                             }
                         }
@@ -276,10 +279,10 @@
         return packages;
     }
 
-    private static double calcPackageWeight(DispatchContext dctx, Map packageMap, List shippableItemInfo, double additionalWeight) {
+    private static BigDecimal calcPackageWeight(DispatchContext dctx, Map packageMap, List shippableItemInfo, BigDecimal additionalWeight) {
 
         LocalDispatcher dispatcher = dctx.getDispatcher();
-        double totalWeight = 0.00;
+        BigDecimal totalWeight = BigDecimal.ZERO;
         String defaultWeightUomId = UtilProperties.getPropertyValue("shipment.properties", "shipment.default.weight.uom");
         if (UtilValidate.isEmpty(defaultWeightUomId)) {
             Debug.logWarning("No shipment.default.weight.uom set in shipment.properties, setting it to WT_oz for USPS", module);
@@ -290,8 +293,8 @@
         while (i.hasNext()) {
             String productId = (String) i.next();
             Map productInfo = getProductItemInfo(shippableItemInfo, productId);
-            double productWeight = ((Double) productInfo.get("weight")).doubleValue();
-            double quantity = ((Double) packageMap.get(productId)).doubleValue();
+            BigDecimal productWeight = (BigDecimal) productInfo.get("weight");
+            BigDecimal quantity = (BigDecimal) packageMap.get(productId);
 
             // DLK - I'm not sure if this line is working. shipment_package seems to leave this value null so???
             String weightUomId = (String) productInfo.get("weight_uom_id");
@@ -306,23 +309,23 @@
                 // attempt a conversion to pounds
                 Map result = new HashMap();
                 try {
-                    result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", "WT_lb", "originalValue", new Double(productWeight)));
+                    result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", "WT_lb", "originalValue", productWeight));
                 } catch (GenericServiceException ex) {
                     Debug.logError(ex, module);
                 }
                     
                 if (result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS) && result.get("convertedValue") != null) {
-                    productWeight = ((Double) result.get("convertedValue")).doubleValue();
+                    productWeight = (BigDecimal) result.get("convertedValue");
                 } else {
                     Debug.logError("Unsupported weightUom [" + weightUomId + "] for calcPackageWeight running productId " + productId + ", could not find a conversion factor to WT_lb",module);
                 }
                     
             }
 
-            totalWeight += (productWeight * quantity);
+            totalWeight = totalWeight.add(productWeight.multiply(quantity));
         }
         Debug.logInfo("Package Weight : " + String.valueOf(totalWeight) + " lbs.", module);
-        return totalWeight + additionalWeight;
+        return totalWeight.add(additionalWeight);
     }
 
     // lifted from UpsServices with no changes - 2004.09.06 JFE
@@ -866,7 +869,7 @@
                 return ServiceUtil.returnError("No packages found for ShipmentRouteSegment " + srsKeyString);
             }
 
-            double actualTransportCost = 0;
+            BigDecimal actualTransportCost = BigDecimal.ZERO;
 
             String carrierDeliveryZone = null;
             String carrierRestrictionCodes = null;
@@ -901,9 +904,9 @@
                     return ServiceUtil.returnError("weight not found for ShipmentPackage " + spKeyString);
                 }
 
-                double weight = 0;
+                BigDecimal weight = BigDecimal.ZERO;
                 try {
-                    weight = Double.parseDouble(weightStr);
+                    weight = new BigDecimal(weightStr);
                 } catch (NumberFormatException nfe) {
                     nfe.printStackTrace(); // TODO: handle exception
                 }
@@ -916,13 +919,13 @@
                     // attempt a conversion to pounds
                     Map result = new HashMap();
                     try {
-                        result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", "WT_lb", "originalValue", new Double(weight)));
+                        result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", "WT_lb", "originalValue", weight));
                     } catch (GenericServiceException ex) {
                         return ServiceUtil.returnError(ex.getMessage());
                     }
                     
                     if (result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS) && result.get("convertedValue") != null) {
-                        weight *= ((Double) result.get("convertedValue")).doubleValue();
+                        weight = weight.multiply((BigDecimal) result.get("convertedValue"));
                     } else {
                         return ServiceUtil.returnError("Unsupported weightUom [" + weightUomId + "] for ShipmentPackage " +
                                 spKeyString + ", could not find a conversion factor for WT_lb");
@@ -930,8 +933,8 @@
                     
                 }
 
-                double weightPounds = Math.floor(weight);
-                double weightOunces = Math.ceil(weight * 16 % 16);
+                BigDecimal weightPounds = weight.setScale(0, BigDecimal.ROUND_FLOOR);
+                BigDecimal weightOunces = weight.multiply(new BigDecimal("16")).remainder(new BigDecimal("16")).setScale(0, BigDecimal.ROUND_CEILING);
 
                 DecimalFormat df = new DecimalFormat("#");
                 UtilXml.addChildElementValue(packageElement, "Pounds", df.format(weightPounds), requestDocument);
@@ -997,13 +1000,13 @@
                             "missing or empty Postage element");
                 }
 
-                double postage = 0;
+                BigDecimal postage = BigDecimal.ZERO;
                 try {
-                    postage = Double.parseDouble(postageString);
+                    postage = new BigDecimal(postageString);
                 } catch (NumberFormatException nfe) {
                     nfe.printStackTrace(); // TODO: handle exception
                 }
-                actualTransportCost += postage;
+                actualTransportCost = actualTransportCost.add(postage);
 
                 shipmentPackageRouteSeg.setString("packageTransportCost", postageString);
                 shipmentPackageRouteSeg.store();
@@ -1187,9 +1190,9 @@
                     return ServiceUtil.returnError("weight not found for ShipmentPackage " + spKeyString);
                 }
 
-                double weight = 0;
+                BigDecimal weight = BigDecimal.ZERO;
                 try {
-                    weight = Double.parseDouble(weightStr);
+                    weight = new BigDecimal(weightStr);
                 } catch (NumberFormatException nfe) {
                     nfe.printStackTrace(); // TODO: handle exception
                 }
@@ -1207,11 +1210,11 @@
                         return ServiceUtil.returnError("Unsupported weightUom [" + weightUomId + "] for ShipmentPackage " +
                                 spKeyString + ", could not find a conversion factor for WT_oz");
                     }
-                    weight *= uomConversion.getDouble("conversionFactor").doubleValue();
+                    weight = weight.multiply(uomConversion.getBigDecimal("conversionFactor"));
                 }
 
                 DecimalFormat df = new DecimalFormat("#");
-                UtilXml.addChildElementValue(requestElement, "WeightInOunces", df.format(Math.ceil(weight)), requestDocument);
+                UtilXml.addChildElementValue(requestElement, "WeightInOunces", df.format(weight.setScale(0, BigDecimal.ROUND_CEILING)), requestDocument);
 
                 UtilXml.addChildElementValue(requestElement, "ServiceType", serviceType, requestDocument);
                 UtilXml.addChildElementValue(requestElement, "ImageType", "TIF", requestDocument);

Modified: ofbiz/branches/typecheckcleanup200810/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductQuickAdmin.groovy
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductQuickAdmin.groovy?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductQuickAdmin.groovy (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/webapp/catalog/WEB-INF/actions/product/EditProductQuickAdmin.groovy Sun Nov 30 22:51:11 2008
@@ -93,10 +93,10 @@
 featureSalesThru = [:];
 featureThruDate = [:];
 selFeatureDesc = [:];
-Double floz = null;
-Double ml = null;
-Double ntwt = null;
-Double grams = null;
+BigDecimal floz = null;
+BigDecimal ml = null;
+BigDecimal ntwt = null;
+BigDecimal grams = null;
 String hazmat = "nbsp;";
 String salesthru = null;
 String thrudate = null;
@@ -169,7 +169,7 @@
     prodFeaturesFiltered = EntityUtil.filterByAnd(productFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'VLIQ_ozUS']);
     if (prodFeaturesFiltered) {
         try {
-            floz = ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified");
+            floz = ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified");
         } catch (Exception e) {
             floz = null;
         }
@@ -178,7 +178,7 @@
     prodFeaturesFiltered = EntityUtil.filterByAnd(productFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'VLIQ_ml']);
     if (prodFeaturesFiltered) {
         try {
-            ml = ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified");
+            ml = ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified");
         } catch (Exception e) {
             ml = null;
         }
@@ -187,7 +187,7 @@
     prodFeaturesFiltered = EntityUtil.filterByAnd(productFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'WT_g']);
     if (prodFeaturesFiltered) {
         try {
-            grams = ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified");
+            grams = ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified");
         } catch (Exception e) {
             grams = null;
         }
@@ -196,7 +196,7 @@
     prodFeaturesFiltered = EntityUtil.filterByAnd(productFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'WT_oz']);
     if (prodFeaturesFiltered) {
         try {
-            ntwt = ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified");
+            ntwt = ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified");
         } catch (Exception e) {
             ntwt = null;
         }
@@ -239,19 +239,19 @@
             assocProductFeatureAndAppls = assocProduct.getRelated("ProductFeatureAndAppl");
             prodFeaturesFiltered = EntityUtil.filterByAnd(assocProductFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'VLIQ_ozUS']);
             if (prodFeaturesFiltered) {
-                featureFloz.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified"));
+                featureFloz.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified"));
             }
             prodFeaturesFiltered = EntityUtil.filterByAnd(assocProductFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'VLIQ_ml']);
             if (prodFeaturesFiltered) {
-                featureMl.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified"));
+                featureMl.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified"));
             }
             prodFeaturesFiltered = EntityUtil.filterByAnd(assocProductFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'WT_g']);
             if (prodFeaturesFiltered) {
-                featureGrams.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified"));
+                featureGrams.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified"));
             }
             prodFeaturesFiltered = EntityUtil.filterByAnd(assocProductFeatureAndAppls, [productFeatureTypeId : 'AMOUNT', uomId : 'WT_oz']);
             if (prodFeaturesFiltered) {
-                featureNtwt.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getDouble("numberSpecified"));
+                featureNtwt.put(assocProduct.productId, ((GenericValue)prodFeaturesFiltered.get(0)).getBigDecimal("numberSpecified"));
             }
             prodFeaturesFiltered = EntityUtil.filterByAnd(assocProductFeatureAndAppls, [productFeatureTypeId : 'HAZMAT']);
             if (prodFeaturesFiltered) {