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.
M2M Collection feature request in a pattern language
Logged In: YES
user_id=609357
Feature request re-stated in patern-like lingo. (See
attached file)
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.