11ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotpackage org.hamcrest.internal;
21ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
31ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotimport java.lang.reflect.Array;
41ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotimport java.util.Iterator;
51ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
61ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabotpublic class ArrayIterator implements Iterator<Object> {
71ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	private final Object array;
81ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	private int currentIndex = 0;
91ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
101ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	public ArrayIterator(Object array) {
111ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot		if (!array.getClass().isArray()) {
121ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot			throw new IllegalArgumentException("not an array");
131ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot		}
141ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot		this.array = array;
151ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	}
161ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
171ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	public boolean hasNext() {
181ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot		return currentIndex < Array.getLength(array);
191ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	}
201ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
211ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	public Object next() {
221ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot		return Array.get(array, currentIndex++);
231ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	}
241ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
251ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	public void remove() {
261ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot		throw new UnsupportedOperationException("cannot remove items from an array");
271ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot	}
281ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot}
29