BaseMSeqIterator extends BaseSeqIterator<T, BaseMSeq<T>> { @Override public void set(final T value) { if (lastElement < 0) { throw new IllegalStateException(); } array.set(lastElement, value); } BaseMSeqIterator(final BaseMSeq<T> seq); @Override void set(final T value);  }
@Test public void set() { long seed = Randoms.seed(); final Random random = new Random(seed); final Array<Integer> impl = Array.of(ObjectStore.ofLength(1000)); for (int i = 0; i < impl.length(); ++i) { impl.set(i, random.nextInt()); } seed = Randoms.seed(); random.setSeed(seed); final ListIterator<Integer> it = new BaseMSeqIterator<>(impl); while (it.hasNext()) { it.next(); it.set(random.nextInt()); } random.setSeed(seed); for (int i = 0; i < impl.length(); ++i) { Assert.assertEquals(impl.get(i).intValue(), random.nextInt()); } }
@Test public void setValueForward() { final Array<Integer> proxy = Array.of(ObjectStore.ofLength(1000)); for (int i = 0; i < proxy.length(); ++i) { proxy.set(i, 111); } for (int i = 0; i < proxy.length(); ++i) { final Integer value = proxy.get(i); Assert.assertEquals(value, Integer.valueOf(111)); } int count = 0; final ListIterator<Integer> it = new BaseMSeqIterator<>(proxy); while (it.hasNext()) { it.next(); it.set(222); ++count; } Assert.assertEquals(count, proxy.length()); for (int i = 0; i < proxy.length(); ++i) { final Integer value = proxy.get(i); Assert.assertEquals(value, Integer.valueOf(222)); } }
@Test public void setValueBackward() { final Array<Integer> proxy = Array.of(ObjectStore.ofLength(1000)); for (int i = 0; i < proxy.length(); ++i) { proxy.set(i, 111); } for (int i = 0; i < proxy.length(); ++i) { final Integer value = proxy.get(i); Assert.assertEquals(value, Integer.valueOf(111)); } final ListIterator<Integer> it = new BaseMSeqIterator<>(proxy); while (it.hasNext()) { it.next(); } int count = 0; while (it.hasPrevious()) { it.previous(); it.set(222); ++count; } Assert.assertEquals(count, proxy.length()); for (int i = 0; i < proxy.length(); ++i) { final Integer value = proxy.get(i); Assert.assertEquals(value, Integer.valueOf(222)); } }