package closestpair.version2; import java.util.Comparator; public class Point { public final double x; public final double y; public Point(double x, double y) { this.x = x; this.y = y; } public static final Comparator xComparator = new Comparator() { @Override public int compare(Point p1, Point p2) { if(p1.x > p2.x) return 1; if(p1.x < p2.x) return -1; return 0; } }; public static final Comparator yComparator = new Comparator() { @Override public int compare(Point p1, Point p2) { if(p1.y > p2.y) return 1; if(p1.y < p2.y) return -1; return 0; } }; public static Comparator xComparator(){ return xComparator; } public static Comparator yComparator(){ return yComparator; } @Override public String toString() { return "["+x+" ,"+y+"]"; } public double distanceTo(Point point2) { double dx = x - point2.x; double dy = y - point2.y; return Math.sqrt(dx*dx+dy*dy); } }