-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitress.java
More file actions
29 lines (24 loc) · 726 Bytes
/
Waitress.java
File metadata and controls
29 lines (24 loc) · 726 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
package CompositeIteratorPattern;
import java.util.Iterator;
public class Waitress {
MenuComponent allMenus;
public Waitress(MenuComponent allMenus) {
this.allMenus = allMenus;
}
public void printMenu() {
allMenus.print();
}
public void printVegetarianMenu(){
Iterator<MenuComponent> iterator = allMenus.createIterator();
while (iterator.hasNext()) {
MenuComponent menuComponent = iterator.next();
try {
if (menuComponent.isVegetarian()) {
menuComponent.print();
}
} catch (UnsupportedOperationException e) {
// Handle exception
}
}
}
}