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

Comparing jsr166/src/main/java/util/AbstractCollection.java (file contents):
Revision 1.12 by jsr166, Sun May 18 23:47:55 2008 UTC vs.
Revision 1.16 by jsr166, Thu Sep 30 01:53:03 2010 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
2 > * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# Line 18 | Line 18
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.
21 > * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 > * or visit www.oracle.com if you need additional information or have any
23 > * questions.
24   */
25  
26   package java.util;
# Line 54 | Line 54 | package java.util;
54   *
55   * @author  Josh Bloch
56   * @author  Neal Gafter
57 * @version %I%, %G%
57   * @see Collection
58   * @since 1.2
59   */
# Line 97 | Line 96 | public abstract class AbstractCollection
96       * @throws NullPointerException {@inheritDoc}
97       */
98      public boolean contains(Object o) {
99 <        Iterator<E> e = iterator();
99 >        Iterator<E> it = iterator();
100          if (o==null) {
101 <            while (e.hasNext())
102 <                if (e.next()==null)
101 >            while (it.hasNext())
102 >                if (it.next()==null)
103                      return true;
104          } else {
105 <            while (e.hasNext())
106 <                if (o.equals(e.next()))
105 >            while (it.hasNext())
106 >                if (o.equals(it.next()))
107                      return true;
108          }
109          return false;
# Line 256 | Line 255 | public abstract class AbstractCollection
255       * @throws NullPointerException          {@inheritDoc}
256       */
257      public boolean remove(Object o) {
258 <        Iterator<E> e = iterator();
258 >        Iterator<E> it = iterator();
259          if (o==null) {
260 <            while (e.hasNext()) {
261 <                if (e.next()==null) {
262 <                    e.remove();
260 >            while (it.hasNext()) {
261 >                if (it.next()==null) {
262 >                    it.remove();
263                      return true;
264                  }
265              }
266          } else {
267 <            while (e.hasNext()) {
268 <                if (o.equals(e.next())) {
269 <                    e.remove();
267 >            while (it.hasNext()) {
268 >                if (o.equals(it.next())) {
269 >                    it.remove();
270                      return true;
271                  }
272              }
# Line 291 | Line 290 | public abstract class AbstractCollection
290       * @see #contains(Object)
291       */
292      public boolean containsAll(Collection<?> c) {
293 <        Iterator<?> e = c.iterator();
294 <        while (e.hasNext())
295 <            if (!contains(e.next()))
293 >        Iterator<?> it = c.iterator();
294 >        while (it.hasNext())
295 >            if (!contains(it.next()))
296                  return false;
297          return true;
298      }
# Line 318 | Line 317 | public abstract class AbstractCollection
317       */
318      public boolean addAll(Collection<? extends E> c) {
319          boolean modified = false;
320 <        Iterator<? extends E> e = c.iterator();
321 <        while (e.hasNext()) {
322 <            if (add(e.next()))
320 >        Iterator<? extends E> it = c.iterator();
321 >        while (it.hasNext()) {
322 >            if (add(it.next()))
323                  modified = true;
324          }
325          return modified;
# Line 349 | Line 348 | public abstract class AbstractCollection
348       */
349      public boolean removeAll(Collection<?> c) {
350          boolean modified = false;
351 <        Iterator<?> e = iterator();
352 <        while (e.hasNext()) {
353 <            if (c.contains(e.next())) {
354 <                e.remove();
351 >        Iterator<?> it = iterator();
352 >        while (it.hasNext()) {
353 >            if (c.contains(it.next())) {
354 >                it.remove();
355                  modified = true;
356              }
357          }
# Line 382 | Line 381 | public abstract class AbstractCollection
381       */
382      public boolean retainAll(Collection<?> c) {
383          boolean modified = false;
384 <        Iterator<E> e = iterator();
385 <        while (e.hasNext()) {
386 <            if (!c.contains(e.next())) {
387 <                e.remove();
384 >        Iterator<E> it = iterator();
385 >        while (it.hasNext()) {
386 >            if (!c.contains(it.next())) {
387 >                it.remove();
388                  modified = true;
389              }
390          }
# Line 408 | Line 407 | public abstract class AbstractCollection
407       * @throws UnsupportedOperationException {@inheritDoc}
408       */
409      public void clear() {
410 <        Iterator<E> e = iterator();
411 <        while (e.hasNext()) {
412 <            e.next();
413 <            e.remove();
410 >        Iterator<E> it = iterator();
411 >        while (it.hasNext()) {
412 >            it.next();
413 >            it.remove();
414          }
415      }
416  
# Line 429 | Line 428 | public abstract class AbstractCollection
428       * @return a string representation of this collection
429       */
430      public String toString() {
431 <        Iterator<E> i = iterator();
432 <        if (! i.hasNext())
431 >        Iterator<E> it = iterator();
432 >        if (! it.hasNext())
433              return "[]";
434  
435          StringBuilder sb = new StringBuilder();
436          sb.append('[');
437          for (;;) {
438 <            E e = i.next();
438 >            E e = it.next();
439              sb.append(e == this ? "(this Collection)" : e);
440 <            if (! i.hasNext())
440 >            if (! it.hasNext())
441                  return sb.append(']').toString();
442 <            sb.append(", ");
442 >            sb.append(',').append(' ');
443          }
444      }
445  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines