title: Collections.sort comparison method violates its general contract
body: <p>First of all, sorry for asking a question to this topic again. I'm well aware that there are plenty of questions and answers here. I've read some of them but my problem is that I still cannot figure out what I'm doing wrong. Here is my code:</p>
  
  <pre><code>Collections.sort(hLines, new Comparator&lt;Line&gt;() {
  
          @Override
          public int compare(Line lhs, Line rhs) {
              if ( lhs.p1.y &lt; rhs.p1.y){
                  if (lhs.p2.y &lt; rhs.p2.y)
                      return 1;
                  else
                      return -1;
              }
              if (lhs.p1.y &gt; rhs.p1.y){
                  if (lhs.p2.y &gt; rhs.p2.y)
                      return -1;
                  else
                      return 1;
              }
              else
                  return 0;
          }
  
      });
      Collections.sort(vLines, new Comparator&lt;Line&gt;() {
  
          @Override
          public int compare(Line lhs, Line rhs) {
              if ( lhs.p1.x &lt; rhs.p1.x){
                  if (lhs.p2.x &lt; rhs.p2.x)
                      return 1;
                  else
                      return -1;
              }
              if (lhs.p1.x &gt; rhs.p1.x){
                  if (lhs.p2.x &gt; rhs.p2.x)
                      return -1;
                  else
                      return 1;
              }
              else
              return 0;
          }
  
      });
  </code></pre>
  
  <p>It seems that I'm just to blind to see my error, so if someone of you could help me out with this, I would be very thankful.</p>
  
  <p>EDIT:
  What I want to do is to determine if a line is the upper, lower, most left or moste right line in a Coordinate System which has its 0/0 coordinate in the upper left corner. The points are of type double. And here is the Error-Message:</p>
  
  <pre><code>06-03 10:42:22.576: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=0 ext2=0
  06-03 10:42:22.815: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=1 ext2=0
  06-03 10:42:22.848: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=1 ext2=0
  06-03 10:42:26.408: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=0 ext2=0
  06-03 10:42:26.747: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=1 ext2=0
  06-03 10:42:26.781: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=1 ext2=0
  06-03 10:42:29.474: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=0 ext2=0
  06-03 10:42:30.613: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=0 ext2=0
  06-03 10:42:30.646: E/OpenCV_NativeCamera(15810): CameraHandler::Notify: msgType=4 ext1=0 ext2=0
  06-03 10:42:30.874: E/AndroidRuntime(15810): FATAL EXCEPTION: Thread-2592
  06-03 10:42:30.874: E/AndroidRuntime(15810): java.lang.IllegalArgumentException: Comparison method violates its general contract!
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.util.TimSort.mergeHi(TimSort.java:864)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.util.TimSort.mergeAt(TimSort.java:481)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.util.TimSort.mergeForceCollapse(TimSort.java:422)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.util.TimSort.sort(TimSort.java:219)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.util.TimSort.sort(TimSort.java:169)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.util.Arrays.sort(Arrays.java:2038)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.util.Collections.sort(Collections.java:1891)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at com.example.camera.RectangleDetector.drawLines(RectangleDetector.java:108)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at com.example.camera.RectangleDetector.findRectangle(RectangleDetector.java:94)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at com.example.camera.MainActivity.onCameraFrame(MainActivity.java:114)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at org.opencv.android.NativeCameraView$CameraWorker.run(NativeCameraView.java:177)
  06-03 10:42:30.874: E/AndroidRuntime(15810):    at java.lang.Thread.run(Thread.java:838)
  </code></pre>