-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathFunction.java
More file actions
40 lines (30 loc) · 934 Bytes
/
Copy pathFunction.java
File metadata and controls
40 lines (30 loc) · 934 Bytes
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 subway.constant;
import subway.exception.InvalidInputException;
import java.util.ArrayList;
import java.util.List;
public enum Function {
ADD("1"),
DELETE("2"),
SHOW("3"),
QUIT("B");
private static List<String> functionCodes = new ArrayList<>();
private String code;
Function(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public static void validate(String input) throws InvalidInputException {
if (!isAvailable(input))
throw new InvalidInputException(InvalidInputException.ExceptionCode.INVALID_FUNCTION_CODE);
}
private static boolean isAvailable(String input) {
initFunctionCodes();
return functionCodes.contains(input);
}
private static void initFunctionCodes() {
for (Function function : Function.values())
functionCodes.add(function.code);
}
}