Skip to content

Commit

Permalink
P4ADEV-1774 modified collect in mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
RiccardoGiuliani committed Jan 14, 2025
1 parent 7c029a8 commit b040e23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@Service
public class DebtPositionMapper {

private final PaymentOptionMapper paymentOptionMapper;

private static final Supplier<TreeSet<PaymentOption>> TREE_SET_SUPPLIER = TreeSet::new;
private static final Collector<PaymentOption, ?, SortedSet<PaymentOption>> toTreeSet = Collectors.toCollection(TreeSet::new);

public DebtPositionMapper(PaymentOptionMapper paymentOptionMapper) {
this.paymentOptionMapper = paymentOptionMapper;
Expand Down Expand Up @@ -46,11 +47,7 @@ public Pair<DebtPosition, Map<InstallmentNoPII, Installment>> mapToModel(DebtPos
installmentMapping.putAll(paymentOptionWithInstallments.getSecond());
return paymentOptionWithInstallments.getFirst();
})
.collect(
TREE_SET_SUPPLIER,
SortedSet::add,
SortedSet::addAll
);
.collect(toTreeSet);

debtPosition.setPaymentOptions(paymentOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@Service
public class PaymentOptionMapper {

private final InstallmentMapper installmentMapper;
private final InstallmentPIIMapper installmentPIIMapper;

private static final Supplier<TreeSet<InstallmentNoPII>> TREE_SET_SUPPLIER = TreeSet::new;
private static final Collector<InstallmentNoPII, ?, SortedSet<InstallmentNoPII>> toTreeSet = Collectors.toCollection(TreeSet::new);

public PaymentOptionMapper(InstallmentMapper installmentMapper, InstallmentPIIMapper installmentPIIMapper) {
this.installmentMapper = installmentMapper;
Expand All @@ -39,10 +40,7 @@ public Pair<PaymentOption, Map<InstallmentNoPII, Installment>> mapToModel(Paymen
installmentMapping.put(installmentNoPII, installment);
return installmentNoPII;
})
.collect(
TREE_SET_SUPPLIER,
SortedSet::add,
SortedSet::addAll);
.collect(toTreeSet);

PaymentOption paymentOption = new PaymentOption();
paymentOption.setPaymentOptionId(dto.getPaymentOptionId());
Expand Down

0 comments on commit b040e23

Please sign in to comment.