@Test public void shouldAllowNullValuesInTheInputIterator() throws Exception { Iterator<String> input = iterableWith("a", "b", null).iterator(); Iterator<String> iterator = new CyclicIterator<String>(input); assertThat(iterator.next(), is("a")); assertThat(iterator.next(), is("b")); assertThat(iterator.next(), is(nullValue())); }
@Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } if (iteratorContainsMoreElements()) { T next = iterator.next(); elements.add(next); return next; } else { T next = elements.get(index); if (index == (elements.size() - 1)) { if (!shouldCycleInfinitely()) { repeats++; } index = 0; } else { index++; } return next; } }
CyclicIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } if (iteratorContainsMoreElements()) { T next = iterator.next(); elements.add(next); return next; } else { T next = elements.get(index); if (index == (elements.size() - 1)) { if (!shouldCycleInfinitely()) { repeats++; } index = 0; } else { index++; } return next; } } }
CyclicIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } if (iteratorContainsMoreElements()) { T next = iterator.next(); elements.add(next); return next; } else { T next = elements.get(index); if (index == (elements.size() - 1)) { if (!shouldCycleInfinitely()) { repeats++; } index = 0; } else { index++; } return next; } } CyclicIterator(Iterator<? extends T> iterator);  CyclicIterator(Iterator<? extends T> iterator, int numberOfTimesToRepeat); }
CyclicIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } if (iteratorContainsMoreElements()) { T next = iterator.next(); elements.add(next); return next; } else { T next = elements.get(index); if (index == (elements.size() - 1)) { if (!shouldCycleInfinitely()) { repeats++; } index = 0; } else { index++; } return next; } } CyclicIterator(Iterator<? extends T> iterator);  CyclicIterator(Iterator<? extends T> iterator, int numberOfTimesToRepeat); @Override boolean hasNext(); @Override T next(); @Override void remove(); @Override String toString(); }
CyclicIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } if (iteratorContainsMoreElements()) { T next = iterator.next(); elements.add(next); return next; } else { T next = elements.get(index); if (index == (elements.size() - 1)) { if (!shouldCycleInfinitely()) { repeats++; } index = 0; } else { index++; } return next; } } CyclicIterator(Iterator<? extends T> iterator);  CyclicIterator(Iterator<? extends T> iterator, int numberOfTimesToRepeat); @Override boolean hasNext(); @Override T next(); @Override void remove(); @Override String toString();  }