title: Data transformation
body: <p>I have data composed of a list of <code>employers</code> and a list of <code>workers</code>.  Each has a many-to-many relationship with the other (so an employer can have many workers, and a worker can have many employers).</p>
  
  <p>The way the data is retrieved (and given to me) is as follows: each <code>employer</code> has an array of <code>workers</code>.  In other words:</p>
  
  <pre><code>employer n has:
    worker x, worker y etc.
  </code></pre>
  
  <p>So I have a bunch of employer objects each containing an array of workers.</p>
  
  <p>I need to transform this data (and basically invert the relationship).  I need to have a bunch of <code>worker</code> objects, each containing an array of <code>employers</code>.  In other words:</p>
  
  <pre><code>worker x has:
    employer n1, employer n2 etc.
  </code></pre>
  
  <p>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 <em>that</em> much data so I would prefer readability over complex optimizations which reduce complexity).  (Oh and I am using Java, but pseudocode would be fine).  </p>