1 |
|
/* |
2 |
< |
* %W% %E% |
2 |
> |
* Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. |
3 |
> |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
|
* |
5 |
< |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
6 |
< |
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
5 |
> |
* This code is free software; you can redistribute it and/or modify it |
6 |
> |
* under the terms of the GNU General Public License version 2 only, as |
7 |
> |
* published by the Free Software Foundation. Sun designates this |
8 |
> |
* particular file as subject to the "Classpath" exception as provided |
9 |
> |
* by Sun in the LICENSE file that accompanied this code. |
10 |
> |
* |
11 |
> |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
> |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
> |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
> |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
> |
* accompanied this code). |
16 |
> |
* |
17 |
> |
* You should have received a copy of the GNU General Public License version |
18 |
> |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
> |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
> |
* |
21 |
> |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
22 |
> |
* CA 95054 USA or visit www.sun.com if you need additional information or |
23 |
> |
* have any questions. |
24 |
|
*/ |
25 |
|
|
26 |
|
package java.util; |
74 |
|
* Java Collections Framework</a>. |
75 |
|
* |
76 |
|
* @since 1.5 |
59 |
– |
* @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 |
|
} |