-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCoordinate.java
57 lines (50 loc) · 1.26 KB
/
Coordinate.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.io.Serializable;
import java.util.Objects;
public class Coordinate implements Comparable<Coordinate>, Serializable {
public int x;
public int y;
public Coordinate(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(Coordinate coordinate) {
if (x < coordinate.x) {
return -1;
} else if (x > coordinate.x) {
return 1;
} else {
if (y < coordinate.y) {
return -1;
} else if (y > coordinate.y) {
return 1;
} else {
return 0;
}
}
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Coordinate c = (Coordinate) obj;
return x == c.x && y == c.y;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(x);
sb.append(", ");
sb.append(y);
sb.append(")");
return sb.toString();
}
}