harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r406611 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util: AbstractCollection.java AbstractList.java AbstractMap.java AbstractSequentialList.java AbstractSet.java ArrayList.java
Date Mon, 15 May 2006 10:52:08 GMT
Author: smishura
Date: Mon May 15 03:52:04 2006
New Revision: 406611

URL: http://svn.apache.org/viewcvs?rev=406611&view=rev
Log:
Apply updated patch for HARMONY-461 ([classlib][luni] Collections classes cleanup, generification,
etc)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractCollection.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSequentialList.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSet.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractCollection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractCollection.java?rev=406611&r1=406610&r2=406611&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractCollection.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractCollection.java
Mon May 15 03:52:04 2006
@@ -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<E> implements Collection<E> {
 
 	/**
@@ -134,7 +134,7 @@
 	 * 
 	 * @see Iterator
 	 */
-	public abstract Iterator iterator();
+	public abstract Iterator<E> iterator();
 
 	/**
 	 * Removes the first occurrence of the specified object from this
@@ -251,12 +251,11 @@
 	 */
 	public <T> T[] toArray(T[] contents) {
 		int size = size(), index = 0;
-		Iterator<T> it = iterator();
 		if (size > contents.length)
 			contents = (T[]) Array.newInstance(contents.getClass()
 					.getComponentType(), size);
-		while (index < size)
-			contents[index++] = it.next();
+		for (E entry: this)
+			contents[index++] = (T)entry;
 		if (index < contents.length)
 			contents[index] = null;
 		return contents;
@@ -271,7 +270,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 +280,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();
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java?rev=406611&r1=406610&r2=406611&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
Mon May 15 03:52:04 2006
@@ -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<E> extends AbstractCollection<E> implements
List<E> {
 
@@ -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<E> extends
+			SubAbstractList<E> implements RandomAccess {
+		SubAbstractListRandomAccess(AbstractList<E> list, int start, int end) {
 			super(list, start, end);
 		}
 	}
 
-	private static class SubAbstractList extends AbstractList {
-		private final AbstractList fullList;
+	private static class SubAbstractList<E> extends AbstractList<E> {
+		private final AbstractList<E> fullList;
 
 		private int offset, size;
 
-		private static final class SubAbstractListIterator implements
-				ListIterator {
-			private final SubAbstractList subList;
+		private static final class SubAbstractListIterator<E> implements
+				ListIterator<E> {
+			private final SubAbstractList<E> subList;
 
-			private final ListIterator iterator;
+			private final ListIterator<E> iterator;
 
 			private int start, end;
 
-			SubAbstractListIterator(ListIterator it, SubAbstractList list,
+			SubAbstractListIterator(ListIterator<E> it, SubAbstractList<E> 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<E> 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<? extends E> 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<? extends E> 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<E> iterator() {
 			return listIterator(0);
 		}
 
-		public ListIterator listIterator(int location) {
+		public ListIterator<E> listIterator(int location) {
 			if (modCount == fullList.modCount) {
 				if (0 <= location && location <= size)
-					return new SubAbstractListIterator(fullList
+					return new SubAbstractListIterator<E>(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<E>(this, start, end);
+				return new SubAbstractList<E>(this, start, end);
 			}
 			throw new IllegalArgumentException();
 		}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java?rev=406611&r1=406610&r2=406611&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
Mon May 15 03:52:04 2006
@@ -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<K, V> implements Map<K, V> {
 
     // Lazily initialized key set.
-    Set<K> keySet = null;
-
-    Collection valuesCollection = null;
+    Set<K> keySet;
 
+    Collection<V> 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,11 +354,9 @@
             } else {
                 buffer.append("(this Map)");
             }
-            buffer.append(", ");
-        }
-        // Remove the trailing ", "
-        if (buffer.length() > 1) {
-            buffer.setLength(buffer.length() - 2);
+            if(it.hasNext()) {
+                buffer.append(", ");
+            }
         }
         buffer.append('}');
         return buffer.toString();
@@ -370,7 +369,7 @@
      */
     public Collection<V> values() {
         if (valuesCollection == null) {
-            valuesCollection = new AbstractCollection() {
+            valuesCollection = new AbstractCollection<V>() {
                 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<V> iterator() {
+                    return new Iterator<V>() {
+                        Iterator<Map.Entry<K, V>> 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() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSequentialList.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSequentialList.java?rev=406611&r1=406610&r2=406611&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSequentialList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSequentialList.java
Mon May 15 03:52:04 2006
@@ -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<E> extends AbstractList<E> {
 
 	/**
 	 * 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 <code>location < 0 || >= size()</code>
 	 */
-	public boolean addAll(int location, Collection collection) {
-		ListIterator it = listIterator(location);
-		Iterator colIt = collection.iterator();
+	public boolean addAll(int location, Collection<? extends E> collection) {
+		ListIterator<E> it = listIterator(location);
+		Iterator<? extends E> colIt = collection.iterator();
 		int next = it.nextIndex();
 		while (colIt.hasNext()) {
 			it.add(colIt.next());
@@ -99,7 +100,7 @@
 	 * @exception IndexOutOfBoundsException
 	 *                when <code>location < 0 || >= size()</code>
 	 */
-	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<E> iterator() {
 		return listIterator(0);
 	}
 
@@ -133,7 +134,7 @@
 	 * 
 	 * @see ListIterator
 	 */
-	public abstract ListIterator listIterator(int location);
+	public abstract ListIterator<E> listIterator(int location);
 
 	/**
 	 * Removes the object at the specified location from this List.
@@ -147,10 +148,10 @@
 	 * @exception IndexOutOfBoundsException
 	 *                when <code>location < 0 || >= size()</code>
 	 */
-	public Object remove(int location) {
+	public E remove(int location) {
 		try {
-			ListIterator it = listIterator(location);
-			Object result = it.next();
+			ListIterator<E> it = listIterator(location);
+			E result = it.next();
 			it.remove();
 			return result;
 		} catch (NoSuchElementException e) {
@@ -177,9 +178,9 @@
 	 * @exception IndexOutOfBoundsException
 	 *                when <code>location < 0 || >= size()</code>
 	 */
-	public Object set(int location, Object object) {
-		ListIterator it = listIterator(location);
-		Object result = it.next();
+	public E set(int location, E object) {
+		ListIterator<E> it = listIterator(location);
+		E result = it.next();
 		it.set(object);
 		return result;
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSet.java?rev=406611&r1=406610&r2=406611&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSet.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSet.java
Mon May 15 03:52:04 2006
@@ -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<E> extends AbstractCollection<E> implements
Set<E> {
 	

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java?rev=406611&r1=406610&r2=406611&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
Mon May 15 03:52:04 2006
@@ -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<E> extends AbstractList<E> implements List<E>, 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<E> newList = (ArrayList<E>) super.clone();
 			newList.array = (Object[]) array.clone();
 			return newList;
 		} catch (CloneNotSupportedException e) {



Mime
View raw message