jaggregate
Interface Stream<E,S extends ReadOnlySequence<E>>

Type Parameters:
E - the type of elements in the stream
S - the type of the backing store
All Known Implementing Classes:
CollectionStream, ReadStream, WriteStream

public interface Stream<E,S extends ReadOnlySequence<E>>

Provides protocol for a stream consisting of a finite number of past and future sequence values. It maintains a position on its sequence values and allows the position to be altered.

Version:
$Id: Stream.java,v 1.2 2008/03/26 18:00:34 pholser Exp $
Author:
Paul Holser

Method Summary
 boolean atEnd()
          Tells whether this stream is at the end of its values.
 void close()
          Disassociates this stream from its backing store.
 S contents()
          Answers a sequence containing the complete contents of this stream.
 boolean isEmpty()
          Tells whether there are any sequence values in this stream.
 int position()
          Answers the current position of this stream.
 void position(int amount)
          Sets the current position in this stream.
 void reset()
          Sets the position of this stream to be at the beginning of the stream of values.
 void setToEnd()
          Sets the position of this stream to be at the end of the stream of values.
 

Method Detail

atEnd

boolean atEnd()
Tells whether this stream is at the end of its values.

Returns:
true if this stream has no future sequence values available for reading; false otherwise.
Throws:
IllegalStateException - if this stream has been previously closed

close

void close()
Disassociates this stream from its backing store. Any system resources associated with the association should be released.

This message is idempotent: sending it multiple times to this stream has no effect.


contents

S contents()
Answers a sequence containing the complete contents of this stream.

The returned sequence contains this stream's past and future sequence values, in order. The size of the collection is the sum of the sizes of the past and future sequence values.

Returns:
the contents of the receiving stream
Throws:
IllegalStateException - if this stream has been previously closed

isEmpty

boolean isEmpty()
Tells whether there are any sequence values in this stream.

Returns:
true if there are any sequence values in this stream
Throws:
IllegalStateException - if this stream has been previously closed

position

int position()
Answers the current position of this stream.

Returns:
current position
Throws:
IllegalStateException - if this stream has been previously closed

position

void position(int amount)
Sets the current position in this stream.

If the number of past sequence values is smaller than amount, move objects in sequence from the front of the future sequence values to the back of the past sequence values until the number of past sequence values is equal to amount.

If the number of past sequence values is greater than amount, move objects in sequence from the back of the past sequence values to the front of the future sequence values until the number past sequence values is equal to amount.

If the number of past sequence values is equal to amount, no action is taken.

Parameters:
amount - the new position
Throws:
IndexOutOfBoundsException - if amount is negative, or if this stream is not empty and amount >= the total number of sequence values in this stream
IllegalStateException - if this stream has been previously closed

reset

void reset()
Sets the position of this stream to be at the beginning of the stream of values.

Sets the future sequence values to be the current past sequence values appended with the current future sequence values--that is, makes this stream's past sequence values empty.

Throws:
IllegalStateException - if this stream has been previously closed

setToEnd

void setToEnd()
Sets the position of this stream to be at the end of the stream of values.

Adds all of the future sequence values are appended, in sequence, to the past sequence values--that is, makes the future sequence values empty.

Throws:
IllegalStateException - if this stream has been previously closed


© Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. Licensed under the Academic Free License version 3.0. pholser@alumni.rice.edu