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 |
189 |
|
public PriorityQueue(Collection<? extends E> c) { |
190 |
|
initializeArray(c); |
191 |
|
if (c instanceof SortedSet) { |
192 |
< |
SortedSet<? extends E> s = (SortedSet<? extends E>) c; |
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 |
|
} else if (c instanceof PriorityQueue) { |