How to sort Set by not unique data?
<p>I have the following code:</p>

<pre><code>public class EnglishWord implements Comparable&lt;EnglishWord&gt; {

    private String word;// unique
    private int occurenceNumber; //not unique


    public EnglishWord(String word, int occurenceNumber) {
        this.word = word;
        this.occurenceNumber= occurenceNumber;
    }

    public boolean equals(EnglishWord anotherWord) {
        return word.equals(anotherWord.getWord());
    }

    public int compareTo(EnglishWord anotherWord) {
        return occurenceNumber - anotherWord.getOccurenceNumber;
    }
</code></pre>

<p>I want to add all <code>EnglishWord</code>s in to a <code>Set</code> where there's exactly one <code>EnglishWord</code> object for each unique <code>word</code>. I want the <code>Set</code> to be sorted by <code>occurrenceNumber</code>. The code I have already sorts the words by <code>occurrenceNumber</code>, but doesn't add <code>EnglishWord</code> with unique <code>occurrenceNumber</code> to the <code>Set</code>. As code, here is what I mean:</p>

<pre><code>Set&lt;EnglishWord&gt; mySet= new TreeSet&lt;EnglishWord&gt;();
mySet.add(new EnglishWord("hello",8));
mySet.add(new EnglishWord("hi",8));
</code></pre>

<p>After this, <code>mySet</code>'s size is 1.</p>
