title: Java error: Comparison method violates its general contract
body: <p>I saw many questions about this, and tried to solve the problem, but after one hour of googling and a lots of trial &amp; error, I still can't fix it. I hope some of you catch the problem.</p>
  
  <p>This is what I get:</p>
  
  <pre class="lang-none prettyprint-override"><code>java.lang.IllegalArgumentException: Comparison method violates its general contract!
      at java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:835)
      at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:453)
      at java.util.ComparableTimSort.mergeForceCollapse(ComparableTimSort.java:392)
      at java.util.ComparableTimSort.sort(ComparableTimSort.java:191)
      at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
      at java.util.Arrays.sort(Arrays.java:472)
      at java.util.Collections.sort(Collections.java:155)
      ...
  </code></pre>
  
  <p>And this is my comparator:</p>
  
  <pre><code>@Override
  public int compareTo(Object o) {
      if(this == o){
          return 0;
      }
  
      CollectionItem item = (CollectionItem) o;
  
      Card card1 = CardCache.getInstance().getCard(cardId);
      Card card2 = CardCache.getInstance().getCard(item.getCardId());
  
      if (card1.getSet() &lt; card2.getSet()) {
          return -1;
      } else {
          if (card1.getSet() == card2.getSet()) {
              if (card1.getRarity() &lt; card2.getRarity()) {
                  return 1;
              } else {
                  if (card1.getId() == card2.getId()) {
                      if (cardType &gt; item.getCardType()) {
                          return 1;
                      } else {
                          if (cardType == item.getCardType()) {
                              return 0;
                          }
                          return -1;
                      }
                  }
                  return -1;
              }
          }
          return 1;
      }
  }
  </code></pre>
  
  <p>Any idea?</p>