Re: How can i implements a class like an HashMap but with 2 keys ?
- From: Hendrik Maryns <hendrik_maryns@xxxxxxxxxxxxx>
- Date: Tue, 28 Aug 2007 16:53:43 +0200
Jan Thomä schreef:
Rob wrote:
i want to create a class that works like an HashMap but
with 2 keys, get(key1,key2) -> value
I was thinking to create a class "Pair" that override equals and hashcode
and then store here the two keys and then a class that holds an HashMap
with Pair as key and the value class, can be this a solution?
Sounds good to me, actually you could just use a plain hashmap with that
pair class as key, no need to wrap it inside another class. What you could
also do is generating a string from the two keys which is then used as
combined key, but the pair thing looks cleaner to me...
Have a look at Jakarta Commons Collections, it has MultiKey and
MultiKeyMap, which works exactly as you describe.
If you want a generic version, let me know.
H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Attachment:
signature.asc
Description: OpenPGP digital signature
- Follow-Ups:
- References:
- Prev by Date: Re: How can i implements a class like an HashMap but with 2 keys ?
- Next by Date: Re: How can i implements a class like an HashMap but with 2 keys ?
- Previous by thread: Re: How can i implements a class like an HashMap but with 2 keys ?
- Next by thread: Re: How can i implements a class like an HashMap but with 2 keys ?
- Index(es):
Relevant Pages
|