Good afternoon, dear Russian-speaking developers. There is a code that needs to be debugged in a lambda expression. The question has already been asked on an English-language resource , but I did not wait for an exhaustive answer. Is that a comment where it is proposed first aggregation and then assembly into a collection, where I did not understand which particular collector the commentator had in mind. In general, having this method here:
public Map<Job, Map<Sheet, Collection<JobTransform>>> createPartitioning() { Map<Job, Map<Sheet, Collection<JobTransform>>> partitioning = new HashMap<>(); for (Sheet sheet : content) { Map<Job, Collection<JobTransform>> currentMap = sheet.createPartitioning(); for (Map.Entry<Job, Collection<JobTransform>> entry : currentMap.entrySet()) { partitioning .computeIfAbsent(entry.getKey(), key -> new HashMap<>()) .computeIfAbsent(sheet, key -> new LinkedList<>()) .addAll(entry.getValue()); } } return partitioning; }
I would like to convert it to a lambda expression. All I managed to find out was:
content.stream().flatMap(sheet -> sheet.createPartitioning().entrySet().stream()).co‌​llect() ...
But how exactly to write the code inside collect()
I, alas, can’t think at all. I will be glad of any help and forgive my not quite clear Russian! For a long time I live abroad and there is not enough practice in the “Russian language in programming”.