Hi,

we are currently working on a new MultiValuedMap interface for
collections, see https://issues.apache.org/jira/browse/COLLECTIONS-508.

During the work we stumbled across an issue we would like to discuss.
The MultiValuedMap is basically a Map that can hold multiple values
associated to a given key. Thus the get(K key) method will normally
return a Collection.

In case no mapping for the key is stored in the map, it may either
return null (like a normal map), or an empty collection.

I would be in favor to define that get() always returns a collection and
never returns null. The advantage being that the result of get() can
safely be used for further operations, e.g. size(), iterator(), ...
keeping the interface of MultiValuedMap smaller and simple (i.e. no need
to add additional methods there like size(K key) or iterator(K key)).

The containsKey method would have to check if there is either no mapping
at all for the key or the stored collection is empty:

public boolean containsKey(K key) {
  Collection coll = decoratedMap().get(key);
  return coll != null && coll.size > 0;
}

The downside would be that read operations may also alter the map thus
leading to unexpected ConcurrentModificationExceptions when iterating on
e.g. value().

So, I would be interested on opinions about this.

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to