Hi,
Yes, that is how it works.
The problem is that with filter-based pipes, you never know if the .next() of the previous pipe is going to return something as even if the previous iterator .hasNext(), it might not come through to a future Pipe. What I typically do is NOT use hasNext(). If you look at the methods like iterate(), toList(), fill(), count(), etc., they work like this:
try {
while(true) {
pipe.next()
}
} catch() {}
This way, there is only one try/catch for the entire pipeline sequence.
If you can come up with a better solution, I'm more than happy to incorporate it as I've never liked the fact that hasNext() uses try/catch.
Take care,
Marko.
On Jul 30, 2012, at 5:36 AM, Danny Thomas wrote:
I noticed a large number of NoSuchElementExceptions are thrown by SingleIterator because AbstractPipe determines hasNext() by calling next() optimistically and expects an exception if no element is available. These exceptions are for flow control and are caught and handled in AbstractPipe, so there's no benefit to allocating a new exception or having the stack trace - have fast exceptions been considered?