Name: rm29839 Date: 07/07/98
I would like to move over to the JDK 1.2 collection
classes from JGL, but there doesn't seem to be a way
to easily implement a Map in which there can be
duplicate keys (i.e., more than one value associated
with a key).
In addition to "put(Object key, Object value)"
there needs to be a "add(Object key, Object value)"
which will add a new Key/Value pair without
replacing a previous occurrance of the Key.
"put" would be redefined to replace only the
first instance of the key, if any.
Likewise an "addAll(Map map)" needs to be defined
that is analogous to "putAll(Map map)".
Then you need to add "Collection getAll(Object key)"
that will return all values associated with key. (Or else
have it return an Iterator instance).
Implementation-wise, this is not difficult.
Merely have the duplicate keys be consecutive
in the hash buckets, then it is easy to form
a Collection of values for a single key.
If you choose not to add this functionality, do
you have any ideas on how to efficiently
implement a one-to-many Map with the current
facilities? I've considered defining a HashMap of
Set objects, but this is not very acceptable if
most of the keys have just one value.
(Review ID: 34548)