-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Description
Neither ImmutableListMultimap.Builder nor ImmutableSetMultimap.Builder explicitly specify what the iteration order of the resulting Multimap is if orderKeysBy or orderValuesBy is not specified. Neither build nor put nor the class-level Javadoc on the builder itself says anything about ordering; ImmutableListMultimap also mentions no guarantees. ListMultimap does guarantee it “maintains the insertion ordering of values for a given key” but says nothing about the ordering of the keys themselves.
It is possible that these classes intentionally don’t give ordering guarantees, but it seems like it might be an accidental omission in the documentation because some sort on the ordering seems implicit in putAll(Multimap):
The generated multimap's key and value orderings correspond to the iteration ordering of the `multimap.asMap()` view, with new keys and values following any existing keys and values.
and also ImmutableMultimap.copyOf:
Returns an immutable multimap containing the same mappings as multimap. The generated multimap's key and value orderings correspond to the iteration ordering of the `multimap.asMap()` view.
And even if there is no intention to guarantee anything, saying so explicitly would be nice.
(use case: for an internal utility library, I am writing Kotlin extension functions to have versions of associateBy for multimaps and am trying to determine how much to guarantee in the documentation)