--- jsr166/src/main/java/util/PriorityQueue.java 2003/08/06 18:42:49 1.25 +++ jsr166/src/main/java/util/PriorityQueue.java 2003/08/25 19:27:54 1.31 @@ -28,6 +28,18 @@ * elements are added to a priority queue, its capacity grows * automatically. The details of the growth policy are not specified. * + *

The Iterator provided in method {@link #iterator()} is not + * guaranteed to traverse the elements of the PriorityQueue in any + * particular order. If you need ordered traversal, consider using + * Arrays.sort(pq.toArray()). + * + *

Note that this implementation is not synchronized. + * Multiple threads should not access a PriorityQueue + * instance concurrently if any of the threads modifies the list + * structurally. Instead, use the thread-safe {@link + * java.util.concurrent.BlockingPriorityQueue} class. + * + * *

Implementation note: this implementation provides O(log(n)) time * for the insertion methods (offer, poll, * remove() and add) methods; linear time for the @@ -44,6 +56,8 @@ public class PriorityQueue extends AbstractQueue implements Queue, java.io.Serializable { + private static final long serialVersionUID = -7720805057305804111L; + private static final int DEFAULT_INITIAL_CAPACITY = 11; /** @@ -176,17 +190,16 @@ public class PriorityQueue extends Ab */ public PriorityQueue(Collection c) { initializeArray(c); - if (c instanceof SortedSet) { - SortedSet s = (SortedSet) c; + if (c instanceof SortedSet) { + // @fixme double-cast workaround for compiler + SortedSet s = (SortedSet) (SortedSet)c; comparator = (Comparator)s.comparator(); fillFromSorted(s); - } - else if (c instanceof PriorityQueue) { + } else if (c instanceof PriorityQueue) { PriorityQueue s = (PriorityQueue) c; comparator = (Comparator)s.comparator(); fillFromSorted(s); - } - else { + } else { comparator = null; fillFromUnsorted(c); }