BaseSeqIterator implements ListIterator<T> { @Override public int previousIndex() { return cursor - 1; } BaseSeqIterator(final S array); @Override boolean hasNext(); @Override T next(); @Override int nextIndex(); @Override boolean hasPrevious(); @Override T previous(); @Override int previousIndex(); @Override void set(final T value); @Override void add(final T value); @Override void remove(); final S array; }
@Test public void previousIndex() { final long seed = Randoms.seed(); final Random random = new Random(seed); final Array<Integer> proxy = Array.of(ObjectStore.ofLength(1000)); for (int i = 0; i < proxy.length(); ++i) { proxy.set(i, random.nextInt()); } final ListIterator<Integer> it = new BaseSeqIterator<>(proxy); while (it.hasNext()) { it.next(); } int count = proxy.length(); while (it.hasPrevious()) { --count; Assert.assertEquals(it.previousIndex(), count); Assert.assertEquals(proxy.get(it.previousIndex()), it.previous()); } Assert.assertEquals(count, 0); }