< prev index next >
src/com/sun/javatest/util/Fifo.java
Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg
@@ -29,11 +29,11 @@
/**
* A simple variable length first-in first-out queue.
*/
-public class Fifo
+public class Fifo<E>
{
/**
* Create a buffer with a default initial size.
*/
public Fifo() {
@@ -46,11 +46,11 @@
* @param initialSlots The number of initial slots in the buffer; the number of
* slots required by the buffer will be expanded as required.
*/
public Fifo(int initialSlots) {
bufSize = initialSlots;
- buf = new Object[bufSize];
+ buf = (E[]) new Object[bufSize];
insertSlot = 0;
removeSlot = 0;
entries = 0;
}
@@ -76,17 +76,17 @@
* Insert an entry into the buffer. The buffer will be increased in size if necessary
* to accommodate the new entry.
*
* @param obj The object to be inserted. It must not be null.
*/
- public synchronized void insert(Object obj) {
+ public synchronized void insert(E obj) {
if (obj == null)
throw new NullPointerException();
if (entries == bufSize) {
int newBufSize = 2 * bufSize;
- Object[] newBuf = new Object[newBufSize];
+ E[] newBuf = (E[]) new Object[newBufSize];
int saveEntries = entries;
for (int i = 0; entries > 0; i++) {
newBuf[i] = remove();
}
entries = saveEntries;
@@ -105,15 +105,15 @@
* Remove an entry from the buffer if one is available.
*
* @return The next object in line to be removed, if one is available,
* or null if none are available.
*/
- public synchronized Object remove() {
+ public synchronized E remove() {
if (entries == 0)
return null;
- Object o = buf[removeSlot];
+ E o = buf[removeSlot];
buf[removeSlot] = null;
removeSlot = (removeSlot + 1) % bufSize;
entries--;
return o;
@@ -133,11 +133,11 @@
//----------Data members---------------------------------------------------------
private final static int defaultInitialSlots = 16;
- private Object[] buf; // The circular array to hold the entries
+ private E[] buf; // The circular array to hold the entries
private int bufSize; // The size of the array: buf.length
private int insertSlot; // The next slot to store an entry
private int removeSlot; // The next slot from which to remove an entry
private int entries; // The number of entries in the array
< prev index next >