-
Notifications
You must be signed in to change notification settings - Fork 742
/
Copy pathPoint.java
40 lines (33 loc) · 902 Bytes
/
Point.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
package nextstep.ladder;
public class Point {
private boolean current;
private boolean right;
public Point(boolean current, boolean right) {
if (current && right) {
throw new IllegalArgumentException("유효하지 않은 값입니다.");
}
this.current = current;
this.right = right;
}
public static Point first(boolean right) {
return new Point(false, right);
}
public Point next(boolean right) {
if (this.right) {
return new Point(this.right, false);
}
return new Point(this.right, right);
}
public Point last() {
return new Point(this.right, false);
}
public Direction move() {
if (current) {
return Direction.LEFT;
}
if (right) {
return Direction.RIGHT;
}
return Direction.DOWN;
}
}