-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWall.java
More file actions
37 lines (31 loc) · 1.21 KB
/
Wall.java
File metadata and controls
37 lines (31 loc) · 1.21 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 Wall {
WALL, NO_WALL("no"), DOOR, BREAKABLE, FAKE("hidden");
static final private Map<String, Wall> W_MAP = new HashMap<String, Wall>();
private List<String> aliases;
private Wall(String... aliases) {
this.aliases = Arrays.asList(aliases);
}
static {
for (Wall wall : Wall.values()) {
W_MAP.put(wall.name().toUpperCase(), wall);
for (String alias : wall.aliases)
W_MAP.put(alias.toUpperCase(), wall);
}
}
/* returns enum constant if String value matches */
static public Wall 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 + ")");
Wall wall = W_MAP.get(value);
if (wall == null)
throw new IllegalArgumentException(
"Invalid content option \"" + value + "\". Error detected at line=" + lineNum + "(" + line + ")");
return wall;
}
}