Maintain a top-k set in Java
<p>Can't think of a neat way of doing this in java:</p>

<p>I'm streaming sets of strings from a file, line by line.</p>

<pre><code>s1 s2 s3
s4 s5
s6 s7 s8 s9 s10
...
</code></pre>

<p>I load each line into a <code>TreeSet</code>, do some analysis and throw it away and move to the next line... I can fit the content of individual lines in memory, but not everything.</p>

<p>Now I want to maintain the top 5 biggest sets of strings I've encountered in the scan so far (storing nothing else). </p>

<p>I'm thinking a <code>PriorityQueue</code> with a <code>SetSizeComparator</code>, with <code>add</code>/<code>poll</code> when the queue reaches a size of 5. Anyone got a neater solution?</p>

<p>(I can't brain today. I have the dumb...)</p>
