package javacodebook.collections.iterator;

import java.util.*;

public class ArrayIterator implements Iterator {

    private Object[] array;
    int index;

    public ArrayIterator(Object[] array) {
        this.array = array;
        index = -1;
    }

    public boolean hasNext() {
        return index < array.length - 1 && array.length > 0;
    }

    public Object next() {
        index++;
        if(index >= array.length)
            throw new NoSuchElementException();
        return array[index];
    }

    public void remove() {
        //da das Array ausserhalb des Iterators definiert ist und kein Einfluss
        //auf andere Zugriffe darauf genommen werden kann, ist die Implementierung der
        //Methode hier sinnlos
        throw new UnsupportedOperationException();
    }
}
