Author: mbrohl
Date: Fri Aug 18 19:51:39 2017
New Revision: 1805464

URL: http://svn.apache.org/viewvc?rev=1805464&view=rev
Log:
Improved: Fixing defects reported by FindBugs, package 
org.apache.ofbiz.accounting.ledger.
(OFBIZ-9505)

Additionally to the provided patch I removed the static ZERO variable 
and changed the assignment to BigDecimal.ZERO instead. An unused import
statement was removed also.

Thanks Kyra Pritzel-Hentley for reporting and providing the patch.

Modified:
    
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/ledger/GeneralLedgerServices.java

Modified: 
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/ledger/GeneralLedgerServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/ledger/GeneralLedgerServices.java?rev=1805464&r1=1805463&r2=1805464&view=diff
==============================================================================
--- 
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/ledger/GeneralLedgerServices.java
 (original)
+++ 
ofbiz/ofbiz-framework/trunk/applications/accounting/src/main/java/org/apache/ofbiz/accounting/ledger/GeneralLedgerServices.java
 Fri Aug 18 19:51:39 2017
@@ -35,26 +35,23 @@ public class GeneralLedgerServices {
 
     public static final String module = GeneralLedgerServices.class.getName();
 
-    private static BigDecimal ZERO = BigDecimal.ZERO;
-
     public static Map<String, Object> createUpdateCostCenter(DispatchContext 
dctx, Map<String, ? extends Object> context) {
         LocalDispatcher dispatcher = dctx.getDispatcher();
-        BigDecimal totalAmountPercentage = ZERO;
         Map<String, Object> createGlAcctCatMemFromCostCentersMap = null;
         String glAccountId = (String) context.get("glAccountId");
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         Map<String, String> amountPercentageMap = 
UtilGenerics.checkMap(context.get("amountPercentageMap"));
-        totalAmountPercentage = 
GeneralLedgerServices.calculateCostCenterTotal(amountPercentageMap);
+        BigDecimal totalAmountPercentage = 
GeneralLedgerServices.calculateCostCenterTotal(amountPercentageMap);
         Map<String, Object> result = ServiceUtil.returnSuccess();
-        for (String rowKey : amountPercentageMap.keySet()) {
-            String rowValue = amountPercentageMap.get(rowKey);
+        for (Map.Entry<String, String> rowEntry : 
amountPercentageMap.entrySet()) {
+            String rowValue = rowEntry.getValue();
             if (UtilValidate.isNotEmpty(rowValue)) {
                 createGlAcctCatMemFromCostCentersMap = 
UtilMisc.toMap("glAccountId", glAccountId,
-                        "glAccountCategoryId", rowKey, "amountPercentage", new 
BigDecimal(rowValue),
+                        "glAccountCategoryId", rowEntry.getKey(), 
"amountPercentage", new BigDecimal(rowValue),
                         "userLogin", userLogin, "totalAmountPercentage", 
totalAmountPercentage);
             } else {
                 createGlAcctCatMemFromCostCentersMap = 
UtilMisc.toMap("glAccountId", glAccountId,
-                        "glAccountCategoryId", rowKey, "amountPercentage", new 
BigDecimal(0),
+                        "glAccountCategoryId", rowEntry.getKey(), 
"amountPercentage", new BigDecimal(0),
                         "userLogin", userLogin, "totalAmountPercentage", 
totalAmountPercentage);
             }
             try {
@@ -68,12 +65,11 @@ public class GeneralLedgerServices {
     }
 
     public static BigDecimal calculateCostCenterTotal(Map<String, String> 
amountPercentageMap) {
-        BigDecimal totalAmountPercentage = ZERO;
-        for (String rowKey : amountPercentageMap.keySet()) {
-            if (UtilValidate.isNotEmpty(amountPercentageMap.get(rowKey))) {
-                BigDecimal rowValue = new 
BigDecimal(amountPercentageMap.get(rowKey));
-                if (rowValue != null)
-                    totalAmountPercentage = 
totalAmountPercentage.add(rowValue);
+        BigDecimal totalAmountPercentage = BigDecimal.ZERO;
+        for (Map.Entry<String, String> rowEntry : 
amountPercentageMap.entrySet()) {
+            if (UtilValidate.isNotEmpty(rowEntry.getValue())) {
+                BigDecimal rowValue = new BigDecimal(rowEntry.getValue());
+                totalAmountPercentage = totalAmountPercentage.add(rowValue);
             }
         }
         return totalAmountPercentage;


Reply via email to