public class Coord2 implements Comparable { final int x, y; public Coord2(int x, int y) { this.x = x; this.y = y; } /** * Compares by the x-coordinate first. If that * is equal, it compares the y-coordinate. */ @Override public int compareTo(Object obj) { Coord2 that = (Coord2)obj; int diff = 0; if(diff == 0) diff = this.x - that.x; if(diff == 0) diff = this.y - that.y; return diff; } }