@Test public void shouldFailIfThereAreNoMoreItems() { expectedException.expect(NoSuchElementException.class); Iterable<Integer> generatorIterable = new GeneratorIterable<>(0, Generators.positiveInts); Iterator<Integer> iterator = generatorIterable.iterator(); iterator.next(); }
@Override public Iterator<T> iterator() { return new Iterator<T>() { private int cursor = 0; @Override public boolean hasNext() { return size == INFINITE_SIZE || cursor < size; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } cursor++; return generator.next(); } @Override public void remove() { throw new UnsupportedOperationException("remove() operation is not supported"); } }; }
GeneratorIterable implements Iterable<T> { @Override public Iterator<T> iterator() { return new Iterator<T>() { private int cursor = 0; @Override public boolean hasNext() { return size == INFINITE_SIZE || cursor < size; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } cursor++; return generator.next(); } @Override public void remove() { throw new UnsupportedOperationException("remove() operation is not supported"); } }; } }
GeneratorIterable implements Iterable<T> { @Override public Iterator<T> iterator() { return new Iterator<T>() { private int cursor = 0; @Override public boolean hasNext() { return size == INFINITE_SIZE || cursor < size; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } cursor++; return generator.next(); } @Override public void remove() { throw new UnsupportedOperationException("remove() operation is not supported"); } }; } GeneratorIterable(int limit, @Nonnull Generator<T> generator);  GeneratorIterable(@Nonnull Generator<T> generator); }
GeneratorIterable implements Iterable<T> { @Override public Iterator<T> iterator() { return new Iterator<T>() { private int cursor = 0; @Override public boolean hasNext() { return size == INFINITE_SIZE || cursor < size; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } cursor++; return generator.next(); } @Override public void remove() { throw new UnsupportedOperationException("remove() operation is not supported"); } }; } GeneratorIterable(int limit, @Nonnull Generator<T> generator);  GeneratorIterable(@Nonnull Generator<T> generator); @Override Iterator<T> iterator(); }
GeneratorIterable implements Iterable<T> { @Override public Iterator<T> iterator() { return new Iterator<T>() { private int cursor = 0; @Override public boolean hasNext() { return size == INFINITE_SIZE || cursor < size; } @Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); } cursor++; return generator.next(); } @Override public void remove() { throw new UnsupportedOperationException("remove() operation is not supported"); } }; } GeneratorIterable(int limit, @Nonnull Generator<T> generator);  GeneratorIterable(@Nonnull Generator<T> generator); @Override Iterator<T> iterator();  }