< 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,39 **** /** * A simple variable length first-in first-out queue. */ ! public class Fifo { /** * Create a buffer with a default initial size. */ public Fifo() { --- 29,39 ---- /** * A simple variable length first-in first-out queue. */ ! public class Fifo<E> { /** * Create a buffer with a default initial size. */ public Fifo() {
*** 46,56 **** * @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]; insertSlot = 0; removeSlot = 0; entries = 0; } --- 46,56 ---- * @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 = (E[]) new Object[bufSize]; insertSlot = 0; removeSlot = 0; entries = 0; }
*** 76,92 **** * 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) { if (obj == null) throw new NullPointerException(); if (entries == bufSize) { int newBufSize = 2 * bufSize; ! Object[] newBuf = new Object[newBufSize]; int saveEntries = entries; for (int i = 0; entries > 0; i++) { newBuf[i] = remove(); } entries = saveEntries; --- 76,92 ---- * 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(E obj) { if (obj == null) throw new NullPointerException(); if (entries == bufSize) { int newBufSize = 2 * bufSize; ! E[] newBuf = (E[]) new Object[newBufSize]; int saveEntries = entries; for (int i = 0; entries > 0; i++) { newBuf[i] = remove(); } entries = saveEntries;
*** 105,119 **** * 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() { if (entries == 0) return null; ! Object o = buf[removeSlot]; buf[removeSlot] = null; removeSlot = (removeSlot + 1) % bufSize; entries--; return o; --- 105,119 ---- * 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 E remove() { if (entries == 0) return null; ! E o = buf[removeSlot]; buf[removeSlot] = null; removeSlot = (removeSlot + 1) % bufSize; entries--; return o;
*** 133,143 **** //----------Data members--------------------------------------------------------- private final static int defaultInitialSlots = 16; ! private Object[] 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 --- 133,143 ---- //----------Data members--------------------------------------------------------- private final static int defaultInitialSlots = 16; ! 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 >