[collections] MultiMaps...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[collections] MultiMaps...

James Carman
I have a case in my application where I want to map one key to multiple
values.  However, I don't want the values to be stored as a List.  I would
rather have MultiHashMap store the values in a Set of some kind (HashSet
maybe).  It would be nice if I could tell MultiHashMap what kind of
collection to use to store the values.  Maybe we could parameterize the
constructor...

public MultiHashMap( Factory factory )
{
 
}

The factory would be used to create a collection instance each time one is
needed for a new key in the map.  Maybe this is overkill and we could just
give it a Class instance and it can call newInstance() on that.  Anyway,
that would allow MultiHashMap to return any kind of collection, not just
Lists.  Of course, I could just create a new Set using the returned List,
but that's a lot of objects to create.  What do you guys think?



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [collections] MultiMaps...

James Carman
Upon further thought, why do we even have a class like MultiHashMap?
Couldn't we write a generic MultiMap implementation that wraps another map
and provides the "multiple" functionality?

public class MapUtils
{
  ...
  public static MultiMap multiMap( Map implementation );
  public static MultiMap multiMap( Map implementation, Factory
collectionFactory );
  ...
}




-----Original Message-----
From: James Carman [mailto:[hidden email]]
Sent: Friday, May 13, 2005 1:21 PM
To: 'Jakarta Commons Developers List'
Subject: [collections] MultiMaps...


I have a case in my application where I want to map one key to multiple
values.  However, I don't want the values to be stored as a List.  I would
rather have MultiHashMap store the values in a Set of some kind (HashSet
maybe).  It would be nice if I could tell MultiHashMap what kind of
collection to use to store the values.  Maybe we could parameterize the
constructor...

public MultiHashMap( Factory factory )
{
 
}

The factory would be used to create a collection instance each time one is
needed for a new key in the map.  Maybe this is overkill and we could just
give it a Class instance and it can call newInstance() on that.  Anyway,
that would allow MultiHashMap to return any kind of collection, not just
Lists.  Of course, I could just create a new Set using the returned List,
but that's a lot of objects to create.  What do you guys think?



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [collections] MultiMaps...

Stephen Colebourne
A decorator like this is definitely the preferred solution. Its been
suggested before, but no one has yet had the itch to code it ;-)

Stephen


James Carman wrote:

> Upon further thought, why do we even have a class like MultiHashMap?
> Couldn't we write a generic MultiMap implementation that wraps another map
> and provides the "multiple" functionality?
>
> public class MapUtils
> {
>   ...
>   public static MultiMap multiMap( Map implementation );
>   public static MultiMap multiMap( Map implementation, Factory
> collectionFactory );
>   ...
> }
>
>
>
>
> -----Original Message-----
> From: James Carman [mailto:[hidden email]]
> Sent: Friday, May 13, 2005 1:21 PM
> To: 'Jakarta Commons Developers List'
> Subject: [collections] MultiMaps...
>
>
> I have a case in my application where I want to map one key to multiple
> values.  However, I don't want the values to be stored as a List.  I would
> rather have MultiHashMap store the values in a Set of some kind (HashSet
> maybe).  It would be nice if I could tell MultiHashMap what kind of
> collection to use to store the values.  Maybe we could parameterize the
> constructor...
>
> public MultiHashMap( Factory factory )
> {
>  
> }
>
> The factory would be used to create a collection instance each time one is
> needed for a new key in the map.  Maybe this is overkill and we could just
> give it a Class instance and it can call newInstance() on that.  Anyway,
> that would allow MultiHashMap to return any kind of collection, not just
> Lists.  Of course, I could just create a new Set using the returned List,
> but that's a lot of objects to create.  What do you guys think?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]