public List<Receipt> buildTitle(List<ComServiceResponse> comServiceResponses) {
List<Receipt> receipts = new ArrayList<>();
for (ComServiceResponse comService : comServiceResponses) {
// if list not empty
if (comService != null && comService.getComment() != null && !comService.getComment().getComs().isEmpty()) {
String date = calendarService.formatDate(comService.getPeriod());
boolean paymentStatus = isPayed(comService.getComment().getComs());
double totalAmount = calculateComServiceTotalAmount(comService.getComment().getComs());
Receipt receipt = new Receipt();
receipt.setPeriod(date);
receipt.setPayed(paymentStatus);
receipt.setTotalAmount(totalAmount);
receipt.setAccount(comService.getAccount());
receipt.setServiceIcon(properties.getMyVillageIcon());
receipt.setName(comService.getComment().getComs().get(0).getOwner());
receipt.setAddress(comService.getComment().getComs().get(0).getAddress());
receipts.add(receipt);
}
}
return receipts;
}
public List<Receipt> buildTitle(List<ComServiceResponse> comServiceResponses) {
return comServiceResponses.stream()
.map(ComServiceResponse::getComment)
.map(Comment::getComs)
.filter(Objects::nonNull)
.flatMap(List::stream) // Collection::stream ?
.map(comService -> { // todo:: extract to mapping method
var date = calendarService.formatDate(comService.getPeriod()); // todo :: check for null here and below
var paymentStatus = isPayed(comService.getComment().getComs());
var totalAmount = calculateComServiceTotalAmount(comService.getComment().getComs());
var receipt = new Receipt(); // todo:: beter use fluent accessors or builder
receipt.setPeriod(date);
receipt.setPayed(paymentStatus);
receipt.setTotalAmount(totalAmount);
receipt.setAccount(comService.getAccount());
receipt.setServiceIcon(properties.getMyVillageIcon());
receipt.setName(comService.getComment().getComs().get(0).getOwner());
receipt.setAddress(comService.getComment().getComs().get(0).getAddress());
return receipt;
})
.toList();
}