de.matthiasmann.continuations
Class CoIterator<E>

java.lang.Object
  extended by de.matthiasmann.continuations.CoIterator<E>
All Implemented Interfaces:
java.io.Serializable, java.util.Iterator<E>

public abstract class CoIterator<E>
extends java.lang.Object
implements java.util.Iterator<E>, java.io.Serializable

A Coroutine based iterator

See Also:
Serialized Form

Constructor Summary
protected CoIterator()
           
 
Method Summary
 boolean hasNext()
           
 E next()
           
protected  void produce(E element)
          Produces the next value to be returned by the next() method.
 void remove()
          Always throws UnsupportedOperationException.
protected abstract  void run()
          This is the body of the Iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoIterator

protected CoIterator()
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<E>

next

public E next()
Specified by:
next in interface java.util.Iterator<E>

remove

public void remove()
            throws java.lang.UnsupportedOperationException
Always throws UnsupportedOperationException.

Specified by:
remove in interface java.util.Iterator<E>
Throws:
java.lang.UnsupportedOperationException - always

produce

protected void produce(E element)
                throws SuspendExecution
Produces the next value to be returned by the next() method.

Parameters:
element - The value that should be returned by next()
Throws:
SuspendExecution - This method will suspend the execution

run

protected abstract void run()
                     throws SuspendExecution

This is the body of the Iterator. This method is executed as a Coroutine to produce(E) the values of the Iterator.

Note that this method is suspended each time it calls produce. And if the consumer does not consume all values of the Iterator then this method does not get the change to finish it's execution. This also includes the finally blocks.

This method must only suspend by calling produce. Any other reason for suspension will cause a busy loop in the Iterator.

Throws:
SuspendExecution