### Question:
AbstractImmutableArray implements Array<T> { @Override public Iterator<T> iterator() { return new Iterator<T>() { boolean itemsRemaining = true; int[] indices = new int[getNDim()]; @Override public boolean hasNext() { return itemsRemaining; } @Override public T next() { T ret = get(indices); for (int dim = getNDim() - 1; dim >= 0; dim--) { indices[dim]++; if (indices[dim] >= shape[dim]) { indices[dim] = 0; if (dim == 0) { itemsRemaining = false; } } else { break; } } return ret; } @Override public void remove() { throw new UnsupportedOperationException( "Cannot remove values - this Array is immutable"); } }; } AbstractImmutableArray(int... shape); @Override int getNDim(); @Override int[] getShape(); @Override Iterator<T> iterator(); @Override void set(T value, int... coords); @Override long size();  }### Answer:
@Test public void testIterator() { List<Float> expected = new ArrayList<Float>(); for (int j = 0; j < YSIZE; j++) { for (int i = 0; i < XSIZE; i++) { expected.add(j + 0.1f * i); } } Iterator<Float> iterator = array.iterator(); int index = 0; while (iterator.hasNext() && index < 1000) { assertEquals(expected.get(index), iterator.next()); index++; } }