commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r815138 - /commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestListOrderedSet.java
Date Tue, 15 Sep 2009 05:57:47 GMT
Author: bayard
Date: Tue Sep 15 05:57:47 2009
New Revision: 815138

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

Also see the following revisions:

    ------------------------------------------------------------------------
    r471186 | scolebourne | 2006-11-04 05:47:51 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Remove getSet() and getSortedSet() - use decorated()
    ------------------------------------------------------------------------

Modified:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestListOrderedSet.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestListOrderedSet.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestListOrderedSet.java?rev=815138&r1=815137&r2=815138&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestListOrderedSet.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/set/TestListOrderedSet.java
Tue Sep 15 05:57:47 2009
@@ -35,7 +35,12 @@
  * @author Henning P. Schmiedehausen
  * @author Stephen Colebourne
  */
-public class TestListOrderedSet extends AbstractTestSet {
+public class TestListOrderedSet<E> extends AbstractTestSet<E> {
+
+    private static final Integer ZERO = new Integer(0);
+    private static final Integer ONE = new Integer(1);
+    private static final Integer TWO = new Integer(2);
+    private static final Integer THREE = new Integer(3);
 
     public TestListOrderedSet(String testName) {
         super(testName);
@@ -50,22 +55,24 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    public Set makeEmptySet() {
-        return ListOrderedSet.decorate(new HashSet());
+    public ListOrderedSet<E> makeObject() {
+        return ListOrderedSet.decorate(new HashSet<E>());
     }
 
-    protected Set setupSet() {
-        Set set = makeEmptySet();
+    @SuppressWarnings("unchecked")
+    protected ListOrderedSet<E> setupSet() {
+        ListOrderedSet<E> set = makeObject();
 
         for (int i = 0; i < 10; i++) {
-            set.add(Integer.toString(i));
+            set.add((E) Integer.toString(i));
         }
         return set;
     }
 
+    @SuppressWarnings("unchecked")
     public void testOrdering() {
-        Set set = setupSet();
-        Iterator it = set.iterator();
+        ListOrderedSet<E> set = setupSet();
+        Iterator<E> it = set.iterator();
 
         for (int i = 0; i < 10; i++) {
             assertEquals("Sequence is wrong", Integer.toString(i), it.next());
@@ -81,7 +88,7 @@
         }
 
         for (int i = 0; i < 10; i++) {
-            set.add(Integer.toString(i));
+            set.add((E) Integer.toString(i));
         }
 
         assertEquals("Size of set is wrong!", 10, set.size());
@@ -94,19 +101,15 @@
             assertEquals("Sequence is wrong", Integer.toString(i), it.next());
         }
     }
-    
-    private static final Integer ZERO = new Integer(0);
-    private static final Integer ONE = new Integer(1);
-    private static final Integer TWO = new Integer(2);
-    private static final Integer THREE = new Integer(3);
-    
+
+    @SuppressWarnings("unchecked")
     public void testListAddRemove() {
-        ListOrderedSet set = (ListOrderedSet) makeEmptySet();
-        List view = set.asList();
-        set.add(ZERO);
-        set.add(ONE);
-        set.add(TWO);
-        
+        ListOrderedSet<E> set = makeObject();
+        List<E> view = set.asList();
+        set.add((E) ZERO);
+        set.add((E) ONE);
+        set.add((E) TWO);
+
         assertEquals(3, set.size());
         assertSame(ZERO, set.get(0));
         assertSame(ONE, set.get(1));
@@ -115,11 +118,11 @@
         assertSame(ZERO, view.get(0));
         assertSame(ONE, view.get(1));
         assertSame(TWO, view.get(2));
-        
+
         assertEquals(0, set.indexOf(ZERO));
         assertEquals(1, set.indexOf(ONE));
         assertEquals(2, set.indexOf(TWO));
-        
+
         set.remove(1);
         assertEquals(2, set.size());
         assertSame(ZERO, set.get(0));
@@ -127,36 +130,37 @@
         assertEquals(2, view.size());
         assertSame(ZERO, view.get(0));
         assertSame(TWO, view.get(1));
-    }        
-    
+    }
+
+    @SuppressWarnings("unchecked")
     public void testListAddIndexed() {
-        ListOrderedSet set = (ListOrderedSet) makeEmptySet();
-        set.add(ZERO);
-        set.add(TWO);
-        
-        set.add(1, ONE);
+        ListOrderedSet<E> set = makeObject();
+        set.add((E) ZERO);
+        set.add((E) TWO);
+
+        set.add(1, (E) ONE);
         assertEquals(3, set.size());
         assertSame(ZERO, set.get(0));
         assertSame(ONE, set.get(1));
         assertSame(TWO, set.get(2));
-        
-        set.add(0, ONE);
+
+        set.add(0, (E) ONE);
         assertEquals(3, set.size());
         assertSame(ZERO, set.get(0));
         assertSame(ONE, set.get(1));
         assertSame(TWO, set.get(2));
-        
-        List list = new ArrayList();
-        list.add(ZERO);
-        list.add(TWO);
-        
+
+        List<E> list = new ArrayList<E>();
+        list.add((E) ZERO);
+        list.add((E) TWO);
+
         set.addAll(0, list);
         assertEquals(3, set.size());
         assertSame(ZERO, set.get(0));
         assertSame(ONE, set.get(1));
         assertSame(TWO, set.get(2));
-        
-        list.add(0, THREE); // list = [3,0,2]
+
+        list.add(0, (E) THREE); // list = [3,0,2]
         set.remove(TWO);    //  set = [0,1]
         set.addAll(1, list);
         assertEquals(4, set.size());
@@ -166,15 +170,16 @@
         assertSame(ONE, set.get(3));
     }
 
+    @SuppressWarnings("unchecked")
     public void testListAddReplacing() {
-        ListOrderedSet set = (ListOrderedSet) makeEmptySet();
+        ListOrderedSet<E> set = makeObject();
         A a = new A();
         B b = new B();
-        set.add(a);
+        set.add((E) a);
         assertEquals(1, set.size());
-        set.add(b);  // will match but not replace A as equal
+        set.add((E) b);  // will match but not replace A as equal
         assertEquals(1, set.size());
-        assertSame(a, set.getSet().iterator().next());
+        assertSame(a, set.decorated().iterator().next());
         assertSame(a, set.iterator().next());
         assertSame(a, set.get(0));
         assertSame(a, set.asList().get(0));
@@ -200,11 +205,11 @@
 
     public void testDecorator() {
         try {
-            ListOrderedSet.decorate((List) null);
+            ListOrderedSet.decorate((List<E>) null);
             fail();
         } catch (IllegalArgumentException ex) {}
         try {
-            ListOrderedSet.decorate((Set) null);
+            ListOrderedSet.decorate((Set<E>) null);
             fail();
         } catch (IllegalArgumentException ex) {}
         try {
@@ -212,11 +217,11 @@
             fail();
         } catch (IllegalArgumentException ex) {}
         try {
-            ListOrderedSet.decorate(new HashSet(), null);
+            ListOrderedSet.decorate(new HashSet<E>(), null);
             fail();
         } catch (IllegalArgumentException ex) {}
         try {
-            ListOrderedSet.decorate(null, new ArrayList());
+            ListOrderedSet.decorate(null, new ArrayList<E>());
             fail();
         } catch (IllegalArgumentException ex) {}
     }



Mime
View raw message