Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Last active February 9, 2018 21:25
Show Gist options
  • Save bandrzejczak/cc5eb6125b9235f4e4e820f46b19e67d to your computer and use it in GitHub Desktop.
Save bandrzejczak/cc5eb6125b9235f4e4e820f46b19e67d to your computer and use it in GitHub Desktop.
class Point {
private int x;
private int y;
public Point(int x, int y) {
setX(x);
setY(y);
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public boolean equals(Object other) {
if (other instanceof Point) {
Point otherPoint = (Point) other;
return otherPoint.getX() == getX() &&
otherPoint.getY() == getY();
} else {
return false;
}
}
@Override
public int hashCode() {
return (new Integer[] {getX(), getY()}).hashCode();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment