Is there any function in a Util libary (commonsXXX or something else) that can rotate a Map.
By rotating I mean I have a Map<User,Set<Permission>> that should be “rotated” to Map<Permission,Set<User>>?
I know it is not hard to implement, but using a common existing library seems to be better in terms of “don’t invent the wheel twice”.
I needed to do the same thing as what you describe, I used a multimap from commons-collections and wrote my own inverse function. (That was at least 3 years ago, using jdk1.4, so guava wasn’t an option.)
But if you changed your original map to a SetMultimap (I prefer multimaps anyway when mapping keys to collections of values, since they make inserting values easier), then you could use com.google.common.collect.Multimaps.invertFrom: