--- jsr166/src/main/java/util/PriorityQueue.java 2003/08/06 01:57:53 1.23 +++ jsr166/src/main/java/util/PriorityQueue.java 2003/08/24 23:31:53 1.29 @@ -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 @@ -81,7 +93,7 @@ public class PriorityQueue extends Ab /** * Creates a PriorityQueue with the default initial capacity * (11) that orders its elements according to their natural - * ordering (using Comparable.) + * ordering (using Comparable). */ public PriorityQueue() { this(DEFAULT_INITIAL_CAPACITY, null); @@ -90,7 +102,7 @@ public class PriorityQueue extends Ab /** * Creates a PriorityQueue with the specified initial capacity * that orders its elements according to their natural ordering - * (using Comparable.) + * (using Comparable). * * @param initialCapacity the initial capacity for this priority queue. * @throws IllegalArgumentException if initialCapacity is less @@ -159,7 +171,7 @@ public class PriorityQueue extends Ab * specified collection. The priority queue has an initial * capacity of 110% of the size of the specified collection or 1 * if the collection is empty. If the specified collection is an - * instance of a {@link SortedSet} or is another + * instance of a {@link java.util.SortedSet} or is another * PriorityQueue, the priority queue will be sorted * according to the same comparator, or according to its elements' * natural order if the collection is sorted according to its @@ -176,17 +188,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); } @@ -531,7 +542,7 @@ public class PriorityQueue extends Ab /** * Returns the comparator used to order this collection, or null * if this collection is sorted according to its elements natural ordering - * (using Comparable.) + * (using Comparable). * * @return the comparator used to order this collection, or null * if this collection is sorted according to its elements natural ordering.