8 |
|
package java.util; |
9 |
|
|
10 |
|
/** |
11 |
< |
* An unbounded priority {@linkplain Queue queue} based on a priority heap. |
12 |
< |
* This queue orders elements according to an order specified at construction |
13 |
< |
* time, which is specified in the same manner as {@link java.util.TreeSet} |
14 |
< |
* and {@link java.util.TreeMap}: elements are ordered either according to |
15 |
< |
* their <i>natural order</i> (see {@link Comparable}), or according to a |
16 |
< |
* {@link java.util.Comparator}, depending on which constructor is used. |
11 |
> |
* An unbounded priority {@linkplain Queue queue} based on a priority |
12 |
> |
* heap. This queue orders elements according to an order specified |
13 |
> |
* at construction time, which is specified either according to their |
14 |
> |
* <i>natural order</i> (see {@link Comparable}), or according to a |
15 |
> |
* {@link java.util.Comparator}, depending on which constructor is |
16 |
> |
* used. A priority queue does not permit <tt>null</tt> elements. |
17 |
|
* |
18 |
< |
* <p>The <em>head</em> of this queue is the <em>least</em> element with |
19 |
< |
* respect to the specified ordering. If multiple elements are tied for least |
20 |
< |
* value, the head is one of those elements. A priority queue does not permit |
21 |
< |
* <tt>null</tt> elements. |
18 |
> |
* <p>The <em>head</em> of this queue is the <em>least</em> element |
19 |
> |
* with respect to the specified ordering. If multiple elements are |
20 |
> |
* tied for least value, the head is one of those elements -- ties are |
21 |
> |
* broken arbitrarily. The {@link #remove()} and {@link #poll()} |
22 |
> |
* methods remove and return the head of the queue, and the {@link |
23 |
> |
* #element()} and {@link #peek()} methods return, but do not delete, |
24 |
> |
* the head of the queue. |
25 |
|
* |
26 |
< |
* <p>The {@link #remove()} and {@link #poll()} methods remove and |
27 |
< |
* return the head of the queue. |
25 |
< |
* |
26 |
< |
* <p>The {@link #element()} and {@link #peek()} methods return, but do |
27 |
< |
* not delete, the head of the queue. |
28 |
< |
* |
29 |
< |
* <p>A priority queue is unbounded, but has a <i>capacity</i>. The |
30 |
< |
* capacity is the size of the array used internally to store the |
26 |
> |
* <p>A priority queue is unbounded, but has an internal |
27 |
> |
* <i>capacity</i> governing the size of an array used to store the |
28 |
|
* elements on the queue. It is always at least as large as the queue |
29 |
|
* size. As elements are added to a priority queue, its capacity |
30 |
|
* grows automatically. The details of the growth policy are not |
31 |
|
* specified. |
32 |
|
* |
33 |
< |
* <p>The Iterator provided in method {@link #iterator()} is <em>not</em> |
33 |
> |
* <p>This class implements all of the <em>optional</em> methods of |
34 |
> |
* the {@link Collection} and {@link Iterator} interfaces. The |
35 |
> |
* Iterator provided in method {@link #iterator()} is <em>not</em> |
36 |
|
* guaranteed to traverse the elements of the PriorityQueue in any |
37 |
|
* particular order. If you need ordered traversal, consider using |
38 |
|
* <tt>Arrays.sort(pq.toArray())</tt>. |
320 |
|
* to the priority queue's ordering. |
321 |
|
*/ |
322 |
|
public boolean add(E o) { |
323 |
< |
return super.add(o); |
323 |
> |
return offer(o); |
324 |
|
} |
325 |
|
|
326 |
|
|