Closed GoogleCodeExporter closed 9 years ago
I suspect the decision to do this or not will primarily be philosophical, not a
matter of implementation details. We've been pretty insistent that Multimap is
not just a wrapper around a Map to Collections, but that Multimap is a map from
keys to multiple values that may or may not be implemented in terms of a Map of
Collections.
Additionally, there are some funky edge cases that make me pretty deeply
uncomfortable.
- What if the Map maps a key to an empty collection? The Multimap spec says
that that multimap.containsKey(key) is false in that case.
- What if the Map maps a key to null?
- What if you create a Multimap view of the Map and then someone puts null into
the map? The Multimap is basically corrupted now, but it can't find that out
without a full linear-time traversal.
Original comment by lowas...@google.com
on 11 Oct 2012 at 9:43
> I suspect the decision to do this or not will primarily be philosophical, not
a matter of implementation details.
I have no problem with this.
----
Here is how I handled the edge cases:
- containsKey(key) implemented in terms of submap.containsKey(key) && submap.get(key).isEmpty() instead of just submap.containsKey(key).
- A mapping to a null value is treated as non-existence. Multimap.get(key).add("x") replaces the mapping to null with a mapping to whatever is returned from createCollection()
- As for the final concern, Multimap.put is declared to accept both null keys and values, so both {null->["a","b"]} and {"y"->[null]} all seem acceptable to me.
Original comment by gil...@gmail.com
on 11 Oct 2012 at 10:14
A few issues with this idea:
-size() becomes O(#keys)
-get() would throw a NPE on access
We need to figure out what APIs to provide for interoperability between Maps
and Multimaps.
Original comment by kak@google.com
on 22 Aug 2013 at 10:42
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:13
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:18
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
gil...@gmail.com
on 11 Oct 2012 at 9:18