org.gcube.data.streams
Class LookAheadStream<E>

java.lang.Object
  extended by org.gcube.data.streams.LookAheadStream<E>
Type Parameters:
E - the type of stream elements
All Implemented Interfaces:
Iterator<E>, Stream<E>
Direct Known Subclasses:
FoldedStream, GuardedStream, MonitoredStream, PipedStream, ResultsetStream, UnfoldedStream

public abstract class LookAheadStream<E>
extends Object
implements Stream<E>

Partial Stream implementation based on look-ahead operations over an underlying stream.

The implementation attempts to prefetch the output of next() in hasNext(). If a failure occurs, hasNext():

  • keeps consuming the underlying stream as long as the failure is a StreamSkipSignal;
  • consults a FaultHandler for all the other failures. If the FaultHandler re-throws the same or a different exception, the implementation throws it at the following next().

    Author:
    Fabio Simeoni

    Field Summary
    protected  E element
               
    protected  Boolean hasNext
               
     
    Constructor Summary
    LookAheadStream()
               
     
    Method Summary
    protected abstract  boolean delegateHasNext()
              Returns true if the underlying stream has more elements.
    protected abstract  E delegateNext()
              Returns an element of the underlying stream
     boolean hasNext()
               
     E next()
               
     void setHandler(FaultHandler handler)
              Sets the FaultHandler for the iteration
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface org.gcube.data.streams.Stream
    close, isClosed, locator
     
    Methods inherited from interface java.util.Iterator
    remove
     

    Field Detail

    hasNext

    protected Boolean hasNext

    element

    protected E element
    Constructor Detail

    LookAheadStream

    public LookAheadStream()
    Method Detail

    setHandler

    public void setHandler(FaultHandler handler)
                    throws IllegalArgumentException
    Sets the FaultHandler for the iteration

    Parameters:
    handler - the handler
    Throws:
    IllegalArgumentException - if the handler is null

    hasNext

    public final boolean hasNext()
    Specified by:
    hasNext in interface Iterator<E>
    Specified by:
    hasNext in interface Stream<E>

    next

    public final E next()
    Specified by:
    next in interface Iterator<E>
    Specified by:
    next in interface Stream<E>

    delegateNext

    protected abstract E delegateNext()
    Returns an element of the underlying stream

    Returns:
    the element

    delegateHasNext

    protected abstract boolean delegateHasNext()
    Returns true if the underlying stream has more elements.

    Returns:
    true if the underlying stream has more elements


    Copyright © 2012. All Rights Reserved.