You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2009/09/15 07:42:45 UTC

svn commit: r815004 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/comparators/ java/org/apache/commons/collections/iterators/ test/org/apache/commons/collections/comparators/ test/org/apache/commons/collections/iterato...

Author: bayard
Date: Tue Sep 15 05:42:44 2009
New Revision: 815004

URL: http://svn.apache.org/viewvc?rev=815004&view=rev
Log:
Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified in r738956.

Tabs also cleaned up in r814044.


Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/NullComparator.java
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayIterator.java
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/SingletonIterator.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestNullComparator.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTreeList.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/NullComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/NullComparator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/NullComparator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/comparators/NullComparator.java Tue Sep 15 05:42:44 2009
@@ -19,6 +19,8 @@
 import java.io.Serializable;
 import java.util.Comparator;
 
+import org.apache.commons.collections.ComparatorUtils;
+
 /**
  * A Comparator that will compare nulls to be either lower or higher than
  * other objects.
@@ -28,7 +30,7 @@
  *
  * @author Michael A. Smith
  */
-public class NullComparator implements Comparator, Serializable {
+public class NullComparator<E> implements Comparator<E>, Serializable {
 
     /** Serialization version. */
     private static final long serialVersionUID = -5820772575483504339L;
@@ -36,7 +38,7 @@
     /**
      *  The comparator to use when comparing two non-<code>null</code> objects.
      **/
-    private Comparator nonNullComparator;
+    private Comparator<E> nonNullComparator;
 
     /**
      *  Specifies whether a <code>null</code> are compared as higher than
@@ -51,8 +53,9 @@
      *  non-<code>null</code> objects, the {@link ComparableComparator} is
      *  used.
      **/
+    @SuppressWarnings("unchecked")
     public NullComparator() {
-        this(ComparableComparator.getInstance(), true);
+        this(ComparatorUtils.NATURAL_COMPARATOR, true);
     }
 
     /**
@@ -68,7 +71,7 @@
      *  @exception NullPointerException if <code>nonNullComparator</code> is
      *  <code>null</code>
      **/
-    public NullComparator(Comparator nonNullComparator) {
+    public NullComparator(Comparator<E> nonNullComparator) {
         this(nonNullComparator, true);
     }
 
@@ -84,8 +87,9 @@
      *  that <code>null</code> should be compared as lower than a
      *  non-<code>null</code> object.
      **/
+    @SuppressWarnings("unchecked")
     public NullComparator(boolean nullsAreHigh) {
-        this(ComparableComparator.getInstance(), nullsAreHigh);
+        this(ComparatorUtils.NATURAL_COMPARATOR, nullsAreHigh);
     }
     
     /**
@@ -107,11 +111,11 @@
      *  @exception NullPointerException if <code>nonNullComparator</code> is
      *  <code>null</code>
      **/
-    public NullComparator(Comparator nonNullComparator, boolean nullsAreHigh) {
+    public NullComparator(Comparator<E> nonNullComparator, boolean nullsAreHigh) {
         this.nonNullComparator = nonNullComparator;
         this.nullsAreHigh = nullsAreHigh;
         
-        if(nonNullComparator == null) {
+        if (nonNullComparator == null) {
             throw new NullPointerException("null nonNullComparator");
         }
     }
@@ -133,7 +137,7 @@
      *  "higher" than (greater than, after, etc.) <code>o2</code>; or
      *  <code>0</code> if <code>o1</code> and <code>o2</code> are equal.
      **/
-    public int compare(Object o1, Object o2) {
+    public int compare(E o1, E o2) {
         if(o1 == o2) { return 0; }
         if(o1 == null) { return (this.nullsAreHigh ? 1 : -1); }
         if(o2 == null) { return (this.nullsAreHigh ? -1 : 1); }
@@ -167,8 +171,8 @@
         if(obj == this) { return true; }
         if(!obj.getClass().equals(this.getClass())) { return false; }
 
-        NullComparator other = (NullComparator)obj;
-    
+        NullComparator<?> other = (NullComparator<?>) obj;
+
         return ((this.nullsAreHigh == other.nullsAreHigh) &&
                 (this.nonNullComparator.equals(other.nonNullComparator)));
     }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayIterator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayIterator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayIterator.java Tue Sep 15 05:42:44 2009
@@ -41,7 +41,7 @@
  * @author Neil O'Toole
  * @author Stephen Colebourne
  */
-public class ArrayIterator implements ResettableIterator {
+public class ArrayIterator<E> implements ResettableIterator<E> {
 
     /** The array to iterate over */    
     protected Object array;
@@ -159,11 +159,12 @@
      * @throws NoSuchElementException if all the elements in the array
      *  have already been returned
      */
-    public Object next() {
+    @SuppressWarnings("unchecked")
+    public E next() {
         if (hasNext() == false) {
             throw new NoSuchElementException();
         }
-        return Array.get(array, index++);
+        return (E) Array.get(array, index++);
     }
 
     /**

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java Tue Sep 15 05:42:44 2009
@@ -44,8 +44,8 @@
  * @author Stephen Colebourne
  * @author Phil Steitz
  */
-public class ArrayListIterator extends ArrayIterator
-        implements ListIterator, ResettableListIterator {
+public class ArrayListIterator<E> extends ArrayIterator<E>
+        implements ListIterator<E>, ResettableListIterator<E> {
 
     /**
      * Holds the index of the last item returned by a call to <code>next()</code>
@@ -129,12 +129,13 @@
      * @return the previous element
      * @throws NoSuchElementException if there is no previous element
      */
-    public Object previous() {
+    @SuppressWarnings("unchecked")
+    public E previous() {
         if (hasPrevious() == false) {
             throw new NoSuchElementException();
         }
         this.lastItemIndex = --this.index;
-        return Array.get(this.array, this.index);
+        return (E) Array.get(this.array, this.index);
     }
 
     /**
@@ -143,12 +144,13 @@
      * @return the next element
      * @throws NoSuchElementException if there is no next element
      */
-    public Object next() {
+    @SuppressWarnings("unchecked")
+    public E next() {
         if (hasNext() == false) {
             throw new NoSuchElementException();
         }
         this.lastItemIndex = this.index;
-        return Array.get(this.array, this.index++);
+        return (E) Array.get(this.array, this.index++);
     }
 
     /**

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java Tue Sep 15 05:42:44 2009
@@ -41,8 +41,8 @@
  * @author Stephen Colebourne
  * @author Phil Steitz
  */
-public class ObjectArrayListIterator extends ObjectArrayIterator
-        implements ListIterator, ResettableListIterator {
+public class ObjectArrayListIterator<E> extends ObjectArrayIterator<E>
+        implements ListIterator<E>, ResettableListIterator<E> {
 
     /**
      * Holds the index of the last item returned by a call to <code>next()</code> 
@@ -69,7 +69,7 @@
      * @param array the array to iterate over
      * @throws NullPointerException if <code>array</code> is <code>null</code>
      */
-    public ObjectArrayListIterator(Object[] array) {
+    public ObjectArrayListIterator(E[] array) {
         super(array);
     }
 
@@ -82,7 +82,7 @@
      * @throws NullPointerException if <code>array</code> is <code>null</code>
      * @throws IndexOutOfBoundsException if the start index is out of bounds
      */
-    public ObjectArrayListIterator(Object[] array, int start) {
+    public ObjectArrayListIterator(E[] array, int start) {
         super(array, start);
     }
     
@@ -97,7 +97,7 @@
      * @throws IllegalArgumentException if end index is before the start
      * @throws NullPointerException if <code>array</code> is <code>null</code>
      */
-    public ObjectArrayListIterator(Object[] array, int start, int end) {
+    public ObjectArrayListIterator(E[] array, int start, int end) {
         super(array, start, end);
     }
 
@@ -119,7 +119,7 @@
      * @return the previous element
      * @throws NoSuchElementException if there is no previous element
      */
-    public Object previous() {
+    public E previous() {
         if (hasPrevious() == false) {
             throw new NoSuchElementException();
         }
@@ -133,7 +133,7 @@
      * @return the next element
      * @throws NoSuchElementException if there is no next element
      */
-    public Object next() {
+    public E next() {
         if (hasNext() == false) {
             throw new NoSuchElementException();
         }
@@ -166,7 +166,7 @@
      * @param obj  the object to add
      * @throws UnsupportedOperationException always thrown.
      */
-    public void add(Object obj) {
+    public void add(E obj) {
         throw new UnsupportedOperationException("add() method is not supported");
     }
 
@@ -187,7 +187,7 @@
      * @throws IllegalStateException if next() has not yet been called.
      * @throws ClassCastException if the object type is unsuitable for the array
      */
-    public void set(Object obj) {
+    public void set(E obj) {
         if (this.lastItemIndex == -1) {
             throw new IllegalStateException("must call next() or previous() before a call to set()");
         }

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java Tue Sep 15 05:42:44 2009
@@ -75,23 +75,23 @@
  *
  * @author Stephen Colebourne
  */
-public class ObjectGraphIterator implements Iterator {
+public class ObjectGraphIterator<E> implements Iterator<E> {
 
     /** The stack of iterators */
-    protected final ArrayStack stack = new ArrayStack(8);
+    protected final ArrayStack<Iterator<? extends E>> stack = new ArrayStack<Iterator<? extends E>>(8);
     /** The root object in the tree */
-    protected Object root;
+    protected E root;
     /** The transformer to use */
-    protected Transformer transformer;
+    protected Transformer<? super E, ? extends E> transformer;
 
     /** Whether there is another element in the iteration */
-    protected boolean hasNext = false;    
+    protected boolean hasNext = false;
     /** The current iterator */
-    protected Iterator currentIterator;
+    protected Iterator<? extends E> currentIterator;
     /** The current value */
-    protected Object currentValue;
+    protected E currentValue;
     /** The last used iterator, needed for remove() */
-    protected Iterator lastUsedIterator;
+    protected Iterator<? extends E> lastUsedIterator;
 
     //-----------------------------------------------------------------------
     /**
@@ -103,10 +103,11 @@
      * @param root  the root object, null will result in an empty iterator
      * @param transformer  the transformer to use, null will use a no effect transformer
      */
-    public ObjectGraphIterator(Object root, Transformer transformer) {
+    @SuppressWarnings("unchecked")
+    public ObjectGraphIterator(E root, Transformer<? super E, ? extends E> transformer) {
         super();
         if (root instanceof Iterator) {
-            this.currentIterator = (Iterator) root;
+            this.currentIterator = (Iterator<? extends E>) root;
         } else {
             this.root = root;
         }
@@ -123,7 +124,7 @@
      * 
      * @param rootIterator  the root iterator, null will result in an empty iterator
      */
-    public ObjectGraphIterator(Iterator rootIterator) {
+    public ObjectGraphIterator(Iterator<? extends E> rootIterator) {
         super();
         this.currentIterator = rootIterator;
         this.transformer = null;
@@ -158,10 +159,11 @@
      * 
      * @param value  the value to start from
      */
-    protected void findNext(Object value) {
+    @SuppressWarnings("unchecked")
+    protected void findNext(E value) {
         if (value instanceof Iterator) {
             // need to examine this iterator
-            findNextByIterator((Iterator) value);
+            findNextByIterator((Iterator<? extends E>) value);
         } else {
             // next value found
             currentValue = value;
@@ -174,7 +176,7 @@
      * 
      * @param iterator  the iterator to start from
      */
-    protected void findNextByIterator(Iterator iterator) {
+    protected void findNextByIterator(Iterator<? extends E> iterator) {
         if (iterator != currentIterator) {
             // recurse a level
             if (currentIterator != null) {
@@ -184,7 +186,7 @@
         }
         
         while (currentIterator.hasNext() && hasNext == false) {
-            Object next = currentIterator.next();
+            E next = currentIterator.next();
             if (transformer != null) {
                 next = transformer.transform(next);
             }
@@ -196,7 +198,7 @@
             // all iterators exhausted
         } else {
             // current iterator exhausted, go up a level
-            currentIterator = (Iterator) stack.pop();
+            currentIterator = stack.pop();
             findNextByIterator(currentIterator);
         }
     }
@@ -218,13 +220,13 @@
      * @return the next element from the iteration
      * @throws NoSuchElementException if all the Iterators are exhausted
      */
-    public Object next() {
+    public E next() {
         updateCurrentIterator();
         if (hasNext == false) {
             throw new NoSuchElementException("No more elements in the iteration");
         }
         lastUsedIterator = currentIterator;
-        Object result = currentValue;
+        E result = currentValue;
         currentValue = null;
         hasNext = false;
         return result;

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/SingletonIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/SingletonIterator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/SingletonIterator.java (original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/SingletonIterator.java Tue Sep 15 05:42:44 2009
@@ -32,8 +32,8 @@
  * @author Stephen Colebourne
  * @author Rodney Waldhoff
  */
-public class SingletonIterator
-        implements Iterator, ResettableIterator {
+public class SingletonIterator<E>
+        implements Iterator<E>, ResettableIterator<E> {
 
     /** Whether remove is allowed */
     private final boolean removeAllowed;
@@ -42,7 +42,7 @@
     /** Has the element been removed */
     private boolean removed = false;
     /** The object */
-    private Object object;
+    private E object;
 
     /**
      * Constructs a new <code>SingletonIterator</code> where <code>remove</code>
@@ -50,7 +50,7 @@
      *
      * @param object  the single object to return from the iterator
      */
-    public SingletonIterator(Object object) {
+    public SingletonIterator(E object) {
         this(object, true);
     }
 
@@ -62,7 +62,7 @@
      * @param removeAllowed  true if remove is allowed
      * @since Commons Collections 3.1
      */
-    public SingletonIterator(Object object, boolean removeAllowed) {
+    public SingletonIterator(E object, boolean removeAllowed) {
         super();
         this.object = object;
         this.removeAllowed = removeAllowed;
@@ -89,7 +89,7 @@
      * @throws NoSuchElementException if the single object has already 
      *    been returned
      */
-    public Object next() {
+    public E next() {
         if (!beforeFirst || removed) {
             throw new NoSuchElementException();
         }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java Tue Sep 15 05:42:44 2009
@@ -34,7 +34,7 @@
  *
  * @author Stephen Colebourne
  */
-public abstract class AbstractTestComparator extends AbstractTestObject {
+public abstract class AbstractTestComparator<T> extends AbstractTestObject {
 
     /**
      * JUnit constructor.
@@ -46,19 +46,13 @@
     }
 
     //-----------------------------------------------------------------------
-    /**
-     * Implement this method to return the comparator to test.
-     * 
-     * @return the comparator to test
-     */
-    public abstract Comparator makeComparator();
     
     /**
      * Implement this method to return a list of sorted objects.
      * 
      * @return sorted objects
      */
-    public abstract List getComparableObjectsOrdered();
+    public abstract List<T> getComparableObjectsOrdered();
 
     //-----------------------------------------------------------------------
     /**
@@ -66,9 +60,7 @@
      * 
      * @return a full iterator
      */
-    public Object makeObject() {
-        return makeComparator();
-    }
+    public abstract Comparator<T> makeObject();
 
     /**
      * Overrides superclass to block tests.
@@ -96,23 +88,22 @@
     /**
      * Reverse the list.
      */
-    protected void reverseObjects(List list) {
+    protected void reverseObjects(List<?> list) {
         Collections.reverse(list);
     }
 
     /**
      * Randomize the list.
      */
-    protected void randomizeObjects(List list) {
+    protected void randomizeObjects(List<?> list) {
         Collections.shuffle(list);
     }
 
     /**
      * Sort the list.
      */
-    protected void sortObjects(List list, Comparator comparator) {
-        Collections.sort(list,comparator);
-
+    protected void sortObjects(List<T> list, Comparator<? super T> comparator) {
+        Collections.sort(list, comparator);
     }
 
     //-----------------------------------------------------------------------
@@ -120,43 +111,41 @@
      * Test sorting an empty list
      */
     public void testEmptyListSort() {
-        List list = new LinkedList();
-        sortObjects(list, makeComparator());
+        List<T> list = new LinkedList<T>();
+        sortObjects(list, makeObject());
+
+        List<T> list2 = new LinkedList<T>();
 
-        List list2 = new LinkedList();
-        
-        assertTrue("Comparator cannot sort empty lists",
-                   list2.equals(list));
+        assertTrue("Comparator cannot sort empty lists", list2.equals(list));
     }
 
     /**
      * Test sorting a reversed list.
      */
     public void testReverseListSort() {
-        Comparator comparator = makeComparator();
+        Comparator<T> comparator = makeObject();
 
-        List randomList = getComparableObjectsOrdered();
+        List<T> randomList = getComparableObjectsOrdered();
         reverseObjects(randomList);
-        sortObjects(randomList,comparator);
+        sortObjects(randomList, comparator);
 
-        List orderedList = getComparableObjectsOrdered();
+        List<T> orderedList = getComparableObjectsOrdered();
 
         assertTrue("Comparator did not reorder the List correctly",
                    orderedList.equals(randomList));
-
     }
 
     /**
      * Test sorting a random list.
      */
     public void testRandomListSort() {
-        Comparator comparator = makeComparator();
+        Comparator<T> comparator = makeObject();
 
-        List randomList = getComparableObjectsOrdered();
+        List<T> randomList = getComparableObjectsOrdered();
         randomizeObjects(randomList);
         sortObjects(randomList,comparator);
 
-        List orderedList = getComparableObjectsOrdered();
+        List<T> orderedList = getComparableObjectsOrdered();
 
         /* debug 
         Iterator i = randomList.iterator();
@@ -174,7 +163,7 @@
      * Nearly all Comparators should be Serializable.
      */
     public void testComparatorIsSerializable() {
-        Comparator comparator = makeComparator();
+        Comparator<T> comparator = makeObject();
         assertTrue("This comparator should be Serializable.",
                    comparator instanceof Serializable);
     }
@@ -195,37 +184,38 @@
      * Compare the current serialized form of the Comparator
      * against the canonical version in SVN.
      */
+    @SuppressWarnings("unchecked")
     public void testComparatorCompatibility() throws IOException, ClassNotFoundException {
-        if(!skipSerializedCanonicalTests()) {
-            Comparator comparator = null;
+        if (!skipSerializedCanonicalTests()) {
+            Comparator<T> comparator = null;
     
             // test to make sure the canonical form has been preserved
             try {
-                comparator = (Comparator) readExternalFormFromDisk(getCanonicalComparatorName(makeComparator()));
+                comparator = (Comparator<T>) readExternalFormFromDisk(getCanonicalComparatorName(makeObject()));
             } catch (FileNotFoundException exception) {
     
                 boolean autoCreateSerialized = false;
     
-                if(autoCreateSerialized) {
-                    comparator = makeComparator();
+                if (autoCreateSerialized) {
+                      comparator = makeObject();
                     String fileName = getCanonicalComparatorName(comparator);
                     writeExternalFormToDisk((Serializable) comparator, fileName);
-                    fail("Serialized form could not be found.  A serialized version " +
-                         "has now been written (and should be added to SVN): " + fileName);
+                    fail("Serialized form could not be found.  A serialized version "
+                            + "has now been written (and should be added to CVS): " + fileName);
                 } else {
-                    fail("The Serialized form could be located to test serialization " +
-                        "compatibility: " + exception.getMessage());
+                    fail("The Serialized form could be located to test serialization "
+                            + "compatibility: " + exception.getMessage());
                 }
             }
     
             
             // make sure the canonical form produces the ordering we currently
             // expect
-            List randomList = getComparableObjectsOrdered();
+            List<T> randomList = getComparableObjectsOrdered();
             reverseObjects(randomList);
-            sortObjects(randomList,comparator);
+            sortObjects(randomList, comparator);
     
-            List orderedList = getComparableObjectsOrdered();
+            List<T> orderedList = getComparableObjectsOrdered();
     
             assertTrue("Comparator did not reorder the List correctly",
                        orderedList.equals(randomList));

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestNullComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestNullComparator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestNullComparator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/comparators/TestNullComparator.java Tue Sep 15 05:42:44 2009
@@ -30,7 +30,7 @@
  *
  * @author Michael A. Smith
  */
-public abstract class TestNullComparator extends AbstractTestComparator {
+public abstract class TestNullComparator extends AbstractTestComparator<Integer> {
 
     public TestNullComparator(String testName) {
         super(testName);
@@ -52,12 +52,12 @@
             super(testName);
         }
 
-    public Comparator makeComparator() {
-            return new NullComparator();
+        public Comparator<Integer> makeObject() {
+            return new NullComparator<Integer>();
         }
-        
-    public List getComparableObjectsOrdered() {
-        List list = new LinkedList();
+
+        public List<Integer> getComparableObjectsOrdered() {
+            List<Integer> list = new LinkedList<Integer>();
             list.add(new Integer(1));
             list.add(new Integer(2));
             list.add(new Integer(3));
@@ -76,17 +76,17 @@
      *  Test the NullComparator with nulls low using the comparable comparator
      **/
     public static class TestNullComparator2 extends TestNullComparator {
-        
+
         public TestNullComparator2(String testName) {
             super(testName);
         }
-        
-        public Comparator makeComparator() {
-            return new NullComparator(false);
-        }
-        
-        public List getComparableObjectsOrdered() {
-            List list = new LinkedList();
+
+        public Comparator<Integer> makeObject() {
+            return new NullComparator<Integer>(false);
+        }
+
+        public List<Integer> getComparableObjectsOrdered() {
+            List<Integer> list = new LinkedList<Integer>();
             list.add(null);
             list.add(new Integer(1));
             list.add(new Integer(2));
@@ -95,7 +95,7 @@
             list.add(new Integer(5));
             return list;
         }
-        
+
         public String getCanonicalComparatorName(Object object) {
             return super.getCanonicalComparatorName(object) + "2";
         }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java Tue Sep 15 05:42:44 2009
@@ -31,7 +31,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TestSingletonListIterator extends AbstractTestListIterator {
+public class TestSingletonListIterator<E> extends AbstractTestListIterator<E> {
 
     private static final Object testValue = "foo";
     
@@ -47,16 +47,17 @@
      * Returns a SingletonListIterator from which 
      * the element has already been removed.
      */
-    public ListIterator makeEmptyListIterator() {
-        SingletonListIterator iter = (SingletonListIterator)makeFullIterator();
+    public SingletonListIterator<E> makeEmptyIterator() {
+        SingletonListIterator<E> iter = makeObject();
         iter.next();
         iter.remove();
         iter.reset();        
         return iter;
     }
 
-    public ListIterator makeFullListIterator() {
-        return new SingletonListIterator( testValue );
+    @SuppressWarnings("unchecked")
+    public SingletonListIterator<E> makeObject() {
+        return new SingletonListIterator<E>((E) testValue);
     }
 
     public boolean supportsAdd() {
@@ -72,7 +73,7 @@
     }
 
     public void testIterator() {
-        ListIterator iter = (ListIterator) makeObject();
+        ListIterator<E> iter = makeObject();
         assertTrue( "Iterator should have next item", iter.hasNext() );
         assertTrue( "Iterator should have no previous item", !iter.hasPrevious() );
         assertEquals( "Iteration next index", 0, iter.nextIndex() );
@@ -118,7 +119,7 @@
     }
     
     public void testReset() {
-        ResettableListIterator it = (ResettableListIterator) makeObject();
+        ResettableListIterator<E> it = makeObject();
         
         assertEquals(true, it.hasNext());
         assertEquals(false, it.hasPrevious());

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTreeList.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTreeList.java?rev=815004&r1=815003&r2=815004&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTreeList.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestTreeList.java Tue Sep 15 05:42:44 2009
@@ -31,8 +31,8 @@
  *
  * @author Joerg Schmuecker
  */
-public class TestTreeList extends AbstractTestList {
-    
+public class TestTreeList<E> extends AbstractTestList<E> {
+
     public TestTreeList(String name) {
         super(name);
     }
@@ -53,49 +53,49 @@
         return BulkTest.makeSuite(TestTreeList.class);
     }
 
-    public static void benchmark(List l) {
+    public static void benchmark(List<? super Integer> l) {
         long start = System.currentTimeMillis();
         for (int i = 0; i < 100000; i++) {
             l.add(new Integer(i));
         }
         System.out.print(System.currentTimeMillis() - start + ";");
-        
+
         start = System.currentTimeMillis();
         for (int i = 0; i < 200; i++) {
             l.toArray();
         }
         System.out.print(System.currentTimeMillis() - start + ";");
-        
+
         start = System.currentTimeMillis();
         for (int i = 0; i < 100; i++) {
-            java.util.Iterator it = l.iterator();
+            java.util.Iterator<? super Integer> it = l.iterator();
             while (it.hasNext()) {
                 it.next();
             }
         }
         System.out.print(System.currentTimeMillis() - start + ";");
-        
+
         start = System.currentTimeMillis();
         for (int i = 0; i < 10000; i++) {
             int j = (int) (Math.random() * 100000);
             l.add(j, new Integer(-j));
         }
         System.out.print(System.currentTimeMillis() - start + ";");
-        
+
         start = System.currentTimeMillis();
         for (int i = 0; i < 50000; i++) {
             int j = (int) (Math.random() * 110000);
             l.get(j);
         }
         System.out.print(System.currentTimeMillis() - start + ";");
-        
+
         start = System.currentTimeMillis();
         for (int i = 0; i < 200; i++) {
             int j = (int) (Math.random() * 100000);
             l.indexOf(new Integer(j));
         }
         System.out.print(System.currentTimeMillis() - start + ";");
-        
+
         start = System.currentTimeMillis();
         for (int i = 0; i < 10000; i++) {
             int j = (int) (Math.random() * 100000);
@@ -105,18 +105,19 @@
     }
 
     //-----------------------------------------------------------------------
-    public List makeEmptyList() {
-        return new TreeList();
+    public TreeList<E> makeObject() {
+        return new TreeList<E>();
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testAddMultiple() {
-        List l = makeEmptyList();
-        l.add("hugo");
-        l.add("erna");
-        l.add("daniel");
-        l.add("andres");
-        l.add("harald");
+        List<E> l = makeObject();
+        l.add((E) "hugo");
+        l.add((E) "erna");
+        l.add((E) "daniel");
+        l.add((E) "andres");
+        l.add((E) "harald");
         l.add(0, null);
         assertEquals(null, l.get(0));
         assertEquals("hugo", l.get(1));
@@ -126,13 +127,14 @@
         assertEquals("harald", l.get(5));
     }
 
+    @SuppressWarnings("unchecked")
     public void testRemove() {
-        List l = makeEmptyList();
-        l.add("hugo");
-        l.add("erna");
-        l.add("daniel");
-        l.add("andres");
-        l.add("harald");
+        List<E> l = makeObject();
+        l.add((E) "hugo");
+        l.add((E) "erna");
+        l.add((E) "daniel");
+        l.add((E) "andres");
+        l.add((E) "harald");
         l.add(0, null);
         int i = 0;
         assertEquals(null, l.get(i++));
@@ -164,23 +166,25 @@
         assertEquals("harald", l.get(i++));
     }
 
+    @SuppressWarnings("unchecked")
     public void testInsertBefore() {
-        List l = makeEmptyList();
-        l.add("erna");
-        l.add(0, "hugo");
+        List<E> l = makeObject();
+        l.add((E) "erna");
+        l.add(0, (E) "hugo");
         assertEquals("hugo", l.get(0));
         assertEquals("erna", l.get(1));
     }
 
+    @SuppressWarnings("unchecked")
     public void testIndexOf() {
-        List l = makeEmptyList();
-        l.add("0");
-        l.add("1");
-        l.add("2");
-        l.add("3");
-        l.add("4");
-        l.add("5");
-        l.add("6");
+        List<E> l = makeObject();
+        l.add((E) "0");
+        l.add((E) "1");
+        l.add((E) "2");
+        l.add((E) "3");
+        l.add((E) "4");
+        l.add((E) "5");
+        l.add((E) "6");
         assertEquals(0, l.indexOf("0"));
         assertEquals(1, l.indexOf("1"));
         assertEquals(2, l.indexOf("2"));
@@ -188,17 +192,17 @@
         assertEquals(4, l.indexOf("4"));
         assertEquals(5, l.indexOf("5"));
         assertEquals(6, l.indexOf("6"));
-        
-        l.set(1, "0");
+
+        l.set(1, (E) "0");
         assertEquals(0, l.indexOf("0"));
-        
-        l.set(3, "3");
+
+        l.set(3, (E) "3");
         assertEquals(3, l.indexOf("3"));
-        l.set(2, "3");
+        l.set(2, (E) "3");
         assertEquals(2, l.indexOf("3"));
-        l.set(1, "3");
+        l.set(1, (E) "3");
         assertEquals(1, l.indexOf("3"));
-        l.set(0, "3");
+        l.set(0, (E) "3");
         assertEquals(0, l.indexOf("3"));
     }
 
@@ -214,18 +218,18 @@
 
     public void testBug35258() {
         Object objectToRemove = new Integer(3);
-        
-        List treelist = new TreeList();
+
+        List<Integer> treelist = new TreeList<Integer>();
         treelist.add(new Integer(0));
         treelist.add(new Integer(1));
         treelist.add(new Integer(2));
         treelist.add(new Integer(3));
         treelist.add(new Integer(4));
-        
+
         // this cause inconsistence of ListIterator()
         treelist.remove(objectToRemove);
-        
-        ListIterator li = treelist.listIterator();
+
+        ListIterator<Integer> li = treelist.listIterator();
         assertEquals(new Integer(0), li.next());
         assertEquals(new Integer(0), li.previous());
         assertEquals(new Integer(0), li.next());