title: Comparison method violates its general contract, with long comparsion
body: <pre><code>Collections.sort(cells, new Comparator&lt;MyCell&gt;() {
  
          @Override
          public int compare(MyCell o1, MyCell o2) {
              if (o1.getX() &lt;= o2.getX() &amp;&amp; o1.getY() &lt;= o2.getY()) {
                  return -1;
              } else {
                  return 1;
              }
          }
  
      });
  </code></pre>
  
  <p>Here the full stack trace:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
  at java.util.TimSort.mergeHi(Unknown Source)
  at java.util.TimSort.mergeAt(Unknown Source)
  at java.util.TimSort.mergeCollapse(Unknown Source)
  at java.util.TimSort.sort(Unknown Source)
  at java.util.TimSort.sort(Unknown Source)
  at java.util.Arrays.sort(Unknown Source)
  at java.util.Collections.sort(Unknown Source)
  </code></pre>
  
  <p>I know there are many questions like this one but I don't get it why my comparision is wrong. getX() and getY() returns a long. So how can I fix this?</p>
  
  <p>I already search for it, but didn't get an answer.</p>
  
  <p>Thanks in advance.</p>