Skip to content

Commit dce3c66

Browse files
Aman-Mittaladamsaghy
authored andcommitted
FINERACT-2326: Refractor redundant and some deprecated code as per new Java 21 style
1 parent 399789b commit dce3c66

File tree

29 files changed

+117
-232
lines changed

29 files changed

+117
-232
lines changed

fineract-charge/src/main/java/org/apache/fineract/portfolio/charge/domain/ChargeCalculationType.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,14 @@ public static Object[] validValuesForTrancheDisbursement() {
7070
}
7171

7272
public static ChargeCalculationType fromInt(final Integer chargeCalculation) {
73-
ChargeCalculationType chargeCalculationType = ChargeCalculationType.INVALID;
74-
switch (chargeCalculation) {
75-
case 1:
76-
chargeCalculationType = FLAT;
77-
break;
78-
case 2:
79-
chargeCalculationType = PERCENT_OF_AMOUNT;
80-
break;
81-
case 3:
82-
chargeCalculationType = PERCENT_OF_AMOUNT_AND_INTEREST;
83-
break;
84-
case 4:
85-
chargeCalculationType = PERCENT_OF_INTEREST;
86-
break;
87-
case 5:
88-
chargeCalculationType = PERCENT_OF_DISBURSEMENT_AMOUNT;
89-
break;
90-
}
91-
return chargeCalculationType;
73+
return switch (chargeCalculation) {
74+
case 1 -> FLAT;
75+
case 2 -> PERCENT_OF_AMOUNT;
76+
case 3 -> PERCENT_OF_AMOUNT_AND_INTEREST;
77+
case 4 -> PERCENT_OF_INTEREST;
78+
case 5 -> PERCENT_OF_DISBURSEMENT_AMOUNT;
79+
default -> INVALID;
80+
};
9281
}
9382

9483
public boolean isPercentageOfAmount() {

fineract-client-feign/src/main/java/org/apache/fineract/client/util/FeignParts.java

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,21 @@ public static String mediaType(String fileName) {
5656
}
5757
String ext = fileName.substring(dotPos + 1).toLowerCase();
5858

59-
switch (ext) {
60-
case "jpg":
61-
case "jpeg":
62-
return "image/jpeg";
63-
case "png":
64-
return "image/png";
65-
case "tif":
66-
case "tiff":
67-
return "image/tiff";
68-
case "gif":
69-
return "image/gif";
70-
case "pdf":
71-
return "application/pdf";
72-
case "docx":
73-
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
74-
case "doc":
75-
return "application/msword";
76-
case "xlsx":
77-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
78-
case "xls":
79-
return "application/vnd.ms-excel";
80-
case "odt":
81-
return "application/vnd.oasis.opendocument.text";
82-
case "ods":
83-
return "application/vnd.oasis.opendocument.spreadsheet";
84-
case "txt":
85-
return "text/plain";
86-
default:
87-
return "application/octet-stream";
88-
}
59+
return switch (ext) {
60+
case "jpg", "jpeg" -> "image/jpeg";
61+
case "png" -> "image/png";
62+
case "tif", "tiff" -> "image/tiff";
63+
case "gif" -> "image/gif";
64+
case "pdf" -> "application/pdf";
65+
case "docx" -> "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
66+
case "doc" -> "application/msword";
67+
case "xlsx" -> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
68+
case "xls" -> "application/vnd.ms-excel";
69+
case "odt" -> "application/vnd.oasis.opendocument.text";
70+
case "ods" -> "application/vnd.oasis.opendocument.spreadsheet";
71+
case "txt" -> "text/plain";
72+
default -> "application/octet-stream";
73+
};
8974
}
9075

