You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by su...@apache.org on 2020/06/04 09:11:40 UTC

[ofbiz-framework] branch trunk updated: Improved: Enforce noninstantiability to BillingAccountWorker Class. (#167)

This is an automated email from the ASF dual-hosted git repository.

surajk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 9ade9d7  Improved: Enforce noninstantiability to BillingAccountWorker Class. (#167)
9ade9d7 is described below

commit 9ade9d776b41cbe33731ec4702d6c1d5dd3ff990
Author: Suraj Khurana <64...@users.noreply.github.com>
AuthorDate: Thu Jun 4 14:41:31 2020 +0530

    Improved: Enforce noninstantiability to BillingAccountWorker Class. (#167)
    
    (OFBIZ-11721)
    Made class as final, added private constructor, changed data members to private and corrected names as per naming convention.
---
 .../ofbiz/accounting/payment/BillingAccountWorker.java   | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/BillingAccountWorker.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/BillingAccountWorker.java
index 13977a7..475f827 100644
--- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/BillingAccountWorker.java
+++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/payment/BillingAccountWorker.java
@@ -50,13 +50,15 @@ import org.apache.ofbiz.service.ServiceUtil;
 /**
  * Worker methods for BillingAccounts
  */
-public class BillingAccountWorker {
+public final class BillingAccountWorker {
 
     private static final String MODULE = BillingAccountWorker.class.getName();
     private static final String RES_ERROR = "AccountingUiLabels";
-    public static final int decimals = UtilNumber.getBigDecimalScale("order.decimals");
-    public static final RoundingMode rounding = UtilNumber.getRoundingMode("order.rounding");
-    public static final BigDecimal ZERO = BigDecimal.ZERO.setScale(decimals, rounding);
+    private static final int DECIMALS = UtilNumber.getBigDecimalScale("order.decimals");
+    private static final RoundingMode ROUNDING = UtilNumber.getRoundingMode("order.rounding");
+    private static final BigDecimal ZERO = BigDecimal.ZERO.setScale(DECIMALS, ROUNDING);
+
+    protected BillingAccountWorker() { }
 
     public static List<Map<String, Object>> makePartyBillingAccountList(GenericValue userLogin, String currencyUomId, String partyId, Delegator delegator, LocalDispatcher dispatcher) throws GeneralException {
         List<Map<String, Object>> billingAccountList = new LinkedList<>();
@@ -123,7 +125,7 @@ public class BillingAccountWorker {
     public static BigDecimal getBillingAccountAvailableBalance(GenericValue billingAccount) throws GenericEntityException {
         if ((billingAccount != null) && (billingAccount.get("accountLimit") != null)) {
             BigDecimal accountLimit = billingAccount.getBigDecimal("accountLimit");
-            BigDecimal availableBalance = accountLimit.subtract(OrderReadHelper.getBillingAccountBalance(billingAccount)).setScale(decimals, rounding);
+            BigDecimal availableBalance = accountLimit.subtract(OrderReadHelper.getBillingAccountBalance(billingAccount)).setScale(DECIMALS, ROUNDING);
             return availableBalance;
         }
         Debug.logWarning("Available balance requested for null billing account, returning zero", MODULE);
@@ -161,7 +163,7 @@ public class BillingAccountWorker {
             }
         }
 
-        balance = balance.setScale(decimals, rounding);
+        balance = balance.setScale(DECIMALS, ROUNDING);
         return balance;
     }
 
@@ -175,7 +177,7 @@ public class BillingAccountWorker {
         BigDecimal netBalance = getBillingAccountNetBalance(billingAccount.getDelegator(), billingAccount.getString("billingAccountId"));
         BigDecimal accountLimit = billingAccount.getBigDecimal("accountLimit");
 
-        return accountLimit.subtract(netBalance).setScale(decimals, rounding);
+        return accountLimit.subtract(netBalance).setScale(DECIMALS, ROUNDING);
     }
 
     public static Map<String, Object> calcBillingAccountBalance(DispatchContext dctx, Map<String, ? extends Object> context) {