MultiResettableIterator extends MultiIteratorBase<T, ResettableIterator<T>> implements ResettableIterator<T> { @Override public void reset() { moveTo(-1); } MultiResettableIterator(ResettableIterator<T>[] iterators); @Override void reset();  }
@Test public void testSingleIterator() { ArrayList<Integer> arrayList = new ArrayList<>(); for (int i = 0; i < 1000; i++) { arrayList.add(i); } MultiResettableIterator<Integer> iterator = new MultiResettableIterator<>(new ResettableIterator[]{ArrayResettableIterator.iterator(arrayList)}); for (int i = 0; i < 1000; i++) { assertTrue(iterator.hasNext()); assertEquals(Integer.valueOf(i), iterator.next()); } assertFalse(iterator.hasNext()); iterator.reset(); for (int i = 0; i < 1000; i++) { assertTrue(iterator.hasNext()); assertEquals(Integer.valueOf(i), iterator.next()); } assertFalse(iterator.hasNext()); }
@Test public void testMutlipleIterators() { ArrayList<Integer> arrayList = new ArrayList<>(); for (int i = 0; i < 1000; i++) { arrayList.add(i); } ArrayList<Integer> arrayList2 = new ArrayList<>(); for (int i = 1000; i < 2000; i++) { arrayList2.add(i); } ArrayList<Integer> arrayList3 = new ArrayList<>(); for (int i = 2000; i < 3000; i++) { arrayList3.add(i); } MultiResettableIterator<Integer> iterator = new MultiResettableIterator<>(new ResettableIterator[]{ArrayResettableIterator.iterator(arrayList), ArrayResettableIterator.iterator(arrayList2), ArrayResettableIterator.iterator(arrayList3)}); for (int i = 0; i < 3000; i++) { assertTrue(iterator.hasNext()); assertEquals(Integer.valueOf(i), iterator.next()); } assertFalse(iterator.hasNext()); iterator.reset(); for (int i = 0; i < 3000; i++) { assertTrue(iterator.hasNext()); assertEquals(Integer.valueOf(i), iterator.next()); } assertFalse(iterator.hasNext()); }
@Test public void testMutlipleIteratorsResetMidIteration() { ArrayList<Integer> arrayList = new ArrayList<>(); for (int i = 0; i < 1000; i++) { arrayList.add(i); } ArrayList<Integer> arrayList2 = new ArrayList<>(); for (int i = 1000; i < 2000; i++) { arrayList2.add(i); } ArrayList<Integer> arrayList3 = new ArrayList<>(); for (int i = 2000; i < 3000; i++) { arrayList3.add(i); } MultiResettableIterator<Integer> iterator = new MultiResettableIterator<>(new ResettableIterator[]{ArrayResettableIterator.iterator(arrayList), ArrayResettableIterator.iterator(arrayList2), ArrayResettableIterator.iterator(arrayList3)}); for (int i = 0; i < 100; i++) { assertTrue(iterator.hasNext()); assertEquals(Integer.valueOf(i), iterator.next()); } iterator.reset(); for (int i = 0; i < 3000; i++) { assertTrue(iterator.hasNext()); assertNotNull(iterator.next()); } assertFalse(iterator.hasNext()); }