Package kilim

Class Generator<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Iterator<T>, Fiber.Worker
    Direct Known Subclasses:
    Fib, Post, Pre, Xorshift.X1

    public class Generator<T>
    extends Continuation
    implements java.util.Iterator<T>, java.lang.Iterable<T>
    A Generator, from the caller's perspective, looks like a normal iterator that produces values. Because a standard iterator's next() method must return every time, the programmer is forced to manage the stack explicitly. The Generator class instead allows one to write a task with an automatically managed stack and couple it to an iterator interface. For example:
     class StringGenerator extends Generator{
       public void execute() throws Pausable {
           while (!done) {
               String s = getNextWord(); // this can pause
               yield(s);  
           }
       }
       private String getNextWord() throws Pausable {
       }
     }
     
     
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) boolean done  
      (package private) T nextVal  
    • Constructor Summary

      Constructors 
      Constructor Description
      Generator()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()  
      java.util.Iterator<T> iterator()  
      T next()  
      void remove()  
      void yield​(T val)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • nextVal

        T nextVal
      • done

        boolean done
    • Constructor Detail

      • Generator

        public Generator()
    • Method Detail

      • hasNext

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

        public T next()
        Specified by:
        next in interface java.util.Iterator<T>
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<T>
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>