Open ghost opened 8 years ago
Do you have an actual use case where the value collection is a Set? Can you discuss it?
In this example, we've got a method that takes a SetMultimap
(that depends on the semantics provided by that class, namely, unique values per key). I want to use the output of Multimaps.index
as the parameter to that method, but that always returns a ListMultimap
, even if the input is a Set. So I'm forced to do an additional ImmutableSetMultimap.copyOf
for no reason.
Coincidentally, the method requiring the SetMultimap
is the same as mentioned in my last comment in #2487
Calls to ImmutableSetMultimap.copyOf(Multimaps.index(...))
account for about half a percent of all Multimaps.index
calls in Google's code. But probably SetMultimap
would be a good choice for a decent fraction of all callers. For starters, it would be interesting to see how many calls to index
pass a Set
.
Stream
support also chips away at the need for this. Still, we could consider it someday.
Currently, there's two
Multimap.index
methods both returning anImmutableListMultimap
. It would be useful if there was a method added alongside with the following signature:for the specific situation in which
values
is aSet
, then the returned multimap can be aSetMultimap
, as any subset of thevalues
set will also be a valid set. AndSetMultimap
offers semantic guarantees on value uniqueness that is not guaranteed byMultimap
orListMultimap
.Of course, this method will need a different name to not overload the existing
index
method to maintain source compatibility.