You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ryan Schutt <ry...@yahoo.com> on 2003/11/27 01:26:21 UTC

[Collections] map for 1-to-N relationships both ways

I have an idea for a Map that I think would fit nicely in the commons
collections library.  The idea is to add a method

Set keySetForValue(Object value)

that would return the set of key's that are mapped to the given value.  For
example:

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

map.keySetForValue("1") returns a set containing {"2", "4"}.  

I've often found the need for doing this kind of reverse lookup when using maps
for 1-to-N relationships.  If this sounds like something that fits within the
scope of the commons collections project, let me know and I'll commit an
initial implementation.

-Ryan

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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


Re: [Collections] map for 1-to-N relationships both ways

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Perhaps you could take a look at the new BidiMap interface and
implementations in the current CVS. These provide a full bidirectional
implementation. Your proposal isn't covered by BidiMap fully though, as that
interface currently restricts to one key for each value.

If having looked at that you feel that your 'need' is not met, then I think
that an addition to MapUtils could be possible.

Stephen

----- Original Message -----
From: "Ryan Schutt" <ry...@yahoo.com>
> I have an idea for a Map that I think would fit nicely in the commons
> collections library.  The idea is to add a method
>
> Set keySetForValue(Object value)
>
> that would return the set of key's that are mapped to the given value.
For
> example:
>
> map.put("1", "2");
> map.put("2", "1");
> map.put("3", "3");
> map.put("4", "1");
>
> map.keySetForValue("1") returns a set containing {"2", "4"}.
>
> I've often found the need for doing this kind of reverse lookup when using
maps
> for 1-to-N relationships.  If this sounds like something that fits within
the
> scope of the commons collections project, let me know and I'll commit an
> initial implementation.
>
> -Ryan
>
> __________________________________
> Do you Yahoo!?
> Free Pop-Up Blocker - Get it now
> http://companion.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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