3 * $Id: WoolieQueue.java,v 2.4 2005/01/26 04:15:44 vcss232 Exp $
6 * $Log: WoolieQueue.java,v $
7 * Revision 2.4 2005/01/26 04:15:44 vcss232
10 * Revision 2.3 2004/04/12 23:49:05 cs3
11 * moved the instance variables to the top of the class (bk)
13 * Revision 2.2 2004/01/21 20:05:08 icss235
14 * Reversed order from LIFO to FIFO (jeh)
16 * Revision 2.1 2004/01/21 16:43:43 icss235
17 * Simplified design. (jeh,swm)
19 * Revision 2.0 2004/01/20 22:06:59 icss235
20 * *** empty log message ***
25 * A multithread-safe wrapper around a linked list to make a queue.
27 * @author James Heliotis
29 public class WoolieQueue
{
32 * The underlying data structure
34 private java
.util
.LinkedList
< Woolie
> woolies
=
35 new java
.util
.LinkedList
< Woolie
>();
39 * Constructor. Does nothing in this version.
41 public WoolieQueue() {
45 * Insert a woolie into the queue.
47 * @param caller the Woolie to be inserted.
49 public synchronized void insert( Woolie caller
) {
50 woolies
.addFirst( caller
);
55 * Inspect the first woolie in the queue.
56 * This method never blocks.
58 * @return the Woolie that has been in the queue for
59 * the longest time, or null if the queue is
62 public synchronized Woolie
peek() {
65 result
= woolies
.getLast();
67 catch( java
.util
.NoSuchElementException nse
) {
73 * Remove a woolie from the queue.
74 * This call blocks while the queue is empty.
76 * @return the Woolie that has been in the queue for
79 public synchronized Woolie
remove() {
80 while ( woolies
.isEmpty() ) {
84 catch( InterruptedException ie
) {}
86 return woolies
.removeLast();