001package headfirst.composite.menuiterator;
002
003import java.util.Iterator;
004
005@SuppressWarnings("rawtypes")
006public class Waitress {
007        MenuComponent allMenus;
008
009        public Waitress(MenuComponent allMenus) {
010                this.allMenus = allMenus;
011        }
012
013        public void printMenu() {
014                allMenus.print();
015        }
016
017        public void printVegetarianMenu() {
018                Iterator iterator = allMenus.createIterator();
019
020                System.out.println("\nVEGETARIAN MENU\n----");
021                while (iterator.hasNext()) {
022                        MenuComponent menuComponent =
023                                        (MenuComponent)iterator.next();
024                        try {
025                                if (menuComponent.isVegetarian()) {
026                                        menuComponent.print();
027                                }
028                        } catch (UnsupportedOperationException e) {}
029                }
030        }
031}