--- jsr166/src/main/java/util/PriorityQueue.java 2005/11/28 02:35:46 1.56 +++ jsr166/src/main/java/util/PriorityQueue.java 2006/02/16 08:17:21 1.62 @@ -1,12 +1,11 @@ /* - * @(#)PriorityQueue.java 1.8 05/08/27 + * %W% %E% * - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.util; -import java.util.*; // for javadoc (till 6280605 is fixed) /** * An unbounded priority {@linkplain Queue queue} based on a priority @@ -56,7 +55,7 @@ import java.util.*; // for javadoc (till * * Java Collections Framework. * @since 1.5 - * @version 1.8, 08/27/05 + * @version %I%, %G% * @author Josh Bloch * @param the type of elements held in this collection */ @@ -229,7 +228,9 @@ public class PriorityQueue extends Ab // Double size if small; else grow by 50% int newCapacity = ((oldCapacity < 64)? ((oldCapacity + 1) * 2): - ((oldCapacity * 3) / 2)); + ((oldCapacity / 2) * 3)); + if (newCapacity < 0) // overflow + newCapacity = Integer.MAX_VALUE; if (newCapacity < minCapacity) newCapacity = minCapacity; queue = Arrays.copyOf(queue, newCapacity); @@ -309,10 +310,10 @@ public class PriorityQueue extends Ab /** * Version of remove using reference equality, not equals. - * Needed by iterator.remove + * Needed by iterator.remove. * * @param o element to be removed from this queue, if present - * @return true if removed. + * @return true if removed */ boolean removeEq(Object o) { for (int i = 0; i < size; i++) { @@ -344,7 +345,7 @@ public class PriorityQueue extends Ab * maintained by this list. (In other words, this method must allocate * a new array). The caller is thus free to modify the returned array. * - * @return an array containing all of the elements in this queue. + * @return an array containing all of the elements in this queue */ public Object[] toArray() { return Arrays.copyOf(queue, size);