1package org.hamcrest.internal; 2 3import java.lang.reflect.Array; 4import java.util.Iterator; 5 6public class ArrayIterator implements Iterator<Object> { 7 private final Object array; 8 private int currentIndex = 0; 9 10 public ArrayIterator(Object array) { 11 if (!array.getClass().isArray()) { 12 throw new IllegalArgumentException("not an array"); 13 } 14 this.array = array; 15 } 16 17 public boolean hasNext() { 18 return currentIndex < Array.getLength(array); 19 } 20 21 public Object next() { 22 return Array.get(array, currentIndex++); 23 } 24 25 public void remove() { 26 throw new UnsupportedOperationException("cannot remove items from an array"); 27 } 28} 29