// Doubles the size of the array queue if it is full
// Precondition: checkInitialization has been called.
private void ensureCapacity()
{
   if (frontIndex == ((backIndex + 2) % queue.length)) // if array is full,
   {                                                   // double size of array
      T[] oldQueue = queue;
      int oldSize = oldQueue.length;
      int newSize = 2 * oldSize;
      checkCapacity(newSize);

      // The cast is safe because the new array contains null entries
      @SuppressWarnings("unchecked")
      T[] tempQueue = (T[]) new Object[2 * oldSize];
      queue = tempQueue;
      for (int index = 0; index < oldSize - 1; index++)
      {
         queue[index] = oldQueue[frontIndex];
         frontIndex = (frontIndex + 1) % oldSize;
      } // end for
      
      frontIndex = 0;
      backIndex = oldSize - 2;
   } // end if
} // end ensureCapacity
// Version 4.0
