--- jsr166/src/main/java/util/AbstractCollection.java 2007/05/20 07:54:01 1.11 +++ jsr166/src/main/java/util/AbstractCollection.java 2008/05/18 23:47:55 1.12 @@ -84,7 +84,7 @@ public abstract class AbstractCollection *

This implementation returns size() == 0. */ public boolean isEmpty() { - return size() == 0; + return size() == 0; } /** @@ -97,17 +97,17 @@ public abstract class AbstractCollection * @throws NullPointerException {@inheritDoc} */ public boolean contains(Object o) { - Iterator e = iterator(); - if (o==null) { - while (e.hasNext()) - if (e.next()==null) - return true; - } else { - while (e.hasNext()) - if (o.equals(e.next())) - return true; - } - return false; + Iterator e = iterator(); + if (o==null) { + while (e.hasNext()) + if (e.next()==null) + return true; + } else { + while (e.hasNext()) + if (o.equals(e.next())) + return true; + } + return false; } /** @@ -134,14 +134,14 @@ public abstract class AbstractCollection */ public Object[] toArray() { // Estimate size of array; be prepared to see more or fewer elements - Object[] r = new Object[size()]; + Object[] r = new Object[size()]; Iterator it = iterator(); - for (int i = 0; i < r.length; i++) { - if (! it.hasNext()) // fewer elements than expected - return Arrays.copyOf(r, i); - r[i] = it.next(); - } - return it.hasNext() ? finishToArray(r, it) : r; + for (int i = 0; i < r.length; i++) { + if (! it.hasNext()) // fewer elements than expected + return Arrays.copyOf(r, i); + r[i] = it.next(); + } + return it.hasNext() ? finishToArray(r, it) : r; } /** @@ -179,16 +179,16 @@ public abstract class AbstractCollection .newInstance(a.getClass().getComponentType(), size); Iterator it = iterator(); - for (int i = 0; i < r.length; i++) { - if (! it.hasNext()) { // fewer elements than expected - if (a != r) - return Arrays.copyOf(r, i); - r[i] = null; // null-terminate - return r; - } - r[i] = (T)it.next(); - } - return it.hasNext() ? finishToArray(r, it) : r; + for (int i = 0; i < r.length; i++) { + if (! it.hasNext()) { // fewer elements than expected + if (a != r) + return Arrays.copyOf(r, i); + r[i] = null; // null-terminate + return r; + } + r[i] = (T)it.next(); + } + return it.hasNext() ? finishToArray(r, it) : r; } /** @@ -202,20 +202,20 @@ public abstract class AbstractCollection * further elements returned by the iterator, trimmed to size */ private static T[] finishToArray(T[] r, Iterator it) { - int i = r.length; + int i = r.length; while (it.hasNext()) { int cap = r.length; if (i == cap) { int newCap = ((cap / 2) + 1) * 3; if (newCap <= cap) { // integer overflow - if (cap == Integer.MAX_VALUE) - throw new OutOfMemoryError - ("Required array size too large"); - newCap = Integer.MAX_VALUE; - } - r = Arrays.copyOf(r, newCap); - } - r[i++] = (T)it.next(); + if (cap == Integer.MAX_VALUE) + throw new OutOfMemoryError + ("Required array size too large"); + newCap = Integer.MAX_VALUE; + } + r = Arrays.copyOf(r, newCap); + } + r[i++] = (T)it.next(); } // trim if overallocated return (i == r.length) ? r : Arrays.copyOf(r, i); @@ -236,7 +236,7 @@ public abstract class AbstractCollection * @throws IllegalStateException {@inheritDoc} */ public boolean add(E e) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } /** @@ -256,23 +256,23 @@ public abstract class AbstractCollection * @throws NullPointerException {@inheritDoc} */ public boolean remove(Object o) { - Iterator e = iterator(); - if (o==null) { - while (e.hasNext()) { - if (e.next()==null) { - e.remove(); - return true; - } - } - } else { - while (e.hasNext()) { - if (o.equals(e.next())) { - e.remove(); - return true; - } - } - } - return false; + Iterator e = iterator(); + if (o==null) { + while (e.hasNext()) { + if (e.next()==null) { + e.remove(); + return true; + } + } + } else { + while (e.hasNext()) { + if (o.equals(e.next())) { + e.remove(); + return true; + } + } + } + return false; } @@ -291,11 +291,11 @@ public abstract class AbstractCollection * @see #contains(Object) */ public boolean containsAll(Collection c) { - Iterator e = c.iterator(); - while (e.hasNext()) - if (!contains(e.next())) - return false; - return true; + Iterator e = c.iterator(); + while (e.hasNext()) + if (!contains(e.next())) + return false; + return true; } /** @@ -317,13 +317,13 @@ public abstract class AbstractCollection * @see #add(Object) */ public boolean addAll(Collection c) { - boolean modified = false; - Iterator e = c.iterator(); - while (e.hasNext()) { - if (add(e.next())) - modified = true; - } - return modified; + boolean modified = false; + Iterator e = c.iterator(); + while (e.hasNext()) { + if (add(e.next())) + modified = true; + } + return modified; } /** @@ -348,15 +348,15 @@ public abstract class AbstractCollection * @see #contains(Object) */ public boolean removeAll(Collection c) { - boolean modified = false; - Iterator e = iterator(); - while (e.hasNext()) { - if (c.contains(e.next())) { - e.remove(); - modified = true; - } - } - return modified; + boolean modified = false; + Iterator e = iterator(); + while (e.hasNext()) { + if (c.contains(e.next())) { + e.remove(); + modified = true; + } + } + return modified; } /** @@ -381,15 +381,15 @@ public abstract class AbstractCollection * @see #contains(Object) */ public boolean retainAll(Collection c) { - boolean modified = false; - Iterator e = iterator(); - while (e.hasNext()) { - if (!c.contains(e.next())) { - e.remove(); - modified = true; - } - } - return modified; + boolean modified = false; + Iterator e = iterator(); + while (e.hasNext()) { + if (!c.contains(e.next())) { + e.remove(); + modified = true; + } + } + return modified; } /** @@ -408,11 +408,11 @@ public abstract class AbstractCollection * @throws UnsupportedOperationException {@inheritDoc} */ public void clear() { - Iterator e = iterator(); - while (e.hasNext()) { - e.next(); - e.remove(); - } + Iterator e = iterator(); + while (e.hasNext()) { + e.next(); + e.remove(); + } } @@ -430,18 +430,18 @@ public abstract class AbstractCollection */ public String toString() { Iterator i = iterator(); - if (! i.hasNext()) - return "[]"; + if (! i.hasNext()) + return "[]"; - StringBuilder sb = new StringBuilder(); - sb.append('['); - for (;;) { - E e = i.next(); - sb.append(e == this ? "(this Collection)" : e); - if (! i.hasNext()) - return sb.append(']').toString(); - sb.append(", "); - } + StringBuilder sb = new StringBuilder(); + sb.append('['); + for (;;) { + E e = i.next(); + sb.append(e == this ? "(this Collection)" : e); + if (! i.hasNext()) + return sb.append(']').toString(); + sb.append(", "); + } } }