Improved: Fixing defects reported by FindBugs, package
org.apache.ofbiz.accounting.ledger.
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.
@@ -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,11 +65,10 @@ 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)
+ 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);
}
}