9176
/**

fineract-core/src/main/java/org/apache/fineract/infrastructure/core/exceptionmapper/DefaultExceptionMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import jakarta.ws.rs.core.Response;
2525
import jakarta.ws.rs.ext.ExceptionMapper;
2626
import java.util.Map;
27+
import java.util.Objects;
2728
import lombok.extern.slf4j.Slf4j;
28-
import org.apache.commons.lang3.ObjectUtils;
2929
import org.apache.fineract.infrastructure.core.exception.ErrorHandler;
3030
import org.springframework.context.annotation.Scope;
3131
import org.springframework.stereotype.Component;
@@ -43,8 +43,9 @@ public int errorCode() {
4343
@Override
4444
public Response toResponse(RuntimeException exception) {
4545
log.warn("Exception occurred", ErrorHandler.findMostSpecificException(exception));
46+
4647
return Response.status(SC_INTERNAL_SERVER_ERROR)
47-
.entity(Map.of("Exception", ObjectUtils.defaultIfNull(exception.getMessage(), "No error message available")))
48+
.entity(Map.of("Exception", Objects.requireNonNullElse(exception.getMessage(), "No error message available")))
4849
.type(MediaType.APPLICATION_JSON).build();
4950
}
5051
}

fineract-core/src/main/java/org/apache/fineract/infrastructure/core/service/database/DataSourcePerTenantServiceFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ public DataSource createNewDataSourceFor(FineractPlatformTenant tenant, Fineract
9898

9999
// https://github.com/brettwooldridge/HikariCP/wiki/MBean-(JMX)-Monitoring-and-Management
100100
config.setRegisterMbeans(true);
101-
meterRegistry.ifPresent(registry -> {
102-
config.setMetricsTrackerFactory(new TenantConnectionPoolMetricsTrackerFactory(tenant.getTenantIdentifier(), registry));
103-
});
101+
meterRegistry.ifPresent(registry -> config
102+
.setMetricsTrackerFactory(new TenantConnectionPoolMetricsTrackerFactory(tenant.getTenantIdentifier(), registry)));
104103

105104
// https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
106105
// These are the properties for each Tenant DB; the same configuration

fineract-core/src/main/java/org/apache/fineract/portfolio/common/domain/DaysInMonthType.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,11 @@ public static Object[] integerValues() {
5959
public static DaysInMonthType fromInt(final Integer type) {
6060
DaysInMonthType repaymentFrequencyType = DaysInMonthType.INVALID;
6161
if (type != null) {
62-
switch (type) {
63-
case 1:
64-
repaymentFrequencyType = DaysInMonthType.ACTUAL;
65-
break;
66-
case 30:
67-
repaymentFrequencyType = DaysInMonthType.DAYS_30;
68-
break;
69-
70-
}
62+
repaymentFrequencyType = switch (type) {
63+
case 1 -> DaysInMonthType.ACTUAL;
64+
case 30 -> DaysInMonthType.DAYS_30;
65+
default -> repaymentFrequencyType;
66+
};
7167
}
7268
return repaymentFrequencyType;
7369
}

fineract-core/src/main/java/org/apache/fineract/portfolio/common/domain/DaysInYearType.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,13 @@ public static Object[] integerValues() {
6363
public static DaysInYearType fromInt(final Integer type) {
6464
DaysInYearType repaymentFrequencyType = DaysInYearType.INVALID;
6565
if (type != null) {
66-
switch (type) {
67-
case 1:
68-
repaymentFrequencyType = DaysInYearType.ACTUAL;
69-
break;
70-
case 360:
71-
repaymentFrequencyType = DaysInYearType.DAYS_360;
72-
break;
73-
case 364:
74-
repaymentFrequencyType = DaysInYearType.DAYS_364;
75-
break;
76-
case 365:
77-
repaymentFrequencyType = DaysInYearType.DAYS_365;
78-
break;
79-
}
66+
repaymentFrequencyType = switch (type) {
67+
case 1 -> DaysInYearType.ACTUAL;
68+
case 360 -> DaysInYearType.DAYS_360;
69+
case 364 -> DaysInYearType.DAYS_364;
70+
case 365 -> DaysInYearType.DAYS_365;
71+
default -> repaymentFrequencyType;
72+
};
8073
}
8174
return repaymentFrequencyType;
8275
}

fineract-loan/src/main/java/org/apache/fineract/portfolio/delinquency/helper/DelinquencyEffectivePauseHelperImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public List<LoanDelinquencyActionData> calculateEffectiveDelinquencyList(List<Lo
4242
.collect(Collectors.groupingBy(LoanDelinquencyAction::getAction));
4343
List<LoanDelinquencyActionData> effective = new ArrayList<>();
4444
List<LoanDelinquencyAction> pauses = partitioned.get(DelinquencyAction.PAUSE);
45-
if (pauses != null && pauses.size() > 0) {
45+
if (pauses != null && !pauses.isEmpty()) {
4646
for (LoanDelinquencyAction loanDelinquencyAction : pauses) {
4747
Optional<LoanDelinquencyAction> resume = findMatchingResume(loanDelinquencyAction, partitioned.get(RESUME));
4848
LoanDelinquencyActionData loanDelinquencyActionData = new LoanDelinquencyActionData(loanDelinquencyAction);
@@ -91,7 +91,7 @@ public Long getPausedDaysWithinRange(List<LoanDelinquencyActionData> effectiveDe
9191
}
9292

9393
private Optional<LoanDelinquencyAction> findMatchingResume(LoanDelinquencyAction pause, List<LoanDelinquencyAction> resumes) {
94-
if (resumes != null && resumes.size() > 0) {
94+
if (resumes != null && !resumes.isEmpty()) {
9595
for (LoanDelinquencyAction resume : resumes) {
9696
if (!pause.getStartDate().isAfter(resume.getStartDate()) && !resume.getStartDate().isAfter(pause.getEndDate())) {
9797
return Optional.of(resume);

fineract-loan/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyReadPlatformServiceImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,9 @@ private LocalDate getNextUnpaidInstallmentDueDate(final Loan loan) {
337337
isCurrentDateBeforeInstallmentAndLoanPeriod = DateUtils.isEqual(currentBusinessDate, installment.getDueDate())
338338
&& DateUtils.isBefore(currentBusinessDate, expectedMaturityDate);
339339
}
340-
if (isCurrentDateBeforeInstallmentAndLoanPeriod) {
341-
if (installment.isNotFullyPaidOff()) {
342-
nextUnpaidInstallmentDate = installment.getDueDate();
343-
break;
344-
}
340+
if (isCurrentDateBeforeInstallmentAndLoanPeriod && installment.isNotFullyPaidOff()) {
341+
nextUnpaidInstallmentDate = installment.getDueDate();
342+
break;
345343
}
346344
}
347345
return nextUnpaidInstallmentDate;

fineract-loan/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyWritePlatformServiceHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public Map<String, Object> setLoanDelinquencyTag(Loan loan, Long delinquencyRang
127127
changes.put("current", loanDelinquencyTag.getDelinquencyRange());
128128
}
129129
}
130-
if (loanDelinquencyTagHistory.size() > 0) {
130+
if (!loanDelinquencyTagHistory.isEmpty()) {
131131
this.loanDelinquencyTagRepository.saveAllAndFlush(loanDelinquencyTagHistory);
132132
// if installment level delinquency is enabled event will be raised at installment level calculation, no
133133
// need to raise the event here
@@ -173,10 +173,10 @@ public void applyDelinquencyForLoanInstallments(final Loan loan, final Delinquen
173173
private void removeDelinquencyTagsForNonExistingInstallments(Long loanId) {
174174
List<LoanInstallmentDelinquencyTag> currentLoanInstallmentDelinquencyTags = loanInstallmentDelinquencyTagRepository
175175
.findByLoanId(loanId);
176-
if (currentLoanInstallmentDelinquencyTags != null && currentLoanInstallmentDelinquencyTags.size() > 0) {
176+
if (currentLoanInstallmentDelinquencyTags != null && !currentLoanInstallmentDelinquencyTags.isEmpty()) {
177177
List<Long> loanInstallmentTagsForDelete = currentLoanInstallmentDelinquencyTags.stream()
178178
.filter(tag -> tag.getInstallment() == null).map(tag -> tag.getId()).toList();
179-
if (loanInstallmentTagsForDelete.size() > 0) {
179+
if (!loanInstallmentTagsForDelete.isEmpty()) {
180180
loanInstallmentDelinquencyTagRepository.deleteAllLoanInstallmentsTagsByIds(loanInstallmentTagsForDelete);
181181
}
182182
}
@@ -260,7 +260,7 @@ private boolean setDelinquencyDetailsForInstallment(final Loan loan, final LoanR
260260

261261
}
262262

263-
if (installmentDelinquencyTags.size() > 0) {
263+
if (!installmentDelinquencyTags.isEmpty()) {
264264
loanInstallmentDelinquencyTagRepository.saveAllAndFlush(installmentDelinquencyTags);
265265
}
266266
return isDelinquencyRangeChanged;

fineract-loan/src/main/java/org/apache/fineract/portfolio/delinquency/service/DelinquencyWritePlatformServiceImpl.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public void removeDelinquencyTagToLoan(final Loan loan) {
291291
@Override
292292
public void cleanLoanDelinquencyTags(Loan loan) {
293293
List<LoanDelinquencyTagHistory> loanDelinquencyTags = this.loanDelinquencyTagRepository.findByLoan(loan);
294-
if (loanDelinquencyTags != null && loanDelinquencyTags.size() > 0) {
294+
if (loanDelinquencyTags != null && !loanDelinquencyTags.isEmpty()) {
295295
this.loanDelinquencyTagRepository.deleteAll(loanDelinquencyTags);
296296
}
297297
}
@@ -362,9 +362,7 @@ private DelinquencyBucket updateDelinquencyBucket(DelinquencyBucket delinquencyB
362362

363363
private void setDelinquencyBucketMappings(DelinquencyBucket delinquencyBucket, DelinquencyBucketData data) {
364364
List<Long> rangeIds = new ArrayList<>();
365-
data.getRanges().forEach(dataRange -> {
366-
rangeIds.add(dataRange.getId());
367-
});
365+
data.getRanges().forEach(dataRange -> rangeIds.add(dataRange.getId()));
368366

369367
List<DelinquencyRange> ranges = repositoryRange.findAllById(rangeIds);
370368
validateDelinquencyRanges(ranges);
@@ -383,11 +381,9 @@ private void validateDelinquencyRanges(List<DelinquencyRange> ranges) {
383381

384382
DelinquencyRange prevDelinquencyRange = null;
385383
for (DelinquencyRange delinquencyRange : ranges) {
386-
if (prevDelinquencyRange != null) {
387-
if (isOverlapped(prevDelinquencyRange, delinquencyRange)) {
388-
final String errorMessage = "The delinquency ranges age days values are overlaped";
389-
throw new DelinquencyBucketAgesOverlapedException(errorMessage, prevDelinquencyRange, delinquencyRange);
390-
}
384+
if (prevDelinquencyRange != null && isOverlapped(prevDelinquencyRange, delinquencyRange)) {
385+
final String errorMessage = "The delinquency ranges age days values are overlaped";
386+
throw new DelinquencyBucketAgesOverlapedException(errorMessage, prevDelinquencyRange, delinquencyRange);
391387
}
392388
prevDelinquencyRange = delinquencyRange;
393389
}

0 commit comments

Comments
 (0)