public int compare(VHalfEdge e1, VHalfEdge e2) { if (e1.getLength() > e2.getLength()) return -1; else if (e1.getLength() < e2.getLength()) return 1; else { // Note: duplicates are removed from the TreeMap that uses // this comparator - so we really don't want to edges to // be considered identical (not specified in java documentation) if (e1.getY() < e2.getY()) return -1; else if (e1.getY() > e2.getY()) return 1; else if (e1.getX() < e2.getX()) return -1; else if (e1.getX() > e2.getX()) return 1; else return 0; } }