Coverage Report - jaggregate.Stream
 
Classes in this File Line Coverage Branch Coverage Complexity
Stream
N/A
N/A
0
 
 1  
 /*
 2  
  Copyright 2004-2008 Paul R. Holser, Jr.  All rights reserved.
 3  
  Licensed under the Academic Free License version 3.0
 4  
  */
 5  
 
 6  
 package jaggregate;
 7  
 
 8  
 /**
 9  
  * Provides protocol for a stream consisting of a finite number of <dfn>past</dfn> and
 10  
  * <dfn>future sequence values</dfn>.  It maintains a position on its sequence values
 11  
  * and allows the position to be altered.
 12  
  *
 13  
  * @param <E> the type of elements in the stream
 14  
  * @param <S> the type of the backing store
 15  
  *
 16  
  * @author <a href="mailto:pholser@alumni.rice.edu">Paul Holser</a>
 17  
  * @version $Id: Stream.java,v 1.2 2008/03/26 18:00:34 pholser Exp $
 18  
  */
 19  
 public interface Stream<E, S extends ReadOnlySequence<E>> {
 20  
     /**
 21  
      * Tells whether this stream is at the end of its values.
 22  
      *
 23  
      * @return {@code true} if this stream has no future sequence values available for
 24  
      * reading; {@code false} otherwise.
 25  
      * @throws IllegalStateException if this stream has been previously
 26  
      * {@linkplain #close() closed}
 27  
      */
 28  
     boolean atEnd();
 29  
 
 30  
     /**
 31  
      * Disassociates this stream from its backing store.  Any system resources
 32  
      * associated with the association should be released.
 33  
      * <p/>
 34  
      * This message is <dfn>idempotent</dfn>: sending it multiple times to this stream
 35  
      * has no effect.
 36  
      */
 37  
     void close();
 38  
 
 39  
     /**
 40  
      * Answers a sequence containing the complete contents of this stream.
 41  
      * <p/>
 42  
      * The returned sequence contains this stream's past and future sequence values,
 43  
      * in order.  The {@link Collection#size() size} of the collection is the sum of
 44  
      * the sizes of the past and future sequence values.
 45  
      *
 46  
      * @return the contents of the receiving stream
 47  
      * @throws IllegalStateException if this stream has been previously
 48  
      * {@linkplain #close() closed}
 49  
      */
 50  
     S contents();
 51  
 
 52  
     /**
 53  
      * Tells whether there are any sequence values in this stream.
 54  
      *
 55  
      * @return {@code true} if there are any sequence values in this stream
 56  
      * @throws IllegalStateException if this stream has been previously
 57  
      * {@linkplain #close() closed}
 58  
      */
 59  
     boolean isEmpty();
 60  
 
 61  
     /**
 62  
      * Answers the current position of this stream.
 63  
      *
 64  
      * @return current position
 65  
      * @throws IllegalStateException if this stream has been previously
 66  
      * {@linkplain #close() closed}
 67  
      */
 68  
     int position();
 69  
 
 70  
     /**
 71  
      * Sets the current position in this stream.
 72  
      * <p/>
 73  
      * If the number of past sequence values is smaller than {@code amount},
 74  
      * move objects in sequence from the front of the future sequence values to the back
 75  
      * of the past sequence values until the number of past sequence values is equal to
 76  
      * {@code amount}.
 77  
      * <p/>
 78  
      * If the number of past sequence values is greater than {@code amount},
 79  
      * move objects in sequence from the back of the past sequence values to the front
 80  
      * of the future sequence values until the number past sequence values is equal to
 81  
      * {@code amount}.
 82  
      * <p/>
 83  
      * If the number of past sequence values is equal to {@code amount}, no action is
 84  
      * taken.
 85  
      *
 86  
      * @param amount the new position
 87  
      * @throws IndexOutOfBoundsException if {@code amount} is negative, or if this
 88  
      * stream is not {@link #isEmpty() empty} and {@code amount >=} the total number of
 89  
      * sequence values in this stream
 90  
      * @throws IllegalStateException if this stream has been previously
 91  
      * {@linkplain #close() closed}
 92  
      */
 93  
     void position( int amount );
 94  
 
 95  
     /**
 96  
      * Sets the position of this stream to be at the beginning of the stream of values.
 97  
      * <p/>
 98  
      * Sets the future sequence values to be the current past sequence values appended
 99  
      * with the current future sequence values--that is, makes this stream's past
 100  
      * sequence values empty.
 101  
      *
 102  
      * @throws IllegalStateException if this stream has been previously
 103  
      * {@linkplain #close() closed}
 104  
      */
 105  
     void reset();
 106  
 
 107  
     /**
 108  
      * Sets the position of this stream to be at the end of the stream of values.
 109  
      * <p/>
 110  
      * Adds all of the future sequence values are appended, in sequence, to the past
 111  
      * sequence values--that is, makes the future sequence values empty.
 112  
      *
 113  
      * @throws IllegalStateException if this stream has been previously
 114  
      * {@linkplain #close() closed}
 115  
      */
 116  
     void setToEnd();
 117  
 }