Data transformation question

Posted by tkm on Stack Overflow See other posts from Stack Overflow or by tkm
Published on 2010-06-10T14:11:45Z Indexed on 2010/06/10 14:23 UTC
Read the original article Hit count: 144

Filed under:
|
|
|

I have data composed of a list of employers and a list of workers. Each has a many-to-many relationship with the other (so an employer can have many workers, and a worker can have many employers).

The way the data is retrieved (and given to me) is as follows: each employer has an array of workers. In other words:

employer n has:
  worker x, worker y etc.

So I have a bunch of employer objects each containing an array of workers.

I need to transform this data (and basically invert the relationship). I need to have a bunch of worker objects, each containing and array of employers. In other words:

worker x has:
  employer n1, employer n2 etc.

The context is hypothetical so please don't comment on why I need this or why I am doing it this way. I would really just like help on the algorithm to perform this transformation (there isn't that much data so I would prefer readability over complex optimizations which reduce complexity). (Oh and I am using Java, but pseudocode would be fine). Thanks!

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays