src/share/classes/java/util/AbstractCollection.java

Print this page

        

@@ -94,18 +94,18 @@
      *
      * @throws ClassCastException   {@inheritDoc}
      * @throws NullPointerException {@inheritDoc}
      */
     public boolean contains(Object o) {
-        Iterator<E> e = iterator();
+        Iterator<E> it = iterator();
         if (o==null) {
-            while (e.hasNext())
-                if (e.next()==null)
+            while (it.hasNext())
+                if (it.next()==null)
                     return true;
         } else {
-            while (e.hasNext())
-                if (o.equals(e.next()))
+            while (it.hasNext())
+                if (o.equals(it.next()))
                     return true;
         }
         return false;
     }
 

@@ -267,22 +267,22 @@
      * @throws UnsupportedOperationException {@inheritDoc}
      * @throws ClassCastException            {@inheritDoc}
      * @throws NullPointerException          {@inheritDoc}
      */
     public boolean remove(Object o) {
-        Iterator<E> e = iterator();
+        Iterator<E> it = iterator();
         if (o==null) {
-            while (e.hasNext()) {
-                if (e.next()==null) {
-                    e.remove();
+            while (it.hasNext()) {
+                if (it.next()==null) {
+                    it.remove();
                     return true;
                 }
             }
         } else {
-            while (e.hasNext()) {
-                if (o.equals(e.next())) {
-                    e.remove();
+            while (it.hasNext()) {
+                if (o.equals(it.next())) {
+                    it.remove();
                     return true;
                 }
             }
         }
         return false;

@@ -302,13 +302,12 @@
      * @throws ClassCastException            {@inheritDoc}
      * @throws NullPointerException          {@inheritDoc}
      * @see #contains(Object)
      */
     public boolean containsAll(Collection<?> c) {
-        Iterator<?> e = c.iterator();
-        while (e.hasNext())
-            if (!contains(e.next()))
+        for (Object e : c)
+            if (!contains(e))
                 return false;
         return true;
     }
 
     /**

@@ -329,15 +328,13 @@
      *
      * @see #add(Object)
      */
     public boolean addAll(Collection<? extends E> c) {
         boolean modified = false;
-        Iterator<? extends E> e = c.iterator();
-        while (e.hasNext()) {
-            if (add(e.next()))
+        for (E e : c)
+            if (add(e))
                 modified = true;
-        }
         return modified;
     }
 
     /**
      * {@inheritDoc}

@@ -360,14 +357,14 @@
      * @see #remove(Object)
      * @see #contains(Object)
      */
     public boolean removeAll(Collection<?> c) {
         boolean modified = false;
-        Iterator<?> e = iterator();
-        while (e.hasNext()) {
-            if (c.contains(e.next())) {
-                e.remove();
+        Iterator<?> it = iterator();
+        while (it.hasNext()) {
+            if (c.contains(it.next())) {
+                it.remove();
                 modified = true;
             }
         }
         return modified;
     }

@@ -393,14 +390,14 @@
      * @see #remove(Object)
      * @see #contains(Object)
      */
     public boolean retainAll(Collection<?> c) {
         boolean modified = false;
-        Iterator<E> e = iterator();
-        while (e.hasNext()) {
-            if (!c.contains(e.next())) {
-                e.remove();
+        Iterator<E> it = iterator();
+        while (it.hasNext()) {
+            if (!c.contains(it.next())) {
+                it.remove();
                 modified = true;
             }
         }
         return modified;
     }

@@ -419,14 +416,14 @@
      * <tt>remove</tt> method and this collection is non-empty.
      *
      * @throws UnsupportedOperationException {@inheritDoc}
      */
     public void clear() {
-        Iterator<E> e = iterator();
-        while (e.hasNext()) {
-            e.next();
-            e.remove();
+        Iterator<E> it = iterator();
+        while (it.hasNext()) {
+            it.next();
+            it.remove();
         }
     }
 
 
     //  String conversion

@@ -440,21 +437,21 @@
      * by {@link String#valueOf(Object)}.
      *
      * @return a string representation of this collection
      */
     public String toString() {
-        Iterator<E> i = iterator();
-        if (! i.hasNext())
+        Iterator<E> it = iterator();
+        if (! it.hasNext())
             return "[]";
 
         StringBuilder sb = new StringBuilder();
         sb.append('[');
         for (;;) {
-            E e = i.next();
+            E e = it.next();
             sb.append(e == this ? "(this Collection)" : e);
-            if (! i.hasNext())
+            if (! it.hasNext())
                 return sb.append(']').toString();
-            sb.append(", ");
+            sb.append(',').append(' ');
         }
     }
 
 }