Class FIFOQueue

java.lang.Object
   |
   +----FIFOQueue

public class FIFOQueue
extends Object
implements Enumeration

NetRand Project

Software Engineering - CS536

University of Wisconsin - Milwaukee

Authors:


File: FIFOQueue.java

Written by Tim Macinta 1997
Distributed under the GNU Public License This class provides a simple First In First Out Queue. Please Note: this implementation of a FIFOQueue is not thread safe so if you plan on accessing the same queue with multiple threads you wil need to handle synchronization yourself (e.g., by creating a synchronized subclass).


Variable Index

 o grow_size
 o insert_point
 o q
 o read_point

Constructor Index

 o FIFOQueue()
 o FIFOQueue(int, int)
"initial_cap" specifies the initial capacity of the queue and "grow_size" specifies the amount that the capacity grows by when capacity is reached.

Method Index

 o addElement(Object)
Adds "object" to the queue.
 o countElements()
Returns the number of elements in this queue.
 o grow()
Enlarges the queue capacity by "grow_size".
 o hasMoreElements()
Returns true if this queue contains more elements and false otherwise.
 o insertElementAt(Object, int)
Insert "element" in the queue at index number "index."
 o nextElement()
Removes the next element from the queue and returns it.
 o readElementAt(int)
Returns the element at index number "index" (index number 0 is the first element that is read with the nextElement() method).
 o readNextElement()
Returns the next element that on the queue, but leaves the element on the queue so that the next call to nextElement() or readNextElement() will return the same element.
 o setCapacity(int)
Conserves memory by shrinking the capacity of the queue to "new_capacity".
 o shift()
Shifts all elements so that "read_point" is set to 0.
 o shrinkCapacityToSize()
Sets the capacity to the number of elements in the queue.

Variables

 o grow_size
 int grow_size
 o insert_point
 int insert_point
 o read_point
 int read_point
 o q
 Object q[]

Constructors

 o FIFOQueue
 public FIFOQueue()
 o FIFOQueue
 public FIFOQueue(int initial_cap,
                  int grow_size)
"initial_cap" specifies the initial capacity of the queue and "grow_size" specifies the amount that the capacity grows by when capacity is reached. Both parameters must be positive.

Methods

 o addElement
 public void addElement(Object object)
Adds "object" to the queue. "object" CAN be null.

 o grow
 void grow()
Enlarges the queue capacity by "grow_size".

 o shift
 void shift()
Shifts all elements so that "read_point" is set to 0.

 o nextElement
 public Object nextElement()
Removes the next element from the queue and returns it.

Throws a java.util.NoSuchElementException if the queue is empty.

 o readNextElement
 public Object readNextElement()
Returns the next element that on the queue, but leaves the element on the queue so that the next call to nextElement() or readNextElement() will return the same element.

Throws a java.util.NoSuchElementException if the queue is empty.

 o hasMoreElements
 public boolean hasMoreElements()
Returns true if this queue contains more elements and false otherwise.

 o countElements
 public int countElements()
Returns the number of elements in this queue.

 o setCapacity
 public void setCapacity(int new_capacity)
Conserves memory by shrinking the capacity of the queue to "new_capacity". Of course, you can also use this method to manually grow the size of the queue, but this is unecessary. "new_capacity" should be greater than or equal to the number of elements in the queue - if it is less than the number of elements in the queue, the capacity will be set to the number of elements in the queue.

 o shrinkCapacityToSize
 public void shrinkCapacityToSize()
Sets the capacity to the number of elements in the queue. Equivalent to setCapacity(countElements()) .

 o readElementAt
 public Object readElementAt(int index)
Returns the element at index number "index" (index number 0 is the first element that is read with the nextElement() method).

 o insertElementAt
 public void insertElementAt(Object element,
                             int index)
Insert "element" in the queue at index number "index."