Menu

#1 Many-to-Many collection

open
5
2002-10-08
2002-10-02
Kent Vogel
No

I often have a Map of Sets, used to represent a
Many-to-Many relationship from one side, like:

a->1,2
b->2,3
c->5

Often, I need to 'reverse' this, so I can make lookups
the other way, giving me another Map of Sets which
looks like:

1->a
2->a,b
3->b
5->c

A few lines of code could do the transform, but it
would be nice to put both Maps of Sets into 1
'Relationship' collection, with a simple add method like:

void add(Object a, Object b)

and methods for looking up like:

boolean exists(Object a, Object b)
Object getLeft(Object a)
Object getRight(Object b)

[Not sure what good names for 'left' and 'right' or 'a'
and 'b' could be, maybe this could be generalized more]

It could well be represented internally as 2 Maps of
Sets, although there may be more efficient possibilities.

Discussion

  • Kent Vogel

    Kent Vogel - 2002-10-02

    M2M Collection feature request in a pattern language

     
  • Kent Vogel

    Kent Vogel - 2002-10-02

    Logged In: YES
    user_id=609357

    Feature request re-stated in patern-like lingo. (See
    attached file)

     
  • Kent Vogel

    Kent Vogel - 2002-10-08
    • assigned_to: nobody --> kentv
     
  • Joshua Davis

    Joshua Davis - 2002-10-08
    • labels: --> Core Library Features
     
  • Kent Vogel

    Kent Vogel - 2002-10-08

    Logged In: YES
    user_id=609357

    Checked in initial revision of Relationship.java. It implements
    a normal dependency relationship (1 way). Haven't decided
    the best way to implement a 'reflexive' relationship.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.