Skip to content

Instantly share code, notes, and snippets.

@BobGu
Last active May 5, 2016 16:53
Show Gist options
  • Save BobGu/36cbb3e7d53f6594fe79e12e61da2358 to your computer and use it in GitHub Desktop.
Save BobGu/36cbb3e7d53f6594fe79e12e61da2358 to your computer and use it in GitHub Desktop.
public class KlinesIceCreamMenuIterator implements Iterator {
MenuItem[] items;
int position = 0;
public KlinesIceCreamMenuIterator(MenuItem[] items) {
this.items = items;
}
public MenuItem next() {
MenuItem menuItem = items[position];
position = position + 1;
return menuItem;
}
public boolean hasNext() {
if (position >= items.length || items[position] == null) {
return false;
} else {
return true;
}
}
public void remove() {
if (position <=0) {
throw new IllegalStateException("Can't remove until ")
}
if (list[position - 1] != null) {
for (int i = position - 1; i < (list.length - 1); i++) {
list[i] = list[i+1];
}
list[list.length -1] = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment