31 |
|
* @author Josh Bloch |
32 |
|
*/ |
33 |
|
public class PriorityQueue<E> extends AbstractQueue<E> |
34 |
< |
implements Queue<E>, |
34 |
> |
implements Queue<E>, |
35 |
|
java.io.Serializable { |
36 |
|
private static final int DEFAULT_INITIAL_CAPACITY = 11; |
37 |
|
|
97 |
|
public PriorityQueue(int initialCapacity, Comparator<E> comparator) { |
98 |
|
if (initialCapacity < 1) |
99 |
|
initialCapacity = 1; |
100 |
< |
queue = new E[initialCapacity + 1]; |
100 |
> |
queue = (E[]) new Object[initialCapacity + 1]; |
101 |
|
this.comparator = comparator; |
102 |
|
} |
103 |
|
|
126 |
|
Integer.MAX_VALUE - 1); |
127 |
|
if (initialCapacity < 1) |
128 |
|
initialCapacity = 1; |
129 |
< |
queue = new E[initialCapacity + 1]; |
129 |
> |
queue = (E[]) new Object[initialCapacity + 1]; |
130 |
|
|
131 |
|
|
132 |
|
if (initialElements instanceof Sorted) { |
217 |
|
* elements of the priority queue will be returned by this iterator in the |
218 |
|
* order specified by the queue, which is to say the order they would be |
219 |
|
* returned by repeated calls to <tt>poll</tt>. |
220 |
< |
* |
220 |
> |
* |
221 |
|
* @return an <tt>Iterator</tt> over the elements in this priority queue. |
222 |
|
*/ |
223 |
|
public Iterator<E> iterator() { |
278 |
|
|
279 |
|
/** |
280 |
|
* Returns the number of elements in this priority queue. |
281 |
< |
* |
281 |
> |
* |
282 |
|
* @return the number of elements in this priority queue. |
283 |
|
*/ |
284 |
|
public int size() { |
303 |
|
|
304 |
|
// Grow backing store if necessary |
305 |
|
while (size >= queue.length) { |
306 |
< |
E[] newQueue = new E[2 * queue.length]; |
306 |
> |
E[] newQueue = (E[]) new Object[2 * queue.length]; |
307 |
|
System.arraycopy(queue, 0, newQueue, 0, queue.length); |
308 |
|
queue = newQueue; |
309 |
|
} |
451 |
|
|
452 |
|
// Read in array length and allocate array |
453 |
|
int arrayLength = s.readInt(); |
454 |
< |
queue = new E[arrayLength]; |
454 |
> |
queue = (E[]) new Object[arrayLength]; |
455 |
|
|
456 |
|
// Read in all elements in the proper order. |
457 |
|
for (int i=0; i<size; i++) |