-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathPosition.java
More file actions
51 lines (40 loc) · 1.12 KB
/
Position.java
File metadata and controls
51 lines (40 loc) · 1.12 KB
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
package janggi.domain;
import java.util.Objects;
public class Position {
private static final int MIN_X = 1;
private static final int MAX_X = 9;
private static final int MIN_Y = 1;
private static final int MAX_Y = 10;
private final int x;
private final int y;
public Position(int x, int y) {
validateBoundary(x, y);
this.x = x;
this.y = y;
}
public static boolean isInsideBoundary(int x, int y) {
return x >= MIN_X && x <= MAX_X && y >= MIN_Y && y <= MAX_Y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Position position)) {
return false;
}
return x == position.x && y == position.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
private void validateBoundary(int x, int y) {
if (x < MIN_X || x > MAX_X || y < MIN_Y || y > MAX_Y) {
throw new IllegalArgumentException("[ERROR] 보드 범위를 벗어났습니다.");
}
}
}