Index: /luni/src/main/java/java/util/ArrayList.java =================================================================== --- /luni/src/main/java/java/util/ArrayList.java (revision 406132) +++ /luni/src/main/java/java/util/ArrayList.java (working copy) @@ -24,9 +24,10 @@ import java.lang.reflect.Array; /** - * ArrayList is an implemenation of List, backed by an array. All optional + * ArrayList is an implementation of List, backed by an array. All optional * operations are supported, adding, removing, and replacing. The elements can * be any objects. + * @since 1.2 */ public class ArrayList extends AbstractList implements List, Cloneable, Serializable, RandomAccess { @@ -38,7 +39,7 @@ transient private Object[] array; /** - * Contructs a new instance of ArrayList with zero capacity. + * Constructs a new instance of ArrayList with zero capacity. */ public ArrayList() { this(0); @@ -61,7 +62,7 @@ /** * Constructs a new instance of ArrayList containing the elements in the - * specified collection. The ArrayList will have an initial cacacity which + * specified collection. The ArrayList will have an initial capacity which * is 110% of the size of the collection. The order of the elements in this * ArrayList is the order they are returned by the collection iterator. * @@ -241,7 +242,7 @@ */ public Object clone() { try { - ArrayList newList = (ArrayList) super.clone(); + ArrayList newList = (ArrayList) super.clone(); newList.array = (Object[]) array.clone(); return newList; } catch (CloneNotSupportedException e) { Index: /luni/src/main/java/java/util/AbstractCollection.java =================================================================== --- /luni/src/main/java/java/util/AbstractCollection.java (revision 406132) +++ /luni/src/main/java/java/util/AbstractCollection.java (working copy) @@ -20,10 +20,10 @@ /** * AbstractCollection is an abstract implementation of the Collection interface. - * This implemetation does not support adding. A subclass must implement the + * This implementation does not support adding. A subclass must implement the * abstract methods iterator() and size(). + * @since 1.2 */ - public abstract class AbstractCollection implements Collection { /** @@ -134,7 +134,7 @@ * * @see Iterator */ - public abstract Iterator iterator(); + public abstract Iterator iterator(); /** * Removes the first occurrence of the specified object from this @@ -251,12 +251,12 @@ */ public T[] toArray(T[] contents) { int size = size(), index = 0; - Iterator it = iterator(); + Iterator it = iterator(); if (size > contents.length) contents = (T[]) Array.newInstance(contents.getClass() .getComponentType(), size); while (index < size) - contents[index++] = it.next(); + contents[index++] = (T)it.next(); if (index < contents.length) contents[index] = null; return contents; @@ -271,7 +271,7 @@ if (isEmpty()) return "[]"; //$NON-NLS-1$ - StringBuffer buffer = new StringBuffer(size() * 16); + StringBuilder buffer = new StringBuilder(size() * 16); buffer.append('['); Iterator it = iterator(); while (it.hasNext()) { @@ -281,11 +281,10 @@ } else { buffer.append("(this Collection)"); } - buffer.append(", "); + if(it.hasNext()) { + buffer.append(", "); + } } - // Remove the trailing ", " - if (buffer.length() > 1) - buffer.setLength(buffer.length() - 2); buffer.append(']'); return buffer.toString(); } Index: /luni/src/main/java/java/util/AbstractSequentialList.java =================================================================== --- /luni/src/main/java/java/util/AbstractSequentialList.java (revision 406132) +++ /luni/src/main/java/java/util/AbstractSequentialList.java (working copy) @@ -20,8 +20,9 @@ * AbstractSequentialList is an abstract implementation of the List interface. * This implementation does not support adding. A subclass must implement the * abstract method listIterator(). + * @since 1.2 */ -public abstract class AbstractSequentialList extends AbstractList { +public abstract class AbstractSequentialList extends AbstractList { /** * Constructs a new instance of this AbstractSequentialList. @@ -54,7 +55,7 @@ * when the object is null and this List does not support * null elements */ - public void add(int location, Object object) { + public void add(int location, E object) { listIterator(location).add(object); } @@ -78,9 +79,9 @@ * @exception IndexOutOfBoundsException * when location < 0 || >= size() */ - public boolean addAll(int location, Collection collection) { - ListIterator it = listIterator(location); - Iterator colIt = collection.iterator(); + public boolean addAll(int location, Collection collection) { + ListIterator it = listIterator(location); + Iterator colIt = collection.iterator(); int next = it.nextIndex(); while (colIt.hasNext()) { it.add(colIt.next()); @@ -99,7 +100,7 @@ * @exception IndexOutOfBoundsException * when location < 0 || >= size() */ - public Object get(int location) { + public E get(int location) { try { return listIterator(location).next(); } catch (NoSuchElementException e) { @@ -115,7 +116,7 @@ * * @see Iterator */ - public Iterator iterator() { + public Iterator iterator() { return listIterator(0); } @@ -133,7 +134,7 @@ * * @see ListIterator */ - public abstract ListIterator listIterator(int location); + public abstract ListIterator listIterator(int location); /** * Removes the object at the specified location from this List. @@ -147,10 +148,10 @@ * @exception IndexOutOfBoundsException * when location < 0 || >= size() */ - public Object remove(int location) { + public E remove(int location) { try { - ListIterator it = listIterator(location); - Object result = it.next(); + ListIterator it = listIterator(location); + E result = it.next(); it.remove(); return result; } catch (NoSuchElementException e) { @@ -177,9 +178,9 @@ * @exception IndexOutOfBoundsException * when location < 0 || >= size() */ - public Object set(int location, Object object) { - ListIterator it = listIterator(location); - Object result = it.next(); + public E set(int location, E object) { + ListIterator it = listIterator(location); + E result = it.next(); it.set(object); return result; } Index: /luni/src/main/java/java/util/AbstractList.java =================================================================== --- /luni/src/main/java/java/util/AbstractList.java (revision 406132) +++ /luni/src/main/java/java/util/AbstractList.java (working copy) @@ -21,6 +21,7 @@ * for a backing store which supports random access. This implementation does * not support adding or replacing. A subclass must implement the abstract * methods get() and size(). + * @since 1.2 */ public abstract class AbstractList extends AbstractCollection implements List { @@ -131,27 +132,27 @@ } } - private static final class SubAbstractListRandomAccess extends - SubAbstractList implements RandomAccess { - SubAbstractListRandomAccess(AbstractList list, int start, int end) { + private static final class SubAbstractListRandomAccess extends + SubAbstractList implements RandomAccess { + SubAbstractListRandomAccess(AbstractList list, int start, int end) { super(list, start, end); } } - private static class SubAbstractList extends AbstractList { - private final AbstractList fullList; + private static class SubAbstractList extends AbstractList { + private final AbstractList fullList; private int offset, size; - private static final class SubAbstractListIterator implements - ListIterator { - private final SubAbstractList subList; + private static final class SubAbstractListIterator implements + ListIterator { + private final SubAbstractList subList; - private final ListIterator iterator; + private final ListIterator iterator; private int start, end; - SubAbstractListIterator(ListIterator it, SubAbstractList list, + SubAbstractListIterator(ListIterator it, SubAbstractList list, int offset, int length) { iterator = it; subList = list; @@ -159,7 +160,7 @@ end = start + length; } - public void add(Object object) { + public void add(E object) { iterator.add(object); subList.sizeChanged(true); end++; @@ -173,7 +174,7 @@ return iterator.previousIndex() >= start; } - public Object next() { + public E next() { if (iterator.nextIndex() < end) return iterator.next(); throw new NoSuchElementException(); @@ -183,7 +184,7 @@ return iterator.nextIndex() - start; } - public Object previous() { + public E previous() { if (iterator.previousIndex() >= start) return iterator.previous(); throw new NoSuchElementException(); @@ -202,19 +203,19 @@ end--; } - public void set(Object object) { + public void set(E object) { iterator.set(object); } } - SubAbstractList(AbstractList list, int start, int end) { + SubAbstractList(AbstractList list, int start, int end) { fullList = list; modCount = fullList.modCount; offset = start; size = end - start; } - public void add(int location, Object object) { + public void add(int location, E object) { if (modCount == fullList.modCount) { if (0 <= location && location <= size) { fullList.add(location + offset, object); @@ -226,7 +227,7 @@ throw new ConcurrentModificationException(); } - public boolean addAll(int location, Collection collection) { + public boolean addAll(int location, Collection collection) { if (modCount == fullList.modCount) { if (0 <= location && location <= size) { boolean result = fullList.addAll(location + offset, @@ -242,7 +243,7 @@ throw new ConcurrentModificationException(); } - public boolean addAll(Collection collection) { + public boolean addAll(Collection collection) { if (modCount == fullList.modCount) { boolean result = fullList.addAll(offset + size, collection); if (result) { @@ -254,7 +255,7 @@ throw new ConcurrentModificationException(); } - public Object get(int location) { + public E get(int location) { if (modCount == fullList.modCount) { if (0 <= location && location < size) return fullList.get(location + offset); @@ -263,14 +264,14 @@ throw new ConcurrentModificationException(); } - public Iterator iterator() { + public Iterator iterator() { return listIterator(0); } - public ListIterator listIterator(int location) { + public ListIterator listIterator(int location) { if (modCount == fullList.modCount) { if (0 <= location && location <= size) - return new SubAbstractListIterator(fullList + return new SubAbstractListIterator(fullList .listIterator(location + offset), this, offset, size); throw new IndexOutOfBoundsException(); @@ -278,10 +279,10 @@ throw new ConcurrentModificationException(); } - public Object remove(int location) { + public E remove(int location) { if (modCount == fullList.modCount) { if (0 <= location && location < size) { - Object result = fullList.remove(location + offset); + E result = fullList.remove(location + offset); size--; modCount = fullList.modCount; return result; @@ -302,7 +303,7 @@ } } - public Object set(int location, Object object) { + public E set(int location, E object) { if (modCount == fullList.modCount) { if (0 <= location && location < size) return fullList.set(location + offset, object); @@ -648,8 +649,8 @@ if (0 <= start && end <= size()) { if (start <= end) { if (this instanceof RandomAccess) - return new SubAbstractListRandomAccess(this, start, end); - return new SubAbstractList(this, start, end); + return new SubAbstractListRandomAccess(this, start, end); + return new SubAbstractList(this, start, end); } throw new IllegalArgumentException(); } Index: /luni/src/main/java/java/util/AbstractMap.java =================================================================== --- /luni/src/main/java/java/util/AbstractMap.java (revision 406132) +++ /luni/src/main/java/java/util/AbstractMap.java (working copy) @@ -16,17 +16,18 @@ package java.util; /** - * AbstractMap is an abstract implementation of the Map iterface. This - * implemenation does not support adding. A subclass must implement the abstract + * AbstractMap is an abstract implementation of the Map interface. This + * Implementation does not support adding. A subclass must implement the abstract * method entrySet(). + * @since 1.2 */ public abstract class AbstractMap implements Map { // Lazily initialized key set. - Set keySet = null; + Set keySet; - Collection valuesCollection = null; - + Collection valuesCollection; + /** * Constructs a new instance of this AbstractMap. */ @@ -196,7 +197,7 @@ /** * Answers a Set of the keys contained in this Map. The set is backed by - * this Map so changes to one are relected by the other. The set does not + * this Map so changes to one are reflected by the other. The set does not * support adding. * * @return a Set of the keys @@ -335,7 +336,7 @@ return "{}"; //$NON-NLS-1$ } - StringBuffer buffer = new StringBuffer(size() * 28); + StringBuilder buffer = new StringBuilder(size() * 28); buffer.append('{'); Iterator it = entrySet().iterator(); while (it.hasNext()) { @@ -353,12 +354,10 @@ } else { buffer.append("(this Map)"); } - buffer.append(", "); + if(it.hasNext()) { + buffer.append(", "); + } } - // Remove the trailing ", " - if (buffer.length() > 1) { - buffer.setLength(buffer.length() - 2); - } buffer.append('}'); return buffer.toString(); } @@ -370,7 +369,7 @@ */ public Collection values() { if (valuesCollection == null) { - valuesCollection = new AbstractCollection() { + valuesCollection = new AbstractCollection() { public int size() { return AbstractMap.this.size(); } @@ -379,16 +378,16 @@ return containsValue(object); } - public Iterator iterator() { - return new Iterator() { - Iterator setIterator = entrySet().iterator(); + public Iterator iterator() { + return new Iterator() { + Iterator> setIterator = entrySet().iterator(); public boolean hasNext() { return setIterator.hasNext(); } - public Object next() { - return ((Map.Entry) setIterator.next()).getValue(); + public V next() { + return setIterator.next().getValue(); } public void remove() { Index: /luni/src/main/java/java/util/AbstractSet.java =================================================================== --- /luni/src/main/java/java/util/AbstractSet.java (revision 406132) +++ /luni/src/main/java/java/util/AbstractSet.java (working copy) @@ -17,9 +17,10 @@ /** - * AbstractSet is an abstract implementation of the Set iterface. This - * implemenation does not support adding. A subclass must implement the abstract + * AbstractSet is an abstract implementation of the Set interface. This + * Implementation does not support adding. A subclass must implement the abstract * methods iterator() and size(). + * @since 1.2 */ public abstract class AbstractSet extends AbstractCollection implements Set {