@Test public void equalsTest() { Point point1 = new Point(X, Y); Point point2 = new Point(X, Y); Point point3 = new Point(0, 0); TestUtils.equalsTest(point1, point2); Assert.assertNotEquals(point1, point3); Assert.assertNotEquals(point3, point1); Assert.assertNotEquals(point1, new Object()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (!(obj instanceof Point)) { return false; } Point other = (Point) obj; if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) { return false; } else if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) { return false; } return true; }
Point implements Comparable<Point>, Serializable { @Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (!(obj instanceof Point)) { return false; } Point other = (Point) obj; if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) { return false; } else if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) { return false; } return true; } }
Point implements Comparable<Point>, Serializable { @Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (!(obj instanceof Point)) { return false; } Point other = (Point) obj; if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) { return false; } else if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) { return false; } return true; } Point(double x, double y); }
Point implements Comparable<Point>, Serializable { @Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (!(obj instanceof Point)) { return false; } Point other = (Point) obj; if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) { return false; } else if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) { return false; } return true; } Point(double x, double y); @Override int compareTo(Point point); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); }
Point implements Comparable<Point>, Serializable { @Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (!(obj instanceof Point)) { return false; } Point other = (Point) obj; if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) { return false; } else if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) { return false; } return true; } Point(double x, double y); @Override int compareTo(Point point); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); final double x; final double y; }