harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r412931 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util: AbstractCollection.java AbstractList.java AbstractMap.java AbstractSet.java ArrayList.java
Date Fri, 09 Jun 2006 05:17:13 GMT
Author: ndbeyer
Date: Thu Jun  8 22:17:12 2006
New Revision: 412931

URL: http://svn.apache.org/viewvc?rev=412931&view=rev
Log:
Remove raw type references.

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/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/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractCollection.java?rev=412931&r1=412930&r2=412931&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
Thu Jun  8 22:17:12 2006
@@ -72,7 +72,7 @@
 	 * @see java.util.Collection#clear()
 	 */
 	public void clear() {
-		Iterator it = iterator();
+		Iterator<E> it = iterator();
 		while (it.hasNext()) {
 			it.next();
 			it.remove();
@@ -88,7 +88,7 @@
 	 *         false otherwise
 	 */
 	public boolean contains(Object object) {
-		Iterator it = iterator();
+		Iterator<E> it = iterator();
 		if (object != null) {
 			while (it.hasNext())
 				if (object.equals(it.next()))
@@ -110,7 +110,7 @@
 	 *         this Collection, false otherwise
 	 */
 	public boolean containsAll(Collection<?> collection) {
-		Iterator it = collection.iterator();
+		Iterator<?> it = collection.iterator();
 		while (it.hasNext())
 			if (!contains(it.next()))
 				return false;
@@ -148,7 +148,7 @@
 	 *                when removing from this Collection is not supported
 	 */
 	public boolean remove(Object object) {
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		if (object != null) {
 			while (it.hasNext()) {
 				if (object.equals(it.next())) {
@@ -180,7 +180,7 @@
 	 */
 	public boolean removeAll(Collection<?> collection) {
 		boolean result = false;
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		while (it.hasNext()) {
 			if (collection.contains(it.next())) {
 				it.remove();
@@ -203,7 +203,7 @@
 	 */
 	public boolean retainAll(Collection<?> collection) {
 		boolean result = false;
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		while (it.hasNext()) {
 			if (!collection.contains(it.next())) {
 				it.remove();
@@ -227,7 +227,7 @@
 	 */
 	public Object[] toArray() {
 		int size = size(), index = 0;
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		Object[] array = new Object[size];
 		while (index < size)
 			array[index++] = it.next();
@@ -251,13 +251,16 @@
 	 */
 	public <T> T[] toArray(T[] contents) {
 		int size = size(), index = 0;
-		if (size > contents.length)
-			contents = (T[]) Array.newInstance(contents.getClass()
-					.getComponentType(), size);
-		for (E entry: this)
+		if (size > contents.length) {
+            Class<?> ct = contents.getClass().getComponentType();
+			contents = (T[])Array.newInstance(ct, size);
+        }
+		for (E entry: this) {
 			contents[index++] = (T)entry;
-		if (index < contents.length)
+        }
+		if (index < contents.length) {
 			contents[index] = null;
+        }
 		return contents;
 	}
 
@@ -272,7 +275,7 @@
 
 		StringBuilder buffer = new StringBuilder(size() * 16);
 		buffer.append('[');
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		while (it.hasNext()) {
 			Object next = it.next();
 			if (next != this) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java?rev=412931&r1=412930&r2=412931&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
Thu Jun  8 22:17:12 2006
@@ -438,11 +438,11 @@
 		if (this == object)
 			return true;
 		if (object instanceof List) {
-			List list = (List) object;
+			List<?> list = (List) object;
 			if (list.size() != size())
 				return false;
 
-			Iterator it1 = iterator(), it2 = list.iterator();
+			Iterator<?> it1 = iterator(), it2 = list.iterator();
 			while (it1.hasNext()) {
 				Object e1 = it1.next(), e2 = it2.next();
 				if (!(e1 == null ? e2 == null : e1.equals(e2)))
@@ -477,7 +477,7 @@
 	 */
 	public int hashCode() {
 		int result = 1;
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		while (it.hasNext()) {
 			Object object = it.next();
 			result = (31 * result) + (object == null ? 0 : object.hashCode());
@@ -495,7 +495,7 @@
 	 * @return the index of the first occurrence of the object
 	 */
 	public int indexOf(Object object) {
-		ListIterator it = listIterator();
+		ListIterator<?> it = listIterator();
 		if (object != null) {
 			while (it.hasNext())
 				if (object.equals(it.next()))
@@ -531,7 +531,7 @@
 	 * @return the index of the last occurrence of the object
 	 */
 	public int lastIndexOf(Object object) {
-		ListIterator it = listIterator(size());
+		ListIterator<?> it = listIterator(size());
 		if (object != null) {
 			while (it.hasPrevious())
 				if (object.equals(it.previous()))
@@ -609,7 +609,7 @@
 	 *                when <code>start < 0
 	 */
 	protected void removeRange(int start, int end) {
-		Iterator it = listIterator(start);
+		Iterator<?> it = listIterator(start);
 		for (int i = start; i < end; i++) {
 			it.next();
 			it.remove();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractMap.java?rev=412931&r1=412930&r2=412931&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
Thu Jun  8 22:17:12 2006
@@ -56,16 +56,16 @@
      * @return true if <code>key</code> is a key of this Map, false otherwise
      */
     public boolean containsKey(Object key) {
-        Iterator it = entrySet().iterator();
+        Iterator<Map.Entry<K, V>> it = entrySet().iterator();
         if (key != null) {
             while (it.hasNext()) {
-                if (key.equals(((Map.Entry) it.next()).getKey())) {
+                if (key.equals(it.next().getKey())) {
                     return true;
                 }
             }
         } else {
             while (it.hasNext()) {
-                if (((Map.Entry) it.next()).getKey() == null) {
+                if (it.next().getKey() == null) {
                     return true;
                 }
             }
@@ -82,16 +82,16 @@
      *         otherwise
      */
     public boolean containsValue(Object value) {
-        Iterator it = entrySet().iterator();
+        Iterator<Map.Entry<K, V>> it = entrySet().iterator();
         if (value != null) {
             while (it.hasNext()) {
-                if (value.equals(((Map.Entry) it.next()).getValue())) {
+                if (value.equals(it.next().getValue())) {
                     return true;
                 }
             }
         } else {
             while (it.hasNext()) {
-                if (((Map.Entry) it.next()).getValue() == null) {
+                if (it.next().getValue() == null) {
                     return true;
                 }
             }
@@ -104,7 +104,7 @@
      * 
      * @see java.util.Map#entrySet()
      */
-    abstract public Set<Map.Entry<K, V>> entrySet();
+    public abstract Set<Map.Entry<K, V>> entrySet();
 
     /**
      * Compares the specified object to this Map and answer if they are equal.
@@ -123,13 +123,13 @@
             return true;
         }
         if (object instanceof Map) {
-            Map map = (Map) object;
+            Map<?, ?> map = (Map) object;
             if (size() != map.size()) {
                 return false;
             }
 
-            Set objectSet = map.entrySet();
-            Iterator it = entrySet().iterator();
+            Set<?> objectSet = map.entrySet();
+            Iterator<Map.Entry<K, V>> it = entrySet().iterator();
             while (it.hasNext()) {
                 if (!objectSet.contains(it.next())) {
                     return false;
@@ -177,7 +177,7 @@
      */
     public int hashCode() {
         int result = 0;
-        Iterator it = entrySet().iterator();
+        Iterator<Map.Entry<K, V>> it = entrySet().iterator();
         while (it.hasNext()) {
             result += it.next().hashCode();
         }
@@ -338,9 +338,9 @@
 
         StringBuilder buffer = new StringBuilder(size() * 28);
         buffer.append('{');
-        Iterator it = entrySet().iterator();
+        Iterator<Map.Entry<K, V>> it = entrySet().iterator();
         while (it.hasNext()) {
-            Map.Entry entry = (Map.Entry) it.next();
+            Map.Entry<K, V> entry = it.next();
             Object key = entry.getKey();
             if (key != this) {
                 buffer.append(key);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSet.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractSet.java?rev=412931&r1=412930&r2=412931&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
Thu Jun  8 22:17:12 2006
@@ -46,7 +46,7 @@
 		if (this == object)
 			return true;
 		if (object instanceof Set) {
-			Set s = (Set) object;
+			Set<?> s = (Set) object;
 			return size() == s.size() && containsAll(s);
 		}
 		return false;
@@ -62,7 +62,7 @@
 	 */
 	public int hashCode() {
 		int result = 0;
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		while (it.hasNext()) {
 			Object next = it.next();
 			result += next == null ? 0 : next.hashCode();
@@ -84,7 +84,7 @@
 	public boolean removeAll(Collection<?> collection) {
 		boolean result = false;
 		if (size() <= collection.size()) {
-			Iterator it = iterator();
+			Iterator<?> it = iterator();
 			while (it.hasNext()) {
 				if (collection.contains(it.next())) {
 					it.remove();
@@ -92,7 +92,7 @@
 				}
 			}
 		} else {
-			Iterator it = collection.iterator();
+			Iterator<?> it = collection.iterator();
 			while (it.hasNext())
 				result = remove(it.next()) || result;
 		}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/ArrayList.java?rev=412931&r1=412930&r2=412931&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
Thu Jun  8 22:17:12 2006
@@ -36,7 +36,7 @@
 
 	transient private int firstIndex, lastIndex;
 
-	transient private Object[] array;
+	transient private E[] array;
 
 	/**
 	 * Constructs a new instance of ArrayList with zero capacity.
@@ -54,7 +54,7 @@
 	public ArrayList(int capacity) {
 		firstIndex = lastIndex = 0;
 		try {
-			array = new Object[capacity];
+			array = newElementArray(capacity);
 		} catch (NegativeArraySizeException e) {
 			throw new IllegalArgumentException();
 		}
@@ -72,9 +72,15 @@
 	public ArrayList(Collection<? extends E> collection) {
 		int size = collection.size();
 		firstIndex = lastIndex = 0;
-		array = new Object[size + (size / 10)];
+		array = newElementArray(size + (size / 10));
 		addAll(collection);
 	}
+    
+    //TODO Remove comment when annotations are available
+    //@SuppressWarnings("unused")
+    private E[] newElementArray(int size) {
+        return (E[])new Object[size];
+    }
 
 	/**
 	 * Inserts the specified object into this ArrayList at the specified
@@ -184,7 +190,7 @@
         }
 
         if (growSize > 0) {
-            Iterator it = collection.iterator();
+            Iterator<? extends E> it = collection.iterator();
             int index = location + firstIndex;
             int end = index + growSize;
             while (index < end)
@@ -207,7 +213,7 @@
 		if (growSize > 0) {
 			if (lastIndex > array.length - growSize)
 				growAtEnd(growSize);
-			Iterator it = collection.iterator();
+			Iterator<? extends E> it = collection.iterator();
 			int end = lastIndex + growSize;
 			while (lastIndex < end)
 				array[lastIndex++] = it.next();
@@ -242,7 +248,7 @@
 	public Object clone() {
 		try {
 			ArrayList<E> newList = (ArrayList<E>) super.clone();
-			newList.array = (Object[]) array.clone();
+			newList.array = (E[]) array.clone();
 			return newList;
 		} catch (CloneNotSupportedException e) {
 			return null;
@@ -321,7 +327,7 @@
 				increment = required;
 			if (increment < 12)
 				increment = 12;
-			Object[] newArray = new Object[size + increment];
+			E[] newArray = newElementArray(size + increment);
 			if (size > 0)
 				System.arraycopy(array, firstIndex, newArray, firstIndex, size);
 			array = newArray;
@@ -346,7 +352,7 @@
 				increment = required;
 			if (increment < 12)
 				increment = 12;
-			Object[] newArray = new Object[size + increment];
+			E[] newArray = newElementArray(size + increment);
 			if (size > 0)
 				System.arraycopy(array, firstIndex, newArray, newArray.length
 						- lastIndex, size);
@@ -362,7 +368,7 @@
 			increment = required;
 		if (increment < 12)
 			increment = 12;
-		Object[] newArray = new Object[size + increment];
+		E[] newArray = newElementArray(size + increment);
 		if (location < size / 2) {
 			int newFirst = newArray.length - (size + required);
 			System.arraycopy(array, location, newArray, location + increment,
@@ -569,9 +575,10 @@
 	 */
 	public <T> T[] toArray(T[] contents) {
 		int size = size();
-		if (size > contents.length)
-			contents = (T[]) Array.newInstance(contents.getClass()
-					.getComponentType(), size);
+		if (size > contents.length) {
+            Class<?> ct = contents.getClass().getComponentType();
+			contents = (T[]) Array.newInstance(ct, size);
+        }
 		System.arraycopy(array, firstIndex, contents, 0, size);
 		if (size < contents.length)
 			contents[size] = null;
@@ -585,7 +592,7 @@
 	 */
 	public void trimToSize() {
 		int size = size();
-		Object[] newArray = new Object[size];
+		E[] newArray = newElementArray(size);
 		System.arraycopy(array, firstIndex, newArray, 0, size);
 		array = newArray;
 		firstIndex = 0;
@@ -600,7 +607,7 @@
 		fields.put("size", size()); //$NON-NLS-1$
 		stream.writeFields();
 		stream.writeInt(array.length);
-		Iterator it = iterator();
+		Iterator<?> it = iterator();
 		while (it.hasNext())
 			stream.writeObject(it.next());
 	}
@@ -609,8 +616,8 @@
 			ClassNotFoundException {
 		ObjectInputStream.GetField fields = stream.readFields();
 		lastIndex = fields.get("size", 0); //$NON-NLS-1$
-		array = new Object[stream.readInt()];
+		array = newElementArray(stream.readInt());
 		for (int i = 0; i < lastIndex; i++)
-			array[i] = stream.readObject();
+			array[i] = (E)stream.readObject();
 	}
 }



Mime
View raw message