-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnumMaps.java
More file actions
40 lines (31 loc) · 869 Bytes
/
Copy pathEnumMaps.java
File metadata and controls
40 lines (31 loc) · 869 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 chapter19.nine;
import java.util.EnumMap;
import java.util.Map;
import chapter19.eight.AlarmPints;
public class EnumMaps {
public static void main(String[] args) {
EnumMap<AlarmPints, Command> em=new EnumMap<AlarmPints, Command>(AlarmPints.class);
em.put(AlarmPints.KITCHEN, new Command() {
public void action() {
// TODO Auto-generated method stub
System.out.println("Kitchen fire!");
}
});
em.put(AlarmPints.BATHROOM, new Command() {
public void action() {
// TODO Auto-generated method stub
System.out.println("Bathroom alert");
}
});
for(Map.Entry<AlarmPints, Command> e:em.entrySet()){
System.out.println(e.getKey()+" ");
e.getValue().action();
}
try {
em.get(AlarmPints.UNILITY).action();
} catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
}
}