• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MultiKeyMap or Hashmaps...

 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The MultiKeyMap is a Jakarta Commons (3.1?) item.
I'm trying to cache objects in a collection and want to be able to access those objects in more than one way (more than one lookup key).

The MultiKeyMap allows you to associate multiple keys (up to 5) to a particular object, however, I found if you want to retrieve an object that has 2 keys associated with it, you must provide BOTH keys in your get() (kinda obvious I guess )



if I want to retrieve my object, I must retrieve it using this form:


let's say I only have "smith" (key2). As far as I can tell, I can't get to my object if I only have "smith".

It seems this object is very close to what I need, but not quite.

At the time I add my object, I will have all the keys necessary, however, at the time I retrieve my object, I will only have one key.

From there, I would use brute force to iterate the remaining items (all my objects that have "smith" for key2).

I'm thinking I need to maintain a map for my objects and a map for EACH lookup key.

Does this sound correct?
Thanks.

Chris
[ September 26, 2005: Message edited by: Chris Montgomery ]
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From there, I would use brute force to iterate the remaining items (all my objects that have "smith" for key2).


When you are iterating through the items how do you identify which one you want?

That piece of information should be the second key.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic