commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phillip Rhodes <spamsu...@rhoderunner.com>
Subject [collections] dup-key map and map intersections?
Date Mon, 19 Jan 2004 05:12:02 GMT
I am working on a security model that I hope to release via LGPL.  I am 
trying to work with roles, groups, permissions, etc and use the collections 
api to do some magic!

I have a couple of questions.  I appreciate any pointers including 
re-design advice.

1)  Is there any Map type of Container that allows me to have duplicate 
keys that have different payloads (different values in the value portion?

For example,
map.put("1","1");
map.put("1", "2");
map.put("1","3");

I know this may not make sense, and that leads to the next question. I want 
to preserve the values in the value portion of the map as distinct values. 
That is, if I grabbed a collection of the value elements in the map, the 
collection would have 3 elements.

2)  Is there a way that I can do an Intersection between two of these maps 
and get the value portion of the map into an Collection type of container?

For example:
map1.put("1","1");
map1.put("1","2");
map1.put("2","2");

map2.put("1","3");
map2.put("2","1");
map2.put("3","4");

map1.retainAll(map2);

map1 now contains the keys that were in both map1 and map2, and the values 
that were associated to those keys.
//map1 contains (key, value) is now (1,1),(1,2),(1,3),(2,1),(2,2)
//notice that since the key "3" of map2 is only in map2 and not in map1, 
there is not (3,4)

Thanks for reading my post!







---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message