title: java.lang.IllegalArgumentException: Comparison method violates its general contract
body: <p>Hi below is my compare method of my comparator. I am not sure what is wrong. I looked up other similar titled questions and answers on stack overflow but not sure what is wrong with my method but I keep getting java.lang.IllegalArgumentException: Comparison method violates its general contract!</p>
  
  <p>Any help will be greatly appreciated</p>
  
  <pre><code>public int compare(Node o1, Node o2)
  {
      HashMap&lt;Integer,Integer&gt; childMap = orderMap.get(parentID);
      if(childMap != null &amp;&amp; childMap.containsKey(o1.getID()) &amp;&amp; 
                             childMap.containsKey(o2.getID()))
      {
          int order1 = childMap.get(o1.getID());
          int order2 = childMap.get(o2.getID());
  
          if(order1&lt;order2) 
              return -1;
          else if(order1&gt;order2) 
              return 1;
          else 
              return 0;
      }
      else
          return 0;
  }
  </code></pre>
  
  <p>Adding the exception I am getting</p>
  
  <pre><code>java.lang.IllegalArgumentException: Comparison method violates its general contract!
  at java.util.TimSort.mergeLo(TimSort.java:747)
  at java.util.TimSort.mergeAt(TimSort.java:483)
  at java.util.TimSort.mergeCollapse(TimSort.java:410)
  at java.util.TimSort.sort(TimSort.java:214)
  at java.util.TimSort.sort(TimSort.java:173)
  at java.util.Arrays.sort(Arrays.java:659)
  at java.util.Collections.sort(Collections.java:217)
  </code></pre>