I have an entity that looks like this:
public class Snippet {
private Integer docId;
private Integer page;
private Payload payload;
}
The input data is a List<Snippet>
I need to create an index that allows us to iterate over docIds and pages and obtain the associated Snippet objects.
So a data structure like this:
Map<Integer, Map<Integer, List<Snippet>>>
I can use Java streams to get a Map<Integer, Map<Integer, Snippet>> - but this won't collect the list of Snippets at the end.
List<Snippet> input = ....;
input.stream()
.collect(Collectors.groupingBy(
Snippet::getDocId,
Collectors.toMap(Snippet::getPage, Function.identity())
)
);
How can I do the collecting to get a List as the final map value?