1: /** 2: A class that implements a queue of objects by using an array. 3: @author Frank M. Carrano 4: @author Timothy M. Henry 5: @version 5.0 6: */ 7: public final class ArrayQueue<T> implements QueueInterface<T> 8: { 9: private T[] queue; // Circular array of queue entries and one unused element 10: private int frontIndex; 11: private int backIndex; 12: private boolean integrityOK; 13: private static final int DEFAULT_CAPACITY = 50; 14: private static final int MAX_CAPACITY = 10000; 15: 16: public ArrayQueue() 17: { 18: this(DEFAULT_CAPACITY); 19: } // end default constructor 20: 21: public ArrayQueue(int initialCapacity) 22: { 23: integrityOK = false; 24: checkCapacity(initialCapacity); 25: 26: // The cast is safe because the new array contains null entries 27: @SuppressWarnings("unchecked") 28: T[] tempQueue = (T[]) new Object[initialCapacity + 1]; 29: queue = tempQueue; 30: frontIndex = 0; 31: backIndex = initialCapacity; 32: integrityOK = true; 33: } // end constructor 35: // < Implementations of the queue operations go here. > 36: // . . . 37: 38: } // end ArrayQueue