-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.java
More file actions
57 lines (45 loc) · 1.19 KB
/
Ball.java
File metadata and controls
57 lines (45 loc) · 1.19 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Todo:
Change HashMap to EnumMap
*/
import java.util.HashMap;
import java.util.Map;
public class Ball {
private static final Map<String, Color> map = new HashMap<>();
static {
map.put("org", Color.ORG);
map.put("red", Color.RED);
map.put("blu", Color.BLU);
map.put("pnk", Color.PNK);
map.put("grn", Color.GRN);
map.put("gry", Color.GRY);
map.put("sky", Color.SKY);
map.put("olv", Color.OLV);
map.put("prp", Color.PRP);
map.put("ylw", Color.YLW);
map.put("nvy", Color.NVY);
map.put("brn", Color.BRN);
map.put("lim", Color.LIM);
map.put("wht", Color.WHT);
}
private final Color color;
public Ball(Color color) {
this.color = color;
}
public boolean equals(Ball ball) {
return this.color == ball.color;
}
public Ball clone() {
return new Ball(this.color);
}
public static Ball parse(String str) {
return new Ball(map.getOrDefault(str, Color.NIL));
}
public boolean validate() {
return this.color != Color.NIL;
}
@Override
public String toString() {
return this.color.toString();
}
}