(Solved) Sorting a hashmap based on 2 values of an object key
<p>Thank you for those who helped me. </p>

<p>For example,</p>

<pre><code>Map&lt;Testing, Integer&gt; xx = new EnumMap&lt;&gt;(Testing.class);

public enum Testing {

    EXAMPLE_1(1, 2);
    EXAMPLE_2(2, 100);
    EXAMPLE_3(2, 20);

    public int position;
    public int value;

    public Testing(final int pos, final int value) {
        this.position = pos;
        this.value = value;
    }
}
</code></pre>

<p>I would want to sort the hashmap based on the Testing itself, we could ignore the value of the hashmap here.</p>

<p>Basically, sort based on position in descending, followed by value in ascending</p>

<pre><code>xx.put(EXAMPLE_1, 1111);
xx.put(EXAMPLE_2, 1111);
xx.put(EXAMPLE_3, 1111);
</code></pre>

<p>I want the result to return as {EXAMPLE_2, EXAMPLE_3, EXAMPLE_1)</p>

<p>I've tried using a Collection to sort twice but it doesn't seem to work as it only takes part in the last sort</p>

<pre><code>Eg: 
    Collections.sort(Map, new DescendingPosition());
    Collections.sort(Map, new AscendingValue()); // only this applies
</code></pre>

<p>Thanks in advance.</p>

<p>EDIT*
Here's what i've tested, and it works, is there any shorter way which can be done?</p>

<pre><code>    Map&lt;Testing, Integer&gt;[] hi2 = new TreeMap&lt;&gt;[3];
    for (Entry&lt;Testing, Integer&gt; hmm : statups.entrySet()) {
        final int pos = (hmm.getKey().position - 1);
        if (hi2[pos] == null) {
            hi2[pos] = new TreeMap&lt;&gt;(new CompareValue());
            hi2[pos].put(hmm.getKey(), hmm.getValue());
        } else {
            hi2[pos].put(hmm.getKey(), hmm.getValue());
        }
    }
    Map&lt;Testing, Integer&gt; finalMap = new LinkedHashMap&lt;&gt;();
    for (int i = (hi2.length - 1); i &gt;= 0; i--) { // to arrange positions in descending
        if (hi2[i] != null) {
            finalMap.putAll(hi2[i]);
        }
    }
    System.out.println(finalMap);

    public static class CompareValue implements Comparator&lt;Testing&gt; {
        @Override
        public int compare(Testing o1, Testing o2) {
            return o1.value - o2.value;// ascending values
        }
    }
</code></pre>
