001package headfirst.iterator.dinermerger;
002
003import java.util.Calendar;
004
005public class AlternatingDinerMenuIterator implements Iterator {
006        MenuItem[] list;
007        int position;
008
009        public AlternatingDinerMenuIterator(MenuItem[] list) {
010                this.list = list;
011                Calendar rightNow = Calendar.getInstance();
012                position = Calendar.DAY_OF_WEEK % 2;
013        }
014        public Object next() {
015                MenuItem menuItem = list[position];
016                position = position + 2;
017                return menuItem;
018        }
019        public boolean hasNext() {
020                if (position >= list.length || list[position] == null) {
021                        return false;
022                } else {
023                        return true;
024                }
025        }
026        public String toString() {
027                return "Alternating Diner Menu Iterator";
028        }
029}