74 |
|
* Java Collections Framework</a>. |
75 |
|
* |
76 |
|
* @since 1.5 |
77 |
– |
* @version %I%, %G% |
77 |
|
* @author Josh Bloch, Doug Lea |
78 |
|
* @param <E> the type of elements held in this collection |
79 |
|
*/ |
243 |
|
private void grow(int minCapacity) { |
244 |
|
if (minCapacity < 0) // overflow |
245 |
|
throw new OutOfMemoryError(); |
246 |
< |
int oldCapacity = queue.length; |
246 |
> |
int oldCapacity = queue.length; |
247 |
|
// Double size if small; else grow by 50% |
248 |
|
int newCapacity = ((oldCapacity < 64)? |
249 |
|
((oldCapacity + 1) * 2): |
299 |
|
} |
300 |
|
|
301 |
|
private int indexOf(Object o) { |
302 |
< |
if (o != null) { |
302 |
> |
if (o != null) { |
303 |
|
for (int i = 0; i < size; i++) |
304 |
|
if (o.equals(queue[i])) |
305 |
|
return i; |
319 |
|
* @return {@code true} if this queue changed as a result of the call |
320 |
|
*/ |
321 |
|
public boolean remove(Object o) { |
322 |
< |
int i = indexOf(o); |
323 |
< |
if (i == -1) |
324 |
< |
return false; |
325 |
< |
else { |
326 |
< |
removeAt(i); |
327 |
< |
return true; |
328 |
< |
} |
322 |
> |
int i = indexOf(o); |
323 |
> |
if (i == -1) |
324 |
> |
return false; |
325 |
> |
else { |
326 |
> |
removeAt(i); |
327 |
> |
return true; |
328 |
> |
} |
329 |
|
} |
330 |
|
|
331 |
|
/** |
336 |
|
* @return {@code true} if removed |
337 |
|
*/ |
338 |
|
boolean removeEq(Object o) { |
339 |
< |
for (int i = 0; i < size; i++) { |
340 |
< |
if (o == queue[i]) { |
339 |
> |
for (int i = 0; i < size; i++) { |
340 |
> |
if (o == queue[i]) { |
341 |
|
removeAt(i); |
342 |
|
return true; |
343 |
|
} |
354 |
|
* @return {@code true} if this queue contains the specified element |
355 |
|
*/ |
356 |
|
public boolean contains(Object o) { |
357 |
< |
return indexOf(o) != -1; |
357 |
> |
return indexOf(o) != -1; |
358 |
|
} |
359 |
|
|
360 |
|
/** |
415 |
|
if (a.length < size) |
416 |
|
// Make a new array of a's runtime type, but my contents: |
417 |
|
return (T[]) Arrays.copyOf(queue, size, a.getClass()); |
418 |
< |
System.arraycopy(queue, 0, a, 0, size); |
418 |
> |
System.arraycopy(queue, 0, a, 0, size); |
419 |
|
if (a.length > size) |
420 |
|
a[size] = null; |
421 |
|
return a; |
508 |
|
lastRetElt = null; |
509 |
|
} else { |
510 |
|
throw new IllegalStateException(); |
511 |
< |
} |
511 |
> |
} |
512 |
|
expectedModCount = modCount; |
513 |
|
} |
514 |
|
} |
724 |
|
// Read in (and discard) array length |
725 |
|
s.readInt(); |
726 |
|
|
727 |
< |
queue = new Object[size]; |
727 |
> |
queue = new Object[size]; |
728 |
|
|
729 |
|
// Read in all elements. |
730 |
|
for (int i = 0; i < size; i++) |
731 |
|
queue[i] = s.readObject(); |
732 |
|
|
733 |
< |
// Elements are guaranteed to be in "proper order", but the |
734 |
< |
// spec has never explained what that might be. |
735 |
< |
heapify(); |
733 |
> |
// Elements are guaranteed to be in "proper order", but the |
734 |
> |
// spec has never explained what that might be. |
735 |
> |
heapify(); |
736 |
|
} |
737 |
|
} |