-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathMoveDirection.java
More file actions
41 lines (34 loc) · 1.08 KB
/
MoveDirection.java
File metadata and controls
41 lines (34 loc) · 1.08 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
package nextstep.ladder.domain.laddergame.position;
import java.util.Arrays;
public enum MoveDirection {
LEFT(-1) {
public boolean canMove(boolean left, boolean right) {
return left && !right;
}
},
RIGHT(1) {
public boolean canMove(boolean left, boolean right) {
return !left && right;
}
},
PASS(0) {
public boolean canMove(boolean left, boolean right) {
return !left && !right;
}
};
private int direction;
MoveDirection(int direction) {
this.direction = direction;
}
public static int move(boolean left, boolean right) {
return Arrays.stream(values())
.filter(direction -> direction.canMove(left, right))
.findFirst()
.map(MoveDirection::getDirection)
.orElseThrow(() -> new IllegalArgumentException("포인트를 확인해주세요."));
}
public int getDirection() {
return direction;
}
public abstract boolean canMove(boolean left, boolean right);
}