package org.xander.behavioral.iterator;

import java.util.Iterator;

public class DinnerMenuIterator implements Iterator {
    MenuItem[] items;
    int position = 0;

    public DinnerMenuIterator(MenuItem[] items) {
        this.items = items;
    }

    @Override
    public boolean hasNext() {
        if (position >= items.length || items[position] == null) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public Object next() {
        MenuItem menuItem = items[position];
        position = position + 1;
        return menuItem;
    }

    @Override
    public void remove() {
        if (position <= 0) {
            throw new IllegalStateException(
                    "You can't remove an item until you've done at least one next()");
        }
        if (items[position - 1] != null) {
            for (int i = position - 1; i < (items.length - 1); i++) {
                items[i] = items[i + 1];
            }
            items[items.length - 1] = null;
        }
    }
}

@@ -291,36 +291,39 @@
 ext() %7B%0A        
-if (
+return 
 position %3E= item
@@ -319,10 +319,9 @@
 ion 
-%3E=
+%3C
  ite
@@ -334,10 +334,10 @@
 gth 
-%7C%7C
+&&
  ite
@@ -353,96 +353,16 @@
 on%5D 
-=
+!
 = null
-) %7B%0A            return false;%0A        %7D else %7B%0A            return true;%0A        %7D
+;
 %0A   

Update DinnerMenuIterator.java