I have read Map vs. Multimap with great interest. Multimaps are indeed a commonly used concept for which there's no standard JDK type.
As I am still exploring the Eclipse Collections library, I do have some questions about the usage of Eclipse Collection's Multimaps.
First, what is the most elegant way to create nested groups using Eclipse Collections? Using standard Java Streams, it is merely using another groupingBy Collector as downstream. This allows you to create nested groups as deep as you'd like.
Map<K1, Map<K2, List<V>>> collect = List.of(V, V, V, ...).stream()
.collect(
Collectors.groupingBy(
Function<V, K1>,
Collectors.groupingBy(
Function<V, K2>,
Collectors.toList()
)
)
);
Can you achieve something similar using Eclipse Collections?
As a follow-up question, I could not find a collect method to operate on a complete group, something like:
Multimap.collectMultiValues(Function<? super RichIterable<V>,?> function)
As I am relatively new to this API, this will probably exist but in another form. Until I learn of a more elegant solution, I rely on the following methods:
Multimap.keyMultiValuePairsView()
Multimap.forEachKeyMultiValues(Procedure2<? super K,? super RichIterable<V>> procedure)