Hi there
I was doing some work with an own Multimap. The big difference is when I call asMap on the ArrayListMultimap I get a "Map<K, ArrayList<V>>" instead of "Multimap<K, Collection<V>>". I've done it like this:
public interface Multimap<K, V, L extends Collection<V>> {
...
Map<K, L> asMap();
...
}
So the ListMultimap would look like this:
public interface ListMultimap<K, V, L extends List<V>> extends Multimap<K, V, L> {}
And the ArrayListMultimap would show:
public class ArrayListMultimap<K, V> implements ListMultimap<K, V, ArrayList<V>> {
...
public Map<K, ArrayList<V>> asMap() { .... }
...
}
Is there a special reason not to do it so?
Cheers Adrian
--
guava-...@googlegroups.com
Project site: http://guava-libraries.googlecode.com
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: http://code.google.com/p/guava-libraries/issues/entry
To get help: http://stackoverflow.com/questions/ask (use the tag "guava")
A major reason for this is that we want to be able to remove the
backing lists from our internal map when they become empty but still
allow users to add elements to the wrapper to "resurrect" the key. If
we use a plain ArrayList, either we have to keep it in our internal
map forever, or we have to declare that, once the final element is
removed, it is no longer possible to modify the Multimap through the
list.
We did have a Multimap implementation internally that used ArrayList
(or any other type of your choice) for value collections. From the
two above options, we chose to never remove empty collections from our
backing map. This is probably fine for a lot of users. However, the
implementation never caught on. In part that's because there was no
singular use case that it served, so it was hard to know how to
promote it.