-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPostOffice.java
More file actions
55 lines (47 loc) · 972 Bytes
/
Copy pathPostOffice.java
File metadata and controls
55 lines (47 loc) · 972 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package chapter19.ten;
public class PostOffice {
enum MailHandler{
GENERAL_DELIVERY{
boolean handler(Mail m){
switch (m.generalDelivery) {
case YES:
System.out.println("Using general deliery for"+m);
return true;
default:
return false;
}
}
},
MACHINE_SCAN{
boolean handler(Mail m){
switch (m.scannability) {
case UNSCANNABLE:
return false;
default:
switch (m.address) {
case INCORRECT:
return false;
default:
System.out.println("Delivering"+ m+"automatically");;
return true;
}
}
}
};
abstract boolean handler(Mail m);
}
static void handler(Mail m){
for(MailHandler handler:MailHandler.values()){
if(handler.handler(m)){
return ;
}
}
System.out.println(m+"is a dead letter");
}
public static void main(String[] args) {
for(Mail mail:Mail.generator(10)){
handler(mail);
System.out.println("**************88888");
}
}
}