FINERACT-2421: Refractor redundant and some deprecated code as per new Java 21 style (Phase 3)

This commit is contained in:
Aman-Mittal
2025-12-26 19:27:38 +01:00
committed by Adam Saghy
parent 7dac82a4fc
commit 0ba1745443
18 changed files with 82 additions and 145 deletions
@@ -3150,9 +3150,8 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
.orElse(null);
final List<LoanCharge> liftedLoanCharges = new ArrayList<>();
installments.stream().filter(installment -> !installment.getDueDate().isBefore(transactionDate)).forEach(i -> {
liftedLoanCharges.addAll(getLoanChargesOfInstallment(ctx.getCharges(), i, 1));
});
installments.stream().filter(installment -> !installment.getDueDate().isBefore(transactionDate))
.forEach(i -> liftedLoanCharges.addAll(getLoanChargesOfInstallment(ctx.getCharges(), i, 1)));
installments.removeIf(i -> i.getInstallmentNumber() != null && !i.isDownPayment() && !i.getDueDate().isBefore(transactionDate));
@@ -3308,10 +3307,10 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
private LocalDate calculateReAgedNextDate(final PeriodFrequencyType frequencyType, final LocalDate dueDate,
final Integer frequencyNumber) {
return switch (frequencyType) {
case DAYS -> dueDate.plusDays((long) frequencyNumber);
case WEEKS -> dueDate.plusWeeks((long) frequencyNumber);
case MONTHS -> dueDate.plusMonths((long) frequencyNumber);
case YEARS -> dueDate.plusYears((long) frequencyNumber);
case DAYS -> dueDate.plusDays(frequencyNumber);
case WEEKS -> dueDate.plusWeeks(frequencyNumber);
case MONTHS -> dueDate.plusMonths(frequencyNumber);
case YEARS -> dueDate.plusYears(frequencyNumber);
default -> throw new UnsupportedOperationException();
};
}
@@ -3799,10 +3798,8 @@ public class AdvancedPaymentScheduleTransactionProcessor extends AbstractLoanRep
private void createChargeMappingsForInstallment(final LoanRepaymentScheduleInstallment installment,
List<ReAgedChargeEqualAmortizationValues> reAgedChargeEqualAmortizationValues, Integer index) {
reAgedChargeEqualAmortizationValues.forEach(amortizationValue -> {
installment.getInstallmentCharges().add(new LoanInstallmentCharge(
amortizationValue.equalAmortizationValues.calculateValueBigDecimal(index), amortizationValue.charge, installment));
});
reAgedChargeEqualAmortizationValues.forEach(amortizationValue -> installment.getInstallmentCharges().add(new LoanInstallmentCharge(
amortizationValue.equalAmortizationValues.calculateValueBigDecimal(index), amortizationValue.charge, installment)));
}
private FirstReAgeInstallmentProps calculateFirstReAgeInstallmentProps(List<LoanRepaymentScheduleInstallment> installments,
@@ -78,9 +78,8 @@ public class AdvancedPaymentAllocationsValidator {
AtomicInteger pastDueRuleInteger = new AtomicInteger();
AtomicInteger dueRuleInteger = new AtomicInteger();
AtomicInteger inAdvanceRuleInteger = new AtomicInteger();
paymentAllocationRule.getAllocationTypes().forEach(paymentAllocationType -> {
validateAllocationType(paymentAllocationType, pastDueRuleInteger, dueRuleInteger, inAdvanceRuleInteger);
});
paymentAllocationRule.getAllocationTypes().forEach(paymentAllocationType -> validateAllocationType(paymentAllocationType,
pastDueRuleInteger, dueRuleInteger, inAdvanceRuleInteger));
});
}
@@ -122,14 +121,14 @@ public class AdvancedPaymentAllocationsValidator {
}
private boolean hasAtLeastOneDefaultPaymentAllocation(List<LoanProductPaymentAllocationRule> rules) {
return rules != null && rules.stream() //
return rules != null && !rules.stream() //
.filter(r -> PaymentAllocationTransactionType.DEFAULT.equals(r.getTransactionType())) //
.toList() //
.size() > 0;
.isEmpty();
}
private boolean hasLoanProductPaymentAllocationRule(List<LoanProductPaymentAllocationRule> rules) {
return rules != null && rules.size() > 0;
return rules != null && !rules.isEmpty();
}
private void raiseValidationError(String globalisationMessageCode, String msg) {
@@ -258,12 +258,12 @@ class AdvancedPaymentScheduleTransactionProcessorTest {
when(loan.getPaymentAllocationRules()).thenReturn(List.of(loanPaymentAllocationRule));
when(loanPaymentAllocationRule.getTransactionType()).thenReturn(PaymentAllocationTransactionType.DEFAULT);
when(loanPaymentAllocationRule.getAllocationTypes()).thenReturn(List.of(PaymentAllocationType.DUE_PRINCIPAL));
when(loanTransaction.isOn(eq(transactionDate))).thenReturn(true);
when(loanTransaction.isOn(transactionDate)).thenReturn(true);
underTest.processLatestTransaction(loanTransaction,
new TransactionCtx(currency, List.of(installment), Set.of(charge), new MoneyHolder(overpaidAmount), null));
Mockito.verify(installment, times(1)).payFeeChargesComponent(eq(transactionDate), eq(chargeAmountMoney));
Mockito.verify(installment, times(1)).payFeeChargesComponent(transactionDate, chargeAmountMoney);
Mockito.verify(loanTransaction, times(1)).updateComponents(refEq(zero), refEq(zero), refEq(chargeAmountMoney), refEq(zero));
assertEquals(0, BigDecimal.valueOf(20).compareTo(loanTransaction.getAmount(currency).minus(chargeAmountMoney).getAmount()));
assertEquals(0, chargeAmount.compareTo(installment.getFeeChargesCharged(currency).getAmount()));
@@ -220,18 +220,15 @@ class AdvancedPaymentAllocationsJsonParserTest {
private static List<Pair<Integer, PaymentAllocationType>> createPaymentAllocationTypeList() {
AtomicInteger i = new AtomicInteger(1);
List<Pair<Integer, PaymentAllocationType>> list = EnumSet.allOf(PaymentAllocationType.class).stream()
.map(p -> Pair.of(i.getAndIncrement(), p)).toList();
return list;
return EnumSet.allOf(PaymentAllocationType.class).stream().map(p -> Pair.of(i.getAndIncrement(), p)).toList();
}
@NonNull
private JsonCommand createJsonCommand(Map<String, Object> jsonMap) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonMap);
JsonCommand command = JsonCommand.from(json, JsonParser.parseString(json), fromJsonHelper, null, 1L, 2L, 3L, 4L, null, null, null,
null, null, null, null, null, null);
return command;
return JsonCommand.from(json, JsonParser.parseString(json), fromJsonHelper, null, 1L, 2L, 3L, 4L, null, null, null, null, null,
null, null, null, null);
}
}