Closed GoogleCodeExporter closed 9 years ago
Your Generator class is similar to the Collection Library class
AbstractIterator.
Both simplify the task of building an iterator.
We've discussed the rejected the idea of having a method that converts an
Iterator
into a Iterable, for the following reason. If you call iterable.iterator()
twice on
the same iterable, distinct iterators should be returned. Returning the same
iterator
or having the second iterator() call fail violates the Iterable contract.
Original comment by jared.l....@gmail.com
on 2 Nov 2009 at 12:05
Oh wow, guess I should have read the javadocs more thoroughly.
I see the point on the Iterator->Iterable conversion; slurping an entire
iterator
into some backing list isn't a desirable option either, I suppose.
Original comment by blank...@gmail.com
on 2 Nov 2009 at 12:55
Copying an iterator into a list is totally reasonable. Google Collection Library
includes Lists.newArrayList(Iterator) and ImmutableList.copyOf(Iterator)
methods for
that purpose.
Original comment by jared.l....@gmail.com
on 2 Nov 2009 at 1:18
Ah, I was offering that as the library solution for converting an iterator to
iterable. Once slurped into the backing list, independent and non-failing
iterators
could be returned from it.
Original comment by blank...@gmail.com
on 2 Nov 2009 at 1:48
Right, this is what we recommend Lists.newArrayList() for.
Original comment by kevin...@gmail.com
on 2 Nov 2009 at 4:22
Original issue reported on code.google.com by
blank...@gmail.com
on 31 Oct 2009 at 11:26Attachments: