@Test public void compareToTest() { Point point1 = new Point(1, 2); Point point2 = new Point(1, 2); Point point3 = new Point(1, 1); Point point4 = new Point(2, 2); Assert.assertEquals(0, point1.compareTo(point2)); TestUtils.notCompareToTest(point1, point3); TestUtils.notCompareToTest(point1, point4); }
@Override public int compareTo(Point point) { if (this.x > point.x) { return 1; } else if (this.x < point.x) { return -1; } else if (this.y > point.y) { return 1; } else if (this.y < point.y) { return -1; } return 0; }
Point implements Comparable<Point>, Serializable { @Override public int compareTo(Point point) { if (this.x > point.x) { return 1; } else if (this.x < point.x) { return -1; } else if (this.y > point.y) { return 1; } else if (this.y < point.y) { return -1; } return 0; } }
Point implements Comparable<Point>, Serializable { @Override public int compareTo(Point point) { if (this.x > point.x) { return 1; } else if (this.x < point.x) { return -1; } else if (this.y > point.y) { return 1; } else if (this.y < point.y) { return -1; } return 0; } Point(double x, double y); }
Point implements Comparable<Point>, Serializable { @Override public int compareTo(Point point) { if (this.x > point.x) { return 1; } else if (this.x < point.x) { return -1; } else if (this.y > point.y) { return 1; } else if (this.y < point.y) { return -1; } return 0; } Point(double x, double y); @Override int compareTo(Point point); double distance(Point point); @Override boolean equals(Object obj); @Override int hashCode(); Point offset(double dx, double dy); @Override String toString(); }
Point implements Comparable<Point>, Serializable { @Override public int compareTo(Point point) { if (this.x > point.x) { return 1; } else if (this.x < point.x) { return -1; } else if (this.y > point.y) { return 1; } else if (this.y < point.y) { return -1; } return 0; } Point(double x, double y); @Override int compareTo(Point point); double distance(Point point); @Override boolean equals(Object obj); @Override int hashCode(); Point offset(double dx, double dy); @Override String toString(); final double x; final double y; }