Julez :
How do I put/add eServiceReportsMapByBatchFile
with key oldReportId
to eServiceReportMap
without side-effects?
Map<String, Map<String, Set<EServiceReport>>> eServiceReportMap = new HashMap<>();
reports.forEach(report -> {
String oldReportId = report.getOldId();
Map<String, Set<EServiceReport>> eServiceReportsMapByBatchFile = // processing of batch files
...
eServiceReportMap.put(oldReportId, eServiceReportsMapByBatchFile);
});
return eServiceReportMap;
That is, I want it to become like this:
return reports.stream()
.map(report -> {
String oldReportId = report.getOldId();
Map<String, Set<EServiceReport>> eServiceReportsMapByBatchFile = // processing of batch files
...
// I don't know how and what to return here
}).collect(// I don't know what to do here);
Thank you.
Naman :
You're looking forward mostly to Collectors.toMap
which can be used as :
return reports.stream()
.collect(Collectors.toMap(report -> report.getOldId(),
report -> {
// batch processing for eServiceReportsMapByBatchFile
return eServiceReportsMapByBatchFile;
}));