Elegant and efficient way to put incoming serial data into structures <p>Suppose we have incoming values representing table of known size like this:</p> <pre><code>- a b c x 06 07 08 y 10 11 12 z 14 15 16 </code></pre> <p>but values are arriving from stream/iterator or another serial form, in up-to-down, left-to-right order:</p> <pre><code>- a b c x 06 07 08 y 10 11 12 z 14 15 16 </code></pre> <p>Suppose that data arrives from some provider like <code>newVal = provider.getNext()</code> and we can't go in reverse direction.</p> <p>What is the most elegant and efficient (preffer object oriented) way to put incoming data in three structures:</p> <pre><code>top : 0=&gt;a 1=&gt;b 2=&gt;c left: 0=&gt;x 1=&gt;y 2=&gt;z data: 0,0=&gt;06 1,0=&gt;07 2,0=&gt;08 0,1=&gt;10 1,1=&gt;11 2,1=&gt;12 0,2=&gt;10 1,2=&gt;11 2,2=&gt;12 </code></pre> <p>Would it be better to use some switches/delegates or just buffer all data and extract parts wich we need in loops <strong>(assume that every value has the same type</strong>, let's say integer) ?</p> <p>Assume that we don't need collect data in proper structure in real time (whole data can be buffered, but I look for efficient solution). </p> <p>Real world data in this problem is a triple 'maps', each with size about 500x500 readed from .xls file in java poi extension if it matters.</p>