Extract method to avoid duplicate code.

This commit is contained in:
Sebastian Sieber
2020-12-07 16:31:58 +01:00
parent 9e496f0f55
commit dcf7f82b01

View File

@@ -52,8 +52,12 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
* @return the total amount * @return the total amount
*/ */
protected BigDecimal getChargesForPercent(BigDecimal percent) { protected BigDecimal getChargesForPercent(BigDecimal percent) {
BigDecimal res = BigDecimal.ZERO;
IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges(); IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
return sumAllowanceCharge(percent, charges);
}
private BigDecimal sumAllowanceCharge(BigDecimal percent, IZUGFeRDAllowanceCharge[] charges) {
BigDecimal res = BigDecimal.ZERO;
if ((charges != null) && (charges.length > 0)) { if ((charges != null) && (charges.length > 0)) {
for (IZUGFeRDAllowanceCharge currentCharge : charges) { for (IZUGFeRDAllowanceCharge currentCharge : charges) {
if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)) { if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)) {
@@ -70,8 +74,16 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
* @return the space separated String * @return the space separated String
*/ */
protected String getChargeReasonForPercent(BigDecimal percent) { protected String getChargeReasonForPercent(BigDecimal percent) {
String res = " ";
IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges(); IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
String res = getAllowanceChargeReasonForPercent(percent, charges);
if ("".equals(res)) {
res="Charges";
}
return res;
}
private String getAllowanceChargeReasonForPercent(BigDecimal percent, IZUGFeRDAllowanceCharge[] charges) {
String res = " ";
if ((charges != null) && (charges.length > 0)) { if ((charges != null) && (charges.length > 0)) {
for (IZUGFeRDAllowanceCharge currentCharge : charges) { for (IZUGFeRDAllowanceCharge currentCharge : charges) {
if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)) { if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)) {
@@ -82,9 +94,6 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
} }
} }
res=res.substring(0,res.length()-1); res=res.substring(0,res.length()-1);
if (res.equals("")) {
res="Charges";
}
return res; return res;
} }
@@ -94,19 +103,9 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
* @return the space separated String * @return the space separated String
*/ */
protected String getAllowanceReasonForPercent(BigDecimal percent) { protected String getAllowanceReasonForPercent(BigDecimal percent) {
String res = " ";
IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances(); IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
if ((allowances != null) && (allowances.length > 0)) { String res = getAllowanceChargeReasonForPercent(percent, allowances);
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) { if ("".equals(res)) {
if ((percent==null)||(currentAllowance.getTaxPercent().compareTo(percent)==0)) {
if (currentAllowance.getReason()!=null) {
res = res+currentAllowance.getReason()+" ";
}
}
}
}
res=res.substring(0,res.length()-1);
if (res.equals("")) {
res="Allowances"; res="Allowances";
} }
return res; return res;
@@ -119,16 +118,8 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
* @return the total amount * @return the total amount
*/ */
protected BigDecimal getAllowancesForPercent(BigDecimal percent) { protected BigDecimal getAllowancesForPercent(BigDecimal percent) {
BigDecimal res = BigDecimal.ZERO;
IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances(); IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
if ((allowances != null) && (allowances.length > 0)) { return sumAllowanceCharge(percent, allowances);
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
if ((percent==null)||(currentAllowance.getTaxPercent().compareTo(percent)==0)) {
res = res.add(currentAllowance.getTotalAmount(this));
}
}
}
return res;
} }
/*** /***