Standard question for new functionality: Who will use it? Can you point to specific projects that will replace existing code with this new commons method?
Utility libraries have a habit of collecting a lot of unused cruft that was added because it seemed logical, but that did not have an actual, non-hypothetical need. Unless you can point to specific code where you need to use this, I wouldn't do it. On Thu, Dec 11, 2025 at 12:03 PM Paul King <[email protected]> wrote: > > Hi folks, > > I noticed that Collections doesn't have the equivalent of Guava's > inverse() for ImmutableMultimaps or Eclipse Collections flip() for its > multimaps. Would there be interest in looking at a PR for such > functionality? > > Here is an example: > > Map<String, Set<String>> citiesLived = new HashSetValuedHashMap<>(4); > citiesLived.put("Alice", "N.Y."); > citiesLived.put("Alice", "L.A."); > citiesLived.put("Alice", "Chicago"); > citiesLived.put("Bob", "N.Y."); > citiesLived.put("Cara", "L.A."); > citiesLived.put("Cara", "Chicago"); > > Here is the proposed syntax: > > Map<String, Set<String>> inverted = citiesLived.inverse() > > The current way to get this would be iterating over entries and > creating the inverse multimap manually or use streams like below: > > Map<String, Set<String>> inverted = citiesLived.entries().stream() > .collect(Collectors.groupingBy( > Map.Entry::getValue, > // group by city > Collectors.mapping(Map.Entry::getKey, // collect names > Collectors.toSet()) > )); > > System.out.println("Original: " + citiesLived); > System.out.println("Inverted: " + inverted); > > Output would be: > Original: {Cara=[L.A., Chicago], Bob=[N.Y.], Alice=[L.A., N.Y., Chicago]} > Inverted: {N.Y.=[Bob, Alice], Chicago=[Cara, Alice], L.A.=[Cara, Alice]} > > Thoughts? > > Cheers, Paul. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > -- Elliotte Rusty Harold [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
