001package headfirst.iterator.dinermergercafe; 002 003import java.util.Calendar; 004import java.util.Iterator; 005 006@SuppressWarnings("rawtypes") 007public class AlternatingDinerMenuIterator implements Iterator { 008 MenuItem[] items; 009 int position; 010 011 public AlternatingDinerMenuIterator(MenuItem[] items) { 012 this.items = items; 013 Calendar rightNow = Calendar.getInstance(); 014 position = Calendar.DAY_OF_WEEK % 2; 015 } 016 public Object next() { 017 MenuItem menuItem = items[position]; 018 position = position + 2; 019 return menuItem; 020 } 021 public boolean hasNext() { 022 if (position >= items.length || items[position] == null) { 023 return false; 024 } else { 025 return true; 026 } 027 } 028 public void remove() { 029 throw new UnsupportedOperationException( 030 "Alternating Diner Menu Iterator does not support remove()"); 031 } 032}