--- jsr166/src/main/java/util/PriorityQueue.java 2003/06/24 14:34:30 1.7 +++ jsr166/src/main/java/util/PriorityQueue.java 2003/07/26 13:17:51 1.10 @@ -31,7 +31,8 @@ * @author Josh Bloch */ public class PriorityQueue extends AbstractQueue - implements Queue { + implements Queue, + java.io.Serializable { private static final int DEFAULT_INITIAL_CAPACITY = 11; /** @@ -96,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; } @@ -125,17 +126,14 @@ 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]; - /* Commented out to compile with generics compiler if (initialElements instanceof Sorted) { comparator = ((Sorted)initialElements).comparator(); for (Iterator i = initialElements.iterator(); i.hasNext(); ) queue[++size] = i.next(); } else { - */ - { comparator = null; for (Iterator i = initialElements.iterator(); i.hasNext(); ) add(i.next()); @@ -219,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() { @@ -280,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() { @@ -301,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; } @@ -414,7 +413,7 @@ public class PriorityQueue extends Ab * @return the comparator associated with this priority queue, or * null if it uses its elements' natural ordering. */ - Comparator comparator() { + public Comparator comparator() { return comparator; } @@ -452,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