ps4
Class Pipe

java.lang.Object
  extended byps4.Pipe
All Implemented Interfaces:
Simulatable
Direct Known Subclasses:
IntPipe

public abstract class Pipe
extends Object
implements Simulatable

The Pipe abstract class is implemented by each of the pipes in the pipe-and-filter simulation.

Specification Fields

Field Summary
protected  List inQueue
           
protected  Object label
           
protected  List outQueue
           
protected  Simulator sim
           
 
Constructor Summary
Pipe(Object label, Simulator sim)
           
 
Method Summary
 void checkRep()
           
 Iterator contentsIterator()
          Obtain an iterator over the contents of the pipe
 Object extract()
          Extract an object from the pipe.
 void inject(Object o)
          Inject an object into the pipe.
 boolean outputAvailable()
          Check if any output is available from the pipe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ps4.Simulatable
simulate
 

Field Detail

inQueue

protected List inQueue

outQueue

protected List outQueue

label

protected Object label

sim

protected Simulator sim
Constructor Detail

Pipe

public Pipe(Object label,
            Simulator sim)
Requires:
label != null, sim != null
Effects:
constructs a new Pipe with the given label and simulator
Method Detail

checkRep

public void checkRep()

inject

public void inject(Object o)
Inject an object into the pipe.

Requires:
o != null
Effects:
Adds o to the end of the input queue of the pipe.
Modifies:
this

extract

public Object extract()
Extract an object from the pipe.

Requires:
At least one element is in the output queue.
Effects:
Removes the first element from the output queue.
Modifies:
this
Returns:
The first element from the output queue of the pipe.

outputAvailable

public boolean outputAvailable()
Check if any output is available from the pipe

Requires:
none
Returns:
true output is available; i.e. if the output queue contains at least one element.

contentsIterator

public Iterator contentsIterator()
Obtain an iterator over the contents of the pipe

Requires:
none
Effects:
returns an unmodifiable iterator over the list of elements in this pipe, in both the output and input queues, starting with the one that will be output next, and ending with the one most recently input.