--- jsr166/src/main/java/util/PriorityQueue.java 2003/07/01 16:29:45 1.8 +++ jsr166/src/main/java/util/PriorityQueue.java 2003/07/26 13:17:51 1.10 @@ -31,7 +31,7 @@ * @author Josh Bloch */ public class PriorityQueue extends AbstractQueue - implements Queue, + implements Queue, java.io.Serializable { private static final int DEFAULT_INITIAL_CAPACITY = 11; @@ -97,7 +97,7 @@ public class PriorityQueue extends Ab public PriorityQueue(int initialCapacity, Comparator comparator) { if (initialCapacity < 1) initialCapacity = 1; - queue = new E[initialCapacity + 1]; + queue = (E[]) new Object[initialCapacity + 1]; this.comparator = comparator; } @@ -126,7 +126,7 @@ public class PriorityQueue extends Ab Integer.MAX_VALUE - 1); if (initialCapacity < 1) initialCapacity = 1; - queue = new E[initialCapacity + 1]; + queue = (E[]) new Object[initialCapacity + 1]; if (initialElements instanceof Sorted) { @@ -217,7 +217,7 @@ public class PriorityQueue extends Ab * elements of the priority queue will be returned by this iterator in the * order specified by the queue, which is to say the order they would be * returned by repeated calls to poll. - * + * * @return an Iterator over the elements in this priority queue. */ public Iterator iterator() { @@ -278,7 +278,7 @@ public class PriorityQueue extends Ab /** * Returns the number of elements in this priority queue. - * + * * @return the number of elements in this priority queue. */ public int size() { @@ -299,11 +299,12 @@ public class PriorityQueue extends Ab if (element == null) throw new NullPointerException(); modCount++; + ++size; // Grow backing store if necessary - if (++size == queue.length) { - E[] newQueue = new E[2 * queue.length]; - System.arraycopy(queue, 0, newQueue, 0, size); + while (size >= queue.length) { + E[] newQueue = (E[]) new Object[2 * queue.length]; + System.arraycopy(queue, 0, newQueue, 0, queue.length); queue = newQueue; } @@ -450,7 +451,7 @@ public class PriorityQueue extends Ab // Read in array length and allocate array int arrayLength = s.readInt(); - queue = new E[arrayLength]; + queue = (E[]) new Object[arrayLength]; // Read in all elements in the proper order. for (int i=0; i