-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumMaps.java
More file actions
60 lines (46 loc) · 1.12 KB
/
EnumMaps.java
File metadata and controls
60 lines (46 loc) · 1.12 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
58
59
60
package btp.oneP;
import java.util.EnumMap;
import java.util.Map;
public class EnumMaps {
public static void main(String[] args) {
EnumMap<AlarmPoints,CommandI> em =
new EnumMap<AlarmPoints,CommandI>(AlarmPoints.class);
em.put(AlarmPoints.KITCHEN, new CommandI(){
@Override
public void action() {
System.out.print("Kitchen fire!");
}
});
em.put(AlarmPoints.BATHROOM, new CommandI(){
@Override
public void action() {
System.out.print("Bathroom alert!");
}
});
em.put(AlarmPoints.LOBBY, new CommandI(){
@Override
public void action() {
System.out.print("LOBBY fire!");
}
});
em.put(AlarmPoints.OFFICE1, new CommandI(){
@Override
public void action() {
System.out.print("office1 fire!");
}
});
for(Map.Entry<AlarmPoints, CommandI> e : em.entrySet()){
System.out.print(e.getKey() + ": ");
e.getValue().action();
System.out.println();
}
try{
em.get(AlarmPoints.UTILITY).action();
}catch(Exception e){
e.printStackTrace();
}
}
}
interface CommandI{
void action();
}