Re: How can i implements a class like an HashMap but with 2 keys ?



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



Relevant Pages

  • Re: How can i implements a class like an HashMap but with 2 keys ?
    ... 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 ... actually you could just use a plain hashmap with that ...
    (comp.lang.java.help)
  • Re: Buying Keys from Blizzard?
    ... Battlechest which has up to BC and another $40 for WotLK. ... point I can justify passing the store for the deal but if Blizz is ... DVD keys or buy the DVD keys from Blizzard. ...
    (alt.games.warcraft)
  • Re: EF Designer ignores my foreign key
    ... ItemGroupId}' that are partially contained in the set of primary keys ... I don't know why the EF team didn't fix this, and I can only describe from my own experience with reverse engineering an entity model from a relational schema, but as I do recall we had a similar bug very early on in LLBLGen Pro as well and I think it was even in the first beta cycle of v1. ... Well, unless they store that information, you can't: someone could have written the store XML meta data by hand and could have made an error. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Buying Keys from Blizzard?
    ... Battlechest which has up to BC and another $40 for WotLK. ... point I can justify passing the store for the deal but if Blizz is ... IIRC Blizzard charges the same as Gamestop, ... DVD keys or buy the DVD keys from Blizzard. ...
    (alt.games.warcraft)
  • Re: Where does your APL application hold its settings?
    ... the accepted practices call for on other Unix variants. ... If you are going to "avoid platform specific facilities" then you're going ... The keys are easy to find and to ... store a file name than to store a copy of a file. ...
    (comp.lang.apl)