ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/PriorityQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/PriorityQueue.java (file contents):
Revision 1.64 by jsr166, Sun Mar 19 01:00:40 2006 UTC vs.
Revision 1.69 by jsr166, Sun May 18 23:59:57 2008 UTC

# Line 1 | Line 1
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 2006 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;
# Line 52 | Line 70 | package java.util;
70   * ({@code peek}, {@code element}, and {@code size}).
71   *
72   * <p>This class is a member of the
73 < * <a href="{@docRoot}/../guide/collections/index.html">
73 > * <a href="{@docRoot}/../technotes/guides/collections/index.html">
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   */
# Line 226 | Line 243 | public class PriorityQueue<E> extends Ab
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):
# Line 282 | Line 299 | public class PriorityQueue<E> extends Ab
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;
# Line 302 | Line 319 | public class PriorityQueue<E> extends Ab
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      /**
# Line 319 | Line 336 | public class PriorityQueue<E> extends Ab
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              }
# Line 337 | Line 354 | public class PriorityQueue<E> extends Ab
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      /**
# Line 398 | Line 415 | public class PriorityQueue<E> extends Ab
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;
# Line 491 | Line 508 | public class PriorityQueue<E> extends Ab
508                  lastRetElt = null;
509              } else {
510                  throw new IllegalStateException();
511 <            }
511 >            }
512              expectedModCount = modCount;
513          }
514      }
# Line 707 | Line 724 | public class PriorityQueue<E> extends Ab
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines