ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/PriorityQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/PriorityQueue.java (file contents):
Revision 1.23 by dholmes, Wed Aug 6 01:57:53 2003 UTC vs.
Revision 1.29 by dl, Sun Aug 24 23:31:53 2003 UTC

# Line 28 | Line 28
28   * elements are added to a priority queue, its capacity grows
29   * automatically.  The details of the growth policy are not specified.
30   *
31 + * <p>The Iterator provided in method {@link #iterator()} is <em>not</em>
32 + * guaranteed to traverse the elements of the PriorityQueue in any
33 + * particular order. If you need ordered traversal, consider using
34 + * <tt>Arrays.sort(pq.toArray())</tt>.
35 + *
36 + * <p> <strong>Note that this implementation is not synchronized.</strong>
37 + * Multiple threads should not access a <tt>PriorityQueue</tt>
38 + * instance concurrently if any of the threads modifies the list
39 + * structurally. Instead, use the thread-safe {@link
40 + * java.util.concurrent.BlockingPriorityQueue} class.
41 + *
42 + *
43   * <p>Implementation note: this implementation provides O(log(n)) time
44   * for the insertion methods (<tt>offer</tt>, <tt>poll</tt>,
45   * <tt>remove()</tt> and <tt>add</tt>) methods; linear time for the
# Line 81 | Line 93 | public class PriorityQueue<E> extends Ab
93      /**
94       * Creates a <tt>PriorityQueue</tt> with the default initial capacity
95       * (11) that orders its elements according to their natural
96 <     * ordering (using <tt>Comparable</tt>.)
96 >     * ordering (using <tt>Comparable</tt>).
97       */
98      public PriorityQueue() {
99          this(DEFAULT_INITIAL_CAPACITY, null);
# Line 90 | Line 102 | public class PriorityQueue<E> extends Ab
102      /**
103       * Creates a <tt>PriorityQueue</tt> with the specified initial capacity
104       * that orders its elements according to their natural ordering
105 <     * (using <tt>Comparable</tt>.)
105 >     * (using <tt>Comparable</tt>).
106       *
107       * @param initialCapacity the initial capacity for this priority queue.
108       * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less
# Line 159 | Line 171 | public class PriorityQueue<E> extends Ab
171       * specified collection.  The priority queue has an initial
172       * capacity of 110% of the size of the specified collection or 1
173       * if the collection is empty.  If the specified collection is an
174 <     * instance of a {@link SortedSet} or is another
174 >     * instance of a {@link java.util.SortedSet} or is another
175       * <tt>PriorityQueue</tt>, the priority queue will be sorted
176       * according to the same comparator, or according to its elements'
177       * natural order if the collection is sorted according to its
# Line 176 | Line 188 | public class PriorityQueue<E> extends Ab
188       */
189      public PriorityQueue(Collection<? extends E> c) {
190          initializeArray(c);
191 <        if (c instanceof SortedSet<? extends E>) {
192 <            SortedSet<? extends E> s = (SortedSet<? extends E>) c;
191 >        if (c instanceof SortedSet) {
192 >            // @fixme double-cast workaround for compiler
193 >            SortedSet<? extends E> s = (SortedSet<? extends E>) (SortedSet)c;
194              comparator = (Comparator<? super E>)s.comparator();
195              fillFromSorted(s);
196 <        }
184 <        else if (c instanceof PriorityQueue<? extends E>) {
196 >        } else if (c instanceof PriorityQueue) {
197              PriorityQueue<? extends E> s = (PriorityQueue<? extends E>) c;
198              comparator = (Comparator<? super E>)s.comparator();
199              fillFromSorted(s);
200 <        }
189 <        else {
200 >        } else {
201              comparator = null;
202              fillFromUnsorted(c);
203          }
# Line 531 | Line 542 | public class PriorityQueue<E> extends Ab
542      /**
543       * Returns the comparator used to order this collection, or <tt>null</tt>
544       * if this collection is sorted according to its elements natural ordering
545 <     * (using <tt>Comparable</tt>.)
545 >     * (using <tt>Comparable</tt>).
546       *
547       * @return the comparator used to order this collection, or <tt>null</tt>
548       * if this collection is sorted according to its elements natural ordering.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines