--- jsr166/src/main/java/util/PriorityQueue.java 2003/06/24 14:34:30 1.7 +++ jsr166/src/main/java/util/PriorityQueue.java 2003/07/13 22:51:22 1.9 @@ -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; /** @@ -127,15 +128,12 @@ public class PriorityQueue extends Ab initialCapacity = 1; queue = new E[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()); @@ -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) { + while (size >= queue.length) { E[] newQueue = new E[2 * queue.length]; - System.arraycopy(queue, 0, newQueue, 0, size); + 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; }