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 |
|
|
38 |
|
/** |
128 |
|
initialCapacity = 1; |
129 |
|
queue = new E[initialCapacity + 1]; |
130 |
|
|
130 |
– |
/* Commented out to compile with generics compiler |
131 |
|
|
132 |
|
if (initialElements instanceof Sorted) { |
133 |
|
comparator = ((Sorted)initialElements).comparator(); |
134 |
|
for (Iterator<E> i = initialElements.iterator(); i.hasNext(); ) |
135 |
|
queue[++size] = i.next(); |
136 |
|
} else { |
137 |
– |
*/ |
138 |
– |
{ |
137 |
|
comparator = null; |
138 |
|
for (Iterator<E> i = initialElements.iterator(); i.hasNext(); ) |
139 |
|
add(i.next()); |
299 |
|
if (element == null) |
300 |
|
throw new NullPointerException(); |
301 |
|
modCount++; |
302 |
+ |
++size; |
303 |
|
|
304 |
|
// Grow backing store if necessary |
305 |
< |
if (++size == queue.length) { |
305 |
> |
while (size >= queue.length) { |
306 |
|
E[] newQueue = new E[2 * queue.length]; |
307 |
< |
System.arraycopy(queue, 0, newQueue, 0, size); |
307 |
> |
System.arraycopy(queue, 0, newQueue, 0, queue.length); |
308 |
|
queue = newQueue; |
309 |
|
} |
310 |
|
|
413 |
|
* @return the comparator associated with this priority queue, or |
414 |
|
* <tt>null</tt> if it uses its elements' natural ordering. |
415 |
|
*/ |
416 |
< |
Comparator comparator() { |
416 |
> |
public Comparator comparator() { |
417 |
|
return comparator; |
418 |
|
} |
419 |
|
|