forked from woowacourse/java-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameCommand.java
More file actions
37 lines (30 loc) · 1.07 KB
/
Copy pathGameCommand.java
File metadata and controls
37 lines (30 loc) · 1.07 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
package chess.controller.game;
import java.util.Arrays;
import java.util.List;
public enum GameCommand {
MOVE(3),
STATUS(1),
END(1),
EMPTY(0),
;
private final int size;
GameCommand(final int size) {
this.size = size;
}
public static final int MOVE_SOURCE_INDEX = 1;
public static final int MOVE_TARGET_INDEX = 2;
private static final int COMMAND_INDEX = 0;
private static final String INVALID_COMMAND_MESSAGE = "올바른 명령어를 입력해주세요.";
public static GameCommand from(final List<String> commands) {
return Arrays.stream(values())
.filter(command -> command != EMPTY)
.filter(command -> command.name().equalsIgnoreCase(commands.get(COMMAND_INDEX)))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(INVALID_COMMAND_MESSAGE));
}
public void validateCommandsSize(final List<String> commands) {
if (size != commands.size()) {
throw new IllegalArgumentException(INVALID_COMMAND_MESSAGE);
}
}
}