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();
}
var dateString = "202208";
var inFormat = new SimpleDateFormat("yyyyMM");
var date = inFormat.parse(dateString);
System.out.println(date); // Mon Aug 01 00:00:00 MSK 2022
var outFormat = new SimpleDateFormat("yyyy MMMM");
var dateFormatSymbols = new DateFormatSymbols();
dateFormatSymbols.setMonths(new String[]{"Папа", "у", "Вити", "силен", "в", "джаве.", "Работает", "Август", "папа", "за", "Витю", "весь", "год"});
outFormat.setDateFormatSymbols(dateFormatSymbols);
System.out.println(outFormat.format(date)); // 2022 Август