-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContent.java
More file actions
37 lines (31 loc) · 1.26 KB
/
Content.java
File metadata and controls
37 lines (31 loc) · 1.26 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
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public enum Content {
START("S"), END("E"), EMPTY("no"), KEY, HAMMER, TROPHY, PLAYER, VISIT;
static final private Map<String, Content> C_MAP = new HashMap<String, Content>();
private List<String> aliases;
private Content(String... aliases) {
this.aliases = Arrays.asList(aliases);
}
static {
for (Content content : Content.values()) {
C_MAP.put(content.name().toUpperCase(), content);
for (String alias : content.aliases)
C_MAP.put(alias.toUpperCase(), content);
}
}
/* returns enum constant if String value matches */
static public Content fromString(String value, int lineNum, String line) {
value = value.toUpperCase();
if (value == null)
throw new NullPointerException(
"Invalid content option \"" + value + "\". Error detected at line=" + lineNum + "(" + line + ")");
Content content = C_MAP.get(value);
if (content == null)
throw new IllegalArgumentException(
"Invalid content option \"" + value + "\". Error detected at line=" + lineNum + "(" + line + ")");
return content;
}
}