How do I compare objects based on their location on a line
<p>i am trying to write a compare to method that will do this.  </p>

<pre><code>// If a and b lie on the same horizontal line, 
//    then a &lt; b when a is to the left of b
// Otherwise, a &lt; b when a is below b   
</code></pre>

<p>i dnt really know how to do this, usually i just compare if a>b return +ve int and -ve int if less than or 0 for equal.</p>

<p>My solution from your suggestions.........</p>

<p>i used ideas form Jim Blackler, Ralph and Peter Lawrey and came up with this. it works sorry i was a little confused and did not think of the  Cartesian cordinates thanks Aasmund Eldhuset, this is my final compare method.. and it works </p>

<p>class Lexicographical implements Comparator{
    //This needs to be rewritten so...<br>
    // If a and b lie on the same horizontal line, 
    //    then a &lt; b when a is to the left of b
    // Otherwise, a &lt; b when a is below b<br>
    public int compare(Point a, Point b)
    {
        if (a.y == b.y) // y axis are the same(same line)
        {
              if(a.x &lt; b.x)// to the left of b(on the x axis)
                  return -1;
              else
                  return 1;// to the right of b
        } 
        else if(a.y &lt; b.y)// y axis are not the same(below not same line)
        {
                return -1;</p>

<pre><code>    }
    else 
        return 0;
}
</code></pre>

<p>}</p>
