commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r814997 [17/18] - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/bag/ java/org/apache/commons/collections/bidimap/ java/org/apache/commons/collections/buffer/ java/org/apac...
Date Tue, 15 Sep 2009 05:30:02 GMT
Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLRUMap.java Tue Sep 15 05:29:56 2009
@@ -37,7 +37,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TestLRUMap extends AbstractTestOrderedMap {
+public class TestLRUMap<K, V> extends AbstractTestOrderedMap<K, V> {
 
     public TestLRUMap(String testName) {
         super(testName);
@@ -46,19 +46,27 @@
     public static void main(String[] args) {
         TestRunner.run(suite());
     }
-    
+
     public static Test suite() {
         return BulkTest.makeSuite(TestLRUMap.class);
     }
 
-    public Map makeEmptyMap() {
-        return new LRUMap();
+    public LRUMap<K, V> makeObject() {
+        return new LRUMap<K, V>();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public LRUMap<K, V> makeFullMap() {
+        return (LRUMap<K, V>) super.makeFullMap();
     }
 
     public boolean isGetStructuralModify() {
         return true;
     }
-    
+
     public String getCompatibilityVersion() {
         return "3";
     }
@@ -66,169 +74,174 @@
     //-----------------------------------------------------------------------
     public void testLRU() {
         if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
-        Object[] keys = getSampleKeys();
-        Object[] values = getSampleValues();
-        Iterator it = null;
-        
-        LRUMap map = new LRUMap(2);
+        K[] keys = getSampleKeys();
+        V[] values = getSampleValues();
+        Iterator<K> kit;
+        Iterator<V> vit;
+
+        LRUMap<K, V> map = new LRUMap<K, V>(2);
         assertEquals(0, map.size());
         assertEquals(false, map.isFull());
         assertEquals(2, map.maxSize());
-        
+
         map.put(keys[0], values[0]);
         assertEquals(1, map.size());
         assertEquals(false, map.isFull());
         assertEquals(2, map.maxSize());
-        
+
         map.put(keys[1], values[1]);
         assertEquals(2, map.size());
         assertEquals(true, map.isFull());
         assertEquals(2, map.maxSize());
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[1], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[0], kit.next());
+        assertSame(keys[1], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[0], vit.next());
+        assertSame(values[1], vit.next());
 
         map.put(keys[2], values[2]);
         assertEquals(2, map.size());
         assertEquals(true, map.isFull());
         assertEquals(2, map.maxSize());
-        it = map.keySet().iterator();
-        assertSame(keys[1], it.next());
-        assertSame(keys[2], it.next());
-        it = map.values().iterator();
-        assertSame(values[1], it.next());
-        assertSame(values[2], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[1], kit.next());
+        assertSame(keys[2], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[1], vit.next());
+        assertSame(values[2], vit.next());
 
         map.put(keys[2], values[0]);
         assertEquals(2, map.size());
         assertEquals(true, map.isFull());
         assertEquals(2, map.maxSize());
-        it = map.keySet().iterator();
-        assertSame(keys[1], it.next());
-        assertSame(keys[2], it.next());
-        it = map.values().iterator();
-        assertSame(values[1], it.next());
-        assertSame(values[0], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[1], kit.next());
+        assertSame(keys[2], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[1], vit.next());
+        assertSame(values[0], vit.next());
 
         map.put(keys[1], values[3]);
         assertEquals(2, map.size());
         assertEquals(true, map.isFull());
         assertEquals(2, map.maxSize());
-        it = map.keySet().iterator();
-        assertSame(keys[2], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[3], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[2], kit.next());
+        assertSame(keys[1], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[0], vit.next());
+        assertSame(values[3], vit.next());
     }
-    
-    //-----------------------------------------------------------------------    
+
+    //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testReset() {
         resetEmpty();
-        OrderedMap ordered = (OrderedMap) map;
-        ((ResettableIterator) ordered.mapIterator()).reset();
-        
+        OrderedMap<K, V> ordered = getMap();
+        ((ResettableIterator<K>) ordered.mapIterator()).reset();
+
         resetFull();
-        ordered = (OrderedMap) map;
-        List list = new ArrayList(ordered.keySet());
-        ResettableIterator it = (ResettableIterator) ordered.mapIterator();
+        ordered = getMap();
+        List<K> list = new ArrayList<K>(ordered.keySet());
+        ResettableIterator<K> it = (ResettableIterator<K>) ordered.mapIterator();
         assertSame(list.get(0), it.next());
         assertSame(list.get(1), it.next());
         it.reset();
         assertSame(list.get(0), it.next());
     }
-    
+
     //-----------------------------------------------------------------------
     public void testAccessOrder() {
         if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
-        Object[] keys = getSampleKeys();
-        Object[] values = getSampleValues();
-        Iterator it = null;
-        
+        K[] keys = getSampleKeys();
+        V[] values = getSampleValues();
+        Iterator<K> kit = null;
+        Iterator<V> vit = null;
+
         resetEmpty();
         map.put(keys[0], values[0]);
         map.put(keys[1], values[1]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[1], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[0], kit.next());
+        assertSame(keys[1], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[0], vit.next());
+        assertSame(values[1], vit.next());
 
         // no change to order
         map.put(keys[1], values[1]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[1], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[0], kit.next());
+        assertSame(keys[1], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[0], vit.next());
+        assertSame(values[1], vit.next());
 
         // no change to order
         map.put(keys[1], values[2]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[2], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[0], kit.next());
+        assertSame(keys[1], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[0], vit.next());
+        assertSame(values[2], vit.next());
 
         // change to order
         map.put(keys[0], values[3]);
-        it = map.keySet().iterator();
-        assertSame(keys[1], it.next());
-        assertSame(keys[0], it.next());
-        it = map.values().iterator();
-        assertSame(values[2], it.next());
-        assertSame(values[3], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[1], kit.next());
+        assertSame(keys[0], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[2], vit.next());
+        assertSame(values[3], vit.next());
 
         // change to order
         map.get(keys[1]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[3], it.next());
-        assertSame(values[2], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[0], kit.next());
+        assertSame(keys[1], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[3], vit.next());
+        assertSame(values[2], vit.next());
 
         // change to order
         map.get(keys[0]);
-        it = map.keySet().iterator();
-        assertSame(keys[1], it.next());
-        assertSame(keys[0], it.next());
-        it = map.values().iterator();
-        assertSame(values[2], it.next());
-        assertSame(values[3], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[1], kit.next());
+        assertSame(keys[0], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[2], vit.next());
+        assertSame(values[3], vit.next());
 
         // no change to order
         map.get(keys[0]);
-        it = map.keySet().iterator();
-        assertSame(keys[1], it.next());
-        assertSame(keys[0], it.next());
-        it = map.values().iterator();
-        assertSame(values[2], it.next());
-        assertSame(values[3], it.next());
+        kit = map.keySet().iterator();
+        assertSame(keys[1], kit.next());
+        assertSame(keys[0], kit.next());
+        vit = map.values().iterator();
+        assertSame(values[2], vit.next());
+        assertSame(values[3], vit.next());
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testClone() {
-        LRUMap map = new LRUMap(10);
-        map.put("1", "1");
-        Map cloned = (Map) map.clone();
+        LRUMap<K, V> map = new LRUMap<K, V>(10);
+        map.put((K) "1", (V) "1");
+        Map<K, V> cloned = map.clone();
         assertEquals(map.size(), cloned.size());
         assertSame(map.get("1"), cloned.get("1"));
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testRemoveLRU() {
         MockLRUMapSubclass map = new MockLRUMapSubclass(2);
         assertNull(map.entry);
-        map.put("A", "a");
+        map.put((K) "A", "a");
         assertNull(map.entry);
-        map.put("B", "b");
+        map.put((K) "B", "b");
         assertNull(map.entry);
-        map.put("C", "c");  // removes oldest, which is A=a
+        map.put((K) "C", "c");  // removes oldest, which is A=a
         assertNotNull(map.entry);
         assertEquals("A", map.key);
         assertEquals("a", map.value);
@@ -238,32 +251,34 @@
         assertEquals(true, map.containsKey("B"));
         assertEquals(true, map.containsKey("C"));
     }
-    
-    static class MockLRUMapSubclass extends LRUMap {
-        LinkEntry entry;
-        Object key;
-        Object value;
+
+    @SuppressWarnings("serial")
+    static class MockLRUMapSubclass<K, V> extends LRUMap<K, V> {
+        LinkEntry<K, V> entry;
+        K key;
+        V value;
 
         MockLRUMapSubclass(int size) {
             super(size);
         }
 
-        protected boolean removeLRU(LinkEntry entry) {
+        protected boolean removeLRU(LinkEntry<K, V> entry) {
             this.entry = entry;
             this.key = entry.getKey();
             this.value = entry.getValue();
             return true;
         }
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testRemoveLRUBlocksRemove() {
-        MockLRUMapSubclassBlocksRemove map = new MockLRUMapSubclassBlocksRemove(2, false);
+        MockLRUMapSubclassBlocksRemove<K, V> map = new MockLRUMapSubclassBlocksRemove<K, V>(2, false);
         assertEquals(0, map.size());
-        map.put("A", "a");
+        map.put((K) "A", (V) "a");
         assertEquals(1, map.size());
-        map.put("B", "b");
+        map.put((K) "B", (V) "b");
         assertEquals(2, map.size());
-        map.put("C", "c");  // should remove oldest, which is A=a, but this is blocked
+        map.put((K) "C", (V) "c");  // should remove oldest, which is A=a, but this is blocked
         assertEquals(3, map.size());
         assertEquals(2, map.maxSize());
         assertEquals(true, map.containsKey("A"));
@@ -271,39 +286,42 @@
         assertEquals(true, map.containsKey("C"));
     }
 
+    @SuppressWarnings("unchecked")
     public void testRemoveLRUBlocksRemoveScan() {
-        MockLRUMapSubclassBlocksRemove map = new MockLRUMapSubclassBlocksRemove(2, true);
+        MockLRUMapSubclassBlocksRemove<K, V> map = new MockLRUMapSubclassBlocksRemove<K, V>(2, true);
         assertEquals(0, map.size());
-        map.put("A", "a");
+        map.put((K) "A", (V) "a");
         assertEquals(1, map.size());
-        map.put("B", "b");
+        map.put((K) "B", (V) "b");
         assertEquals(2, map.size());
-        map.put("C", "c");  // should remove oldest, which is A=a, but this is blocked
+        map.put((K) "C", (V) "c");  // should remove oldest, which is A=a, but this is blocked
         assertEquals(3, map.size());
         assertEquals(2, map.maxSize());
         assertEquals(true, map.containsKey("A"));
         assertEquals(true, map.containsKey("B"));
         assertEquals(true, map.containsKey("C"));
     }
-    
-    static class MockLRUMapSubclassBlocksRemove extends LRUMap {
+
+    @SuppressWarnings("serial")
+    static class MockLRUMapSubclassBlocksRemove<K, V> extends LRUMap<K, V> {
         MockLRUMapSubclassBlocksRemove(int size, boolean scanUntilRemove) {
             super(size, scanUntilRemove);
         }
 
-        protected boolean removeLRU(LinkEntry entry) {
+        protected boolean removeLRU(LinkEntry<K, V> entry) {
             return false;
         }
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testRemoveLRUFirstBlocksRemove() {
-        MockLRUMapSubclassFirstBlocksRemove map = new MockLRUMapSubclassFirstBlocksRemove(2);
+        MockLRUMapSubclassFirstBlocksRemove<K, V> map = new MockLRUMapSubclassFirstBlocksRemove<K, V>(2);
         assertEquals(0, map.size());
-        map.put("A", "a");
+        map.put((K) "A", (V) "a");
         assertEquals(1, map.size());
-        map.put("B", "b");
+        map.put((K) "B", (V) "b");
         assertEquals(2, map.size());
-        map.put("C", "c");  // should remove oldest, which is A=a  but this is blocked - so advance to B=b
+        map.put((K) "C", (V) "c");  // should remove oldest, which is A=a  but this is blocked - so advance to B=b
         assertEquals(2, map.size());
         assertEquals(2, map.maxSize());
         assertEquals(true, map.containsKey("A"));
@@ -311,12 +329,13 @@
         assertEquals(true, map.containsKey("C"));
     }
 
-    static class MockLRUMapSubclassFirstBlocksRemove extends LRUMap {
+    @SuppressWarnings("serial")
+    static class MockLRUMapSubclassFirstBlocksRemove<K, V> extends LRUMap<K, V> {
         MockLRUMapSubclassFirstBlocksRemove(int size) {
             super(size, true);
         }
 
-        protected boolean removeLRU(LinkEntry entry) {
+        protected boolean removeLRU(LinkEntry<K, V> entry) {
             if ("a".equals(entry.getValue())) {
                 return false;
             } else {
@@ -341,6 +360,7 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void testInternalState_Buckets() {
         if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
         SingleHashCode one = new SingleHashCode("1");
@@ -350,12 +370,12 @@
         SingleHashCode five = new SingleHashCode("5");
         SingleHashCode six = new SingleHashCode("6");
 
-        LRUMap map = new LRUMap(3, 1.0f);
+        LRUMap<K, V> map = new LRUMap<K, V>(3, 1.0f);
         int hashIndex = map.hashIndex(map.hash(one), 4);
-        map.put(one, "A");
-        map.put(two, "B");
-        map.put(three, "C");
-        
+        map.put((K) one, (V) "A");
+        map.put((K) two, (V) "B");
+        map.put((K) three, (V) "C");
+
         assertEquals(4, map.data.length);
         assertEquals(3, map.size);
         assertEquals(null, map.header.next);
@@ -365,9 +385,9 @@
         assertEquals(three, map.data[hashIndex].key);
         assertEquals(two, map.data[hashIndex].next.key);
         assertEquals(one, map.data[hashIndex].next.next.key);
-        
-        map.put(four, "D");  // reuses last in next list
-        
+
+        map.put((K) four, (V) "D");  // reuses last in next list
+
         assertEquals(4, map.data.length);
         assertEquals(3, map.size);
         assertEquals(null, map.header.next);
@@ -377,9 +397,9 @@
         assertEquals(four, map.data[hashIndex].key);
         assertEquals(three, map.data[hashIndex].next.key);
         assertEquals(two, map.data[hashIndex].next.next.key);
-        
+
         map.get(three);
-        
+
         assertEquals(4, map.data.length);
         assertEquals(3, map.size);
         assertEquals(null, map.header.next);
@@ -389,9 +409,9 @@
         assertEquals(four, map.data[hashIndex].key);
         assertEquals(three, map.data[hashIndex].next.key);
         assertEquals(two, map.data[hashIndex].next.next.key);
-        
-        map.put(five, "E");  // reuses last in next list
-        
+
+        map.put((K) five, (V) "E");  // reuses last in next list
+
         assertEquals(4, map.data.length);
         assertEquals(3, map.size);
         assertEquals(null, map.header.next);
@@ -401,10 +421,10 @@
         assertEquals(five, map.data[hashIndex].key);
         assertEquals(four, map.data[hashIndex].next.key);
         assertEquals(three, map.data[hashIndex].next.next.key);
-        
+
         map.get(three);
         map.get(five);
-        
+
         assertEquals(4, map.data.length);
         assertEquals(3, map.size);
         assertEquals(null, map.header.next);
@@ -414,9 +434,9 @@
         assertEquals(five, map.data[hashIndex].key);
         assertEquals(four, map.data[hashIndex].next.key);
         assertEquals(three, map.data[hashIndex].next.next.key);
-        
-        map.put(six, "F");  // reuses middle in next list
-        
+
+        map.put((K) six, (V) "F");  // reuses middle in next list
+
         assertEquals(4, map.data.length);
         assertEquals(3, map.size);
         assertEquals(null, map.header.next);
@@ -428,21 +448,18 @@
         assertEquals(three, map.data[hashIndex].next.next.key);
     }
 
+    @SuppressWarnings("unchecked")
     public void testInternalState_getEntry_int() {
         if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
         SingleHashCode one = new SingleHashCode("1");
         SingleHashCode two = new SingleHashCode("2");
         SingleHashCode three = new SingleHashCode("3");
-        SingleHashCode four = new SingleHashCode("4");
-        SingleHashCode five = new SingleHashCode("5");
-        SingleHashCode six = new SingleHashCode("6");
 
-        LRUMap map = new LRUMap(3, 1.0f);
-        int hashIndex = map.hashIndex(map.hash(one), 4);
-        map.put(one, "A");
-        map.put(two, "B");
-        map.put(three, "C");
-        
+        LRUMap<K, V> map = new LRUMap<K, V>(3, 1.0f);
+        map.put((K) one, (V) "A");
+        map.put((K) two, (V) "B");
+        map.put((K) three, (V) "C");
+
         assertEquals(one, map.getEntry(0).key);
         assertEquals(two, map.getEntry(1).key);
         assertEquals(three, map.getEntry(2).key);
@@ -787,4 +804,12 @@
 //        resetFull();
 //        writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LRUMap.fullCollection.version3.obj");
 //    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public LRUMap<K, V> getMap() {
+        return (LRUMap<K, V>) super.getMap();
+    }
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLinkedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLinkedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLinkedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestLinkedMap.java Tue Sep 15 05:29:56 2009
@@ -37,7 +37,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TestLinkedMap extends AbstractTestOrderedMap {
+public class TestLinkedMap<K, V> extends AbstractTestOrderedMap<K, V> {
 
     public TestLinkedMap(String testName) {
         super(testName);
@@ -46,127 +46,137 @@
     public static void main(String[] args) {
         TestRunner.run(suite());
     }
-    
+
     public static Test suite() {
         return BulkTest.makeSuite(TestLinkedMap.class);
     }
 
-    public Map makeEmptyMap() {
-        return new LinkedMap();
+    public LinkedMap<K, V> makeObject() {
+        return new LinkedMap<K, V>();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public LinkedMap<K, V> makeFullMap() {
+        return (LinkedMap<K, V>) super.makeFullMap();
     }
 
     public String getCompatibilityVersion() {
         return "3";
     }
 
-    //-----------------------------------------------------------------------    
+    //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testReset() {
         resetEmpty();
-        OrderedMap ordered = (OrderedMap) map;
-        ((ResettableIterator) ordered.mapIterator()).reset();
-        
+        OrderedMap<K, V> ordered = getMap();
+        ((ResettableIterator<K>) ordered.mapIterator()).reset();
+
         resetFull();
-        ordered = (OrderedMap) map;
-        List list = new ArrayList(ordered.keySet());
-        ResettableIterator it = (ResettableIterator) ordered.mapIterator();
+        ordered = getMap();
+        List<K> list = new ArrayList<K>(ordered.keySet());
+        ResettableIterator<K> it = (ResettableIterator<K>) ordered.mapIterator();
         assertSame(list.get(0), it.next());
         assertSame(list.get(1), it.next());
         it.reset();
         assertSame(list.get(0), it.next());
     }
-    
+
     //-----------------------------------------------------------------------
     public void testInsertionOrder() {
         if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
-        Object[] keys = getSampleKeys();
-        Object[] values = getSampleValues();
-        Iterator it = null;
-        
+        K[] keys = getSampleKeys();
+        V[] values = getSampleValues();
+        Iterator<K> keyIter;
+        Iterator<V> valueIter;
+
         resetEmpty();
         map.put(keys[0], values[0]);
         map.put(keys[1], values[1]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[1], it.next());
+        keyIter = map.keySet().iterator();
+        assertSame(keys[0], keyIter.next());
+        assertSame(keys[1], keyIter.next());
+        valueIter = map.values().iterator();
+        assertSame(values[0], valueIter.next());
+        assertSame(values[1], valueIter.next());
 
         // no change to order
         map.put(keys[1], values[1]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[1], it.next());
+        keyIter = map.keySet().iterator();
+        assertSame(keys[0], keyIter.next());
+        assertSame(keys[1], keyIter.next());
+        valueIter = map.values().iterator();
+        assertSame(values[0], valueIter.next());
+        assertSame(values[1], valueIter.next());
 
         // no change to order
         map.put(keys[1], values[2]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[0], it.next());
-        assertSame(values[2], it.next());
+        keyIter = map.keySet().iterator();
+        assertSame(keys[0], keyIter.next());
+        assertSame(keys[1], keyIter.next());
+        valueIter = map.values().iterator();
+        assertSame(values[0], valueIter.next());
+        assertSame(values[2], valueIter.next());
 
         // no change to order
         map.put(keys[0], values[3]);
-        it = map.keySet().iterator();
-        assertSame(keys[0], it.next());
-        assertSame(keys[1], it.next());
-        it = map.values().iterator();
-        assertSame(values[3], it.next());
-        assertSame(values[2], it.next());
+        keyIter = map.keySet().iterator();
+        assertSame(keys[0], keyIter.next());
+        assertSame(keys[1], keyIter.next());
+        valueIter = map.values().iterator();
+        assertSame(values[3], valueIter.next());
+        assertSame(values[2], valueIter.next());
     }
-    
+
     //-----------------------------------------------------------------------
     public void testGetByIndex() {
         resetEmpty();
-        LinkedMap lm = (LinkedMap) map;
+        LinkedMap<K, V> lm = getMap();
         try {
             lm.get(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lm.get(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lm = (LinkedMap) map;
+        lm = getMap();
         try {
             lm.get(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lm.get(lm.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         int i = 0;
-        for (MapIterator it = lm.mapIterator(); it.hasNext(); i++) {
+        for (MapIterator<K, V> it = lm.mapIterator(); it.hasNext(); i++) {
             assertSame(it.next(), lm.get(i));
         }
     }
 
     public void testGetValueByIndex() {
         resetEmpty();
-        LinkedMap lm = (LinkedMap) map;
+        LinkedMap<K, V> lm = getMap();
         try {
             lm.getValue(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lm.getValue(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lm = (LinkedMap) map;
+        lm = getMap();
         try {
             lm.getValue(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lm.getValue(lm.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         int i = 0;
-        for (MapIterator it = lm.mapIterator(); it.hasNext(); i++) {
+        for (MapIterator<K, V> it = lm.mapIterator(); it.hasNext(); i++) {
             it.next();
             assertSame(it.getValue(), lm.getValue(i));
         }
@@ -174,13 +184,13 @@
 
     public void testIndexOf() {
         resetEmpty();
-        LinkedMap lm = (LinkedMap) map;
+        LinkedMap<K, V> lm = getMap();
         assertEquals(-1, lm.indexOf(getOtherKeys()));
-        
+
         resetFull();
-        lm = (LinkedMap) map;
-        List list = new ArrayList();
-        for (MapIterator it = lm.mapIterator(); it.hasNext();) {
+        lm = getMap();
+        List<K> list = new ArrayList<K>();
+        for (MapIterator<K, V> it = lm.mapIterator(); it.hasNext();) {
             list.add(it.next());
         }
         for (int i = 0; i < list.size(); i++) {
@@ -190,25 +200,25 @@
 
     public void testRemoveByIndex() {
         resetEmpty();
-        LinkedMap lm = (LinkedMap) map;
+        LinkedMap<K, V> lm = getMap();
         try {
             lm.remove(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lm.remove(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lm = (LinkedMap) map;
+        lm = getMap();
         try {
             lm.remove(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lm.remove(lm.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
-        List list = new ArrayList();
-        for (MapIterator it = lm.mapIterator(); it.hasNext();) {
+
+        List<K> list = new ArrayList<K>();
+        for (MapIterator<K, V> it = lm.mapIterator(); it.hasNext();) {
             list.add(it.next());
         }
         for (int i = 0; i < list.size(); i++) {
@@ -219,26 +229,26 @@
             assertEquals(false, lm.containsKey(key));
         }
     }
-    
+
     public BulkTest bulkTestListView() {
         return new TestListView();
     }
-    
-    public class TestListView extends AbstractTestList {
-        
+
+    public class TestListView extends AbstractTestList<K> {
+
         TestListView() {
             super("TestListView");
         }
 
-        public List makeEmptyList() {
-            return ((LinkedMap) TestLinkedMap.this.makeEmptyMap()).asList();
+        public List<K> makeObject() {
+            return TestLinkedMap.this.makeObject().asList();
         }
-        
-        public List makeFullList() {
-            return ((LinkedMap) TestLinkedMap.this.makeFullMap()).asList();
+
+        public List<K> makeFullCollection() {
+            return TestLinkedMap.this.makeFullMap().asList();
         }
-        
-        public Object[] getFullElements() {
+
+        public K[] getFullElements() {
             return TestLinkedMap.this.getSampleKeys();
         }
         public boolean isAddSupported() {
@@ -258,18 +268,27 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void testClone() {
-        LinkedMap map = new LinkedMap(10);
-        map.put("1", "1");
-        Map cloned = (Map) map.clone();
+        LinkedMap<K, V> map = new LinkedMap<K, V>(10);
+        map.put((K) "1", (V) "1");
+        Map<K, V> cloned = map.clone();
         assertEquals(map.size(), cloned.size());
         assertSame(map.get("1"), cloned.get("1"));
     }
-    
+
 //    public void testCreate() throws Exception {
 //        resetEmpty();
 //        writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LinkedMap.emptyCollection.version3.obj");
 //        resetFull();
 //        writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LinkedMap.fullCollection.version3.obj");
 //    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public LinkedMap<K, V> getMap() {
+        return (LinkedMap<K, V>) super.getMap();
+    }
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap.java Tue Sep 15 05:29:56 2009
@@ -37,7 +37,7 @@
  * @author Stephen Colebourne
  * @author Matt Benson
  */
-public class TestListOrderedMap extends AbstractTestOrderedMap {
+public class TestListOrderedMap<K, V> extends AbstractTestOrderedMap<K, V> {
 
     public TestListOrderedMap(String testName) {
         super(testName);
@@ -52,57 +52,65 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    public Map makeEmptyMap() {
-        return ListOrderedMap.decorate(new HashMap());
+    public ListOrderedMap<K, V> makeObject() {
+        return (ListOrderedMap<K, V>) ListOrderedMap.decorate(new HashMap<K, V>());
     }
-    
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ListOrderedMap<K, V> makeFullMap() {
+        return (ListOrderedMap<K, V>) super.makeFullMap();
+    }
+
     //-----------------------------------------------------------------------
     public void testGetByIndex() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         try {
             lom.get(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.get(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
+        lom = getMap();
         try {
             lom.get(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.get(lom.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         int i = 0;
-        for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) {
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
             assertSame(it.next(), lom.get(i));
         }
     }
 
     public void testGetValueByIndex() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         try {
             lom.getValue(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.getValue(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
+        lom = getMap();
         try {
             lom.getValue(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.getValue(lom.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         int i = 0;
-        for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) {
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
             it.next();
             assertSame(it.getValue(), lom.getValue(i));
         }
@@ -110,13 +118,13 @@
 
     public void testIndexOf() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         assertEquals(-1, lom.indexOf(getOtherKeys()));
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
-        List list = new ArrayList();
-        for (MapIterator it = lom.mapIterator(); it.hasNext();) {
+        lom = getMap();
+        List<K> list = new ArrayList<K>();
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext();) {
             list.add(it.next());
         }
         for (int i = 0; i < list.size(); i++) {
@@ -124,54 +132,55 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void testSetValueByIndex() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         try {
-            lom.setValue(0, "");
+            lom.setValue(0, (V) "");
         } catch (IndexOutOfBoundsException ex) {}
         try {
-            lom.setValue(-1, "");
+            lom.setValue(-1, (V) "");
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
+        lom = getMap();
         try {
-            lom.setValue(-1, "");
+            lom.setValue(-1, (V) "");
         } catch (IndexOutOfBoundsException ex) {}
         try {
-            lom.setValue(lom.size(), "");
+            lom.setValue(lom.size(), (V) "");
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         for (int i = 0; i < lom.size(); i++) {
-            Object value = lom.getValue(i);
+            V value = lom.getValue(i);
             Object input = new Integer(i);
-            assertEquals(value, lom.setValue(i, input));
+            assertEquals(value, lom.setValue(i, (V) input));
             assertEquals(input, lom.getValue(i));
         }
     }
 
     public void testRemoveByIndex() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         try {
             lom.remove(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.remove(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
+        lom = getMap();
         try {
             lom.remove(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.remove(lom.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
-        List list = new ArrayList();
-        for (MapIterator it = lom.mapIterator(); it.hasNext();) {
+
+        List<K> list = new ArrayList<K>();
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext();) {
             list.add(it.next());
         }
         for (int i = 0; i < list.size(); i++) {
@@ -183,74 +192,75 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void testPut_intObjectObject() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
-        
+        ListOrderedMap<K, V> lom = getMap();
+
         try {
-            lom.put(1, "testInsert1", "testInsert1v");
+            lom.put(1, (K) "testInsert1", (V) "testInsert1v");
             fail("should not be able to insert at pos 1 in empty Map");
         } catch (IndexOutOfBoundsException ex) {}
         try {
-            lom.put(-1, "testInsert-1", "testInsert-1v");
+            lom.put(-1, (K) "testInsert-1", (V) "testInsert-1v");
             fail("should not be able to insert at pos -1 in empty Map");
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         // put where key doesn't exist
-        lom.put(0, "testInsert1", "testInsert1v");
+        lom.put(0, (K) "testInsert1", (V) "testInsert1v");
         assertEquals("testInsert1v", lom.getValue(0));
-        
-        lom.put("testInsertPut", "testInsertPutv");
+
+        lom.put((K) "testInsertPut", (V) "testInsertPutv");
         assertEquals("testInsert1v", lom.getValue(0));
         assertEquals("testInsertPutv", lom.getValue(1));
-        
-        lom.put(0, "testInsert0", "testInsert0v");
+
+        lom.put(0, (K) "testInsert0", (V) "testInsert0v");
         assertEquals("testInsert0v", lom.getValue(0));
         assertEquals("testInsert1v", lom.getValue(1));
         assertEquals("testInsertPutv", lom.getValue(2));
-        
-        lom.put(3, "testInsert3", "testInsert3v");
+
+        lom.put(3, (K) "testInsert3", (V) "testInsert3v");
         assertEquals("testInsert0v", lom.getValue(0));
         assertEquals("testInsert1v", lom.getValue(1));
         assertEquals("testInsertPutv", lom.getValue(2));
         assertEquals("testInsert3v", lom.getValue(3));
-        
-        // put in a full map        
+
+        // put in a full map
         resetFull();
-        lom = (ListOrderedMap) map;
-        ListOrderedMap lom2 = new ListOrderedMap();
+        lom = getMap();
+        ListOrderedMap<K, V> lom2 = new ListOrderedMap<K, V>();
         lom2.putAll(lom);
-        
-        lom2.put(0, "testInsert0", "testInsert0v");
+
+        lom2.put(0, (K) "testInsert0", (V) "testInsert0v");
         assertEquals("testInsert0v", lom2.getValue(0));
         for (int i = 0; i < lom.size(); i++) {
             assertEquals(lom2.getValue(i + 1), lom.getValue(i));
         }
-        
+
         // put where key does exist
         Integer i1 = new Integer(1);
         Integer i1b = new Integer(1);
         Integer i2 = new Integer(2);
         Integer i3 = new Integer(3);
-        
+
         resetEmpty();
-        lom = (ListOrderedMap) map;
-        lom.put(i1, "1");
-        lom.put(i2, "2");
-        lom.put(i3, "3");
-        lom.put(0, i1, "One");
+        lom = getMap();
+        lom.put((K) i1, (V) "1");
+        lom.put((K) i2, (V) "2");
+        lom.put((K) i3, (V) "3");
+        lom.put(0, (K) i1, (V) "One");
         assertEquals(3, lom.size());
         assertEquals(3, lom.map.size());
         assertEquals(3, lom.insertOrder.size());
         assertEquals("One", lom.getValue(0));
         assertSame(i1, lom.get(0));
-        
+
         resetEmpty();
-        lom = (ListOrderedMap) map;
-        lom.put(i1, "1");
-        lom.put(i2, "2");
-        lom.put(i3, "3");
-        lom.put(0, i1b, "One");
+        lom = getMap();
+        lom.put((K) i1, (V) "1");
+        lom.put((K) i2, (V) "2");
+        lom.put((K) i3, (V) "3");
+        lom.put(0, (K) i1b, (V) "One");
         assertEquals(3, lom.size());
         assertEquals(3, lom.map.size());
         assertEquals(3, lom.insertOrder.size());
@@ -258,39 +268,39 @@
         assertEquals("2", lom.getValue(1));
         assertEquals("3", lom.getValue(2));
         assertSame(i1b, lom.get(0));
-        
+
         resetEmpty();
-        lom = (ListOrderedMap) map;
-        lom.put(i1, "1");
-        lom.put(i2, "2");
-        lom.put(i3, "3");
-        lom.put(1, i1b, "One");
+        lom = getMap();
+        lom.put((K) i1, (V) "1");
+        lom.put((K) i2, (V) "2");
+        lom.put((K) i3, (V) "3");
+        lom.put(1, (K) i1b, (V) "One");
         assertEquals(3, lom.size());
         assertEquals(3, lom.map.size());
         assertEquals(3, lom.insertOrder.size());
         assertEquals("One", lom.getValue(0));
         assertEquals("2", lom.getValue(1));
         assertEquals("3", lom.getValue(2));
-        
+
         resetEmpty();
-        lom = (ListOrderedMap) map;
-        lom.put(i1, "1");
-        lom.put(i2, "2");
-        lom.put(i3, "3");
-        lom.put(2, i1b, "One");
+        lom = getMap();
+        lom.put((K) i1, (V) "1");
+        lom.put((K) i2, (V) "2");
+        lom.put((K) i3, (V) "3");
+        lom.put(2, (K) i1b, (V) "One");
         assertEquals(3, lom.size());
         assertEquals(3, lom.map.size());
         assertEquals(3, lom.insertOrder.size());
         assertEquals("2", lom.getValue(0));
         assertEquals("One", lom.getValue(1));
         assertEquals("3", lom.getValue(2));
-        
+
         resetEmpty();
-        lom = (ListOrderedMap) map;
-        lom.put(i1, "1");
-        lom.put(i2, "2");
-        lom.put(i3, "3");
-        lom.put(3, i1b, "One");
+        lom = getMap();
+        lom.put((K) i1, (V) "1");
+        lom.put((K) i2, (V) "2");
+        lom.put((K) i3, (V) "3");
+        lom.put(3, (K) i1b, (V) "One");
         assertEquals(3, lom.size());
         assertEquals(3, lom.map.size());
         assertEquals(3, lom.insertOrder.size());
@@ -328,20 +338,21 @@
     //-----------------------------------------------------------------------
     public void testValueList_getByIndex() {
         resetFull();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         for (int i = 0; i < lom.size(); i++) {
-            Object expected = lom.getValue(i);
+            V expected = lom.getValue(i);
             assertEquals(expected, lom.valueList().get(i));
         }
     }
 
+    @SuppressWarnings("unchecked")
     public void testValueList_setByIndex() {
         resetFull();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         for (int i = 0; i < lom.size(); i++) {
             Object input = new Integer(i);
-            Object expected = lom.getValue(i);
-            assertEquals(expected, lom.valueList().set(i, input));
+            V expected = lom.getValue(i);
+            assertEquals(expected, lom.valueList().set(i, (V) input));
             assertEquals(input, lom.getValue(i));
             assertEquals(input, lom.valueList().get(i));
         }
@@ -349,9 +360,9 @@
 
     public void testValueList_removeByIndex() {
         resetFull();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         while (lom.size() > 1) {
-            Object expected = lom.getValue(1);
+            V expected = lom.getValue(1);
             assertEquals(expected, lom.valueList().remove(1));
         }
     }
@@ -366,19 +377,19 @@
     }
 
     //-----------------------------------------------------------------------
-    public class TestKeyListView extends AbstractTestList {
+    public class TestKeyListView extends AbstractTestList<K> {
         TestKeyListView() {
             super("TestKeyListView");
         }
 
-        public List makeEmptyList() {
-            return ((ListOrderedMap) TestListOrderedMap.this.makeEmptyMap()).keyList();
+        public List<K> makeObject() {
+            return TestListOrderedMap.this.makeObject().keyList();
         }
-        public List makeFullList() {
-            return ((ListOrderedMap) TestListOrderedMap.this.makeFullMap()).keyList();
+        public List<K> makeFullCollection() {
+            return TestListOrderedMap.this.makeFullMap().keyList();
         }
 
-        public Object[] getFullElements() {
+        public K[] getFullElements() {
             return TestListOrderedMap.this.getSampleKeys();
         }
         public boolean isAddSupported() {
@@ -399,19 +410,19 @@
     }
 
     //-----------------------------------------------------------------------
-    public class TestValueListView extends AbstractTestList {
+    public class TestValueListView extends AbstractTestList<V> {
         TestValueListView() {
             super("TestValueListView");
         }
 
-        public List makeEmptyList() {
-            return ((ListOrderedMap) TestListOrderedMap.this.makeEmptyMap()).valueList();
+        public List<V> makeObject() {
+            return TestListOrderedMap.this.makeObject().valueList();
         }
-        public List makeFullList() {
-            return ((ListOrderedMap) TestListOrderedMap.this.makeFullMap()).valueList();
+        public List<V> makeFullCollection() {
+            return TestListOrderedMap.this.makeFullMap().valueList();
         }
 
-        public Object[] getFullElements() {
+        public V[] getFullElements() {
             return TestListOrderedMap.this.getSampleValues();
         }
         public boolean isAddSupported() {
@@ -446,4 +457,12 @@
 //            (java.io.Serializable) map,
 //            "D:/dev/collections/data/test/ListOrderedMap.fullCollection.version3.1.obj");
 //    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ListOrderedMap<K, V> getMap() {
+        return (ListOrderedMap<K, V>) super.getMap();
+    }
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap2.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap2.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap2.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestListOrderedMap2.java Tue Sep 15 05:29:56 2009
@@ -18,7 +18,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import junit.framework.Test;
 
@@ -35,7 +34,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TestListOrderedMap2 extends AbstractTestOrderedMap {
+public class TestListOrderedMap2<K, V> extends AbstractTestOrderedMap<K, V> {
 
     public TestListOrderedMap2(String testName) {
         super(testName);
@@ -50,57 +49,65 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    public Map makeEmptyMap() {
-        return new ListOrderedMap();
+    public ListOrderedMap<K, V> makeObject() {
+        return new ListOrderedMap<K, V>();
     }
-    
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ListOrderedMap<K, V> makeFullMap() {
+        return (ListOrderedMap<K, V>) super.makeFullMap();
+    }
+
     //-----------------------------------------------------------------------
     public void testGetByIndex() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         try {
             lom.get(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.get(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
+        lom = getMap();
         try {
             lom.get(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.get(lom.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         int i = 0;
-        for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) {
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
             assertSame(it.next(), lom.get(i));
         }
     }
 
     public void testGetValueByIndex() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         try {
             lom.getValue(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.getValue(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
+        lom = getMap();
         try {
             lom.getValue(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.getValue(lom.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         int i = 0;
-        for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) {
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
             it.next();
             assertSame(it.getValue(), lom.getValue(i));
         }
@@ -108,13 +115,13 @@
 
     public void testIndexOf() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         assertEquals(-1, lom.indexOf(getOtherKeys()));
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
-        List list = new ArrayList();
-        for (MapIterator it = lom.mapIterator(); it.hasNext();) {
+        lom = getMap();
+        List<K> list = new ArrayList<K>();
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext();) {
             list.add(it.next());
         }
         for (int i = 0; i < list.size(); i++) {
@@ -124,25 +131,25 @@
 
     public void testRemoveByIndex() {
         resetEmpty();
-        ListOrderedMap lom = (ListOrderedMap) map;
+        ListOrderedMap<K, V> lom = getMap();
         try {
             lom.remove(0);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.remove(-1);
         } catch (IndexOutOfBoundsException ex) {}
-        
+
         resetFull();
-        lom = (ListOrderedMap) map;
+        lom = getMap();
         try {
             lom.remove(-1);
         } catch (IndexOutOfBoundsException ex) {}
         try {
             lom.remove(lom.size());
         } catch (IndexOutOfBoundsException ex) {}
-        
-        List list = new ArrayList();
-        for (MapIterator it = lom.mapIterator(); it.hasNext();) {
+
+        List<K> list = new ArrayList<K>();
+        for (MapIterator<K, V> it = lom.mapIterator(); it.hasNext();) {
             list.add(it.next());
         }
         for (int i = 0; i < list.size(); i++) {
@@ -153,26 +160,26 @@
             assertEquals(false, lom.containsKey(key));
         }
     }
-    
+
     public BulkTest bulkTestListView() {
         return new TestListView();
     }
-    
-    public class TestListView extends AbstractTestList {
-        
+
+    public class TestListView extends AbstractTestList<K> {
+
         TestListView() {
             super("TestListView");
         }
 
-        public List makeEmptyList() {
-            return ((ListOrderedMap) TestListOrderedMap2.this.makeEmptyMap()).asList();
+        public List<K> makeObject() {
+            return TestListOrderedMap2.this.makeObject().asList();
         }
-        
-        public List makeFullList() {
-            return ((ListOrderedMap) TestListOrderedMap2.this.makeFullMap()).asList();
+
+        public List<K> makeFullCollection() {
+            return TestListOrderedMap2.this.makeFullMap().asList();
         }
-        
-        public Object[] getFullElements() {
+
+        public K[] getFullElements() {
             return TestListOrderedMap2.this.getSampleKeys();
         }
         public boolean isAddSupported() {
@@ -206,4 +213,13 @@
 //            (java.io.Serializable) map,
 //            "D:/dev/collections/data/test/ListOrderedMap.fullCollection.version3.1.obj");
 //    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public ListOrderedMap<K, V> getMap() {
+        // TODO Auto-generated method stub
+        return (ListOrderedMap<K, V>) super.getMap();
+    }
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestMultiKeyMap.java Tue Sep 15 05:29:56 2009
@@ -32,8 +32,8 @@
  *
  * @author Stephen Colebourne
  */
-public class TestMultiKeyMap extends AbstractTestIterableMap {
-    
+public class TestMultiKeyMap<K, V> extends AbstractTestIterableMap<MultiKey<? extends K>, V> {
+
     static final Integer I1 = new Integer(1);
     static final Integer I2 = new Integer(2);
     static final Integer I3 = new Integer(3);
@@ -55,15 +55,16 @@
         return BulkTest.makeSuite(TestMultiKeyMap.class);
     }
 
-    public Map makeEmptyMap() {
-        return new MultiKeyMap();
+    public MultiKeyMap<K, V> makeObject() {
+        return new MultiKeyMap<K, V>();
     }
 
-    public Object[] getSampleKeys() {
+    public MultiKey<K>[] getSampleKeys() {
         return getMultiKeyKeys();
     }
 
-    private MultiKey[] getMultiKeyKeys() {
+    @SuppressWarnings("unchecked")
+    private MultiKey<K>[] getMultiKeyKeys() {
         return new MultiKey[] {
             new MultiKey(I1, I2),
             new MultiKey(I2, I3),
@@ -80,8 +81,9 @@
         };
     }
 
-    public Object[] getSampleValues() {
-        return new Object[] {
+    @SuppressWarnings("unchecked")
+    public V[] getSampleValues() {
+        return (V[]) new Object[] {
             "2A", "2B", "2C",
             "3D", "3E", "3F",
             "4G", "4H", "4I",
@@ -89,8 +91,9 @@
         };
     }
 
-    public Object[] getNewSampleValues() {
-        return new Object[] {
+    @SuppressWarnings("unchecked")
+    public V[] getNewSampleValues() {
+        return (V[]) new Object[] {
             "1a", "1b", "1c",
             "2d", "2e", "2f",
             "3g", "3h", "3i",
@@ -98,20 +101,22 @@
         };
     }
 
-    public Object[] getOtherKeys() {
-        return new Object[] {
+    @SuppressWarnings("unchecked")
+    public MultiKey<K>[] getOtherKeys() {
+        return (MultiKey<K>[]) new MultiKey[] {
             new MultiKey(I1, I7),
             new MultiKey(I1, I8),
             new MultiKey(I2, I4),
             new MultiKey(I2, I5),
         };
     }
-    
+
     public boolean isAllowNullKey() {
         return false;
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testNullHandling() {
         resetFull();
         assertEquals(null, map.get(null));
@@ -125,9 +130,9 @@
             map.put(null, null);
             fail();
         } catch (NullPointerException ex) {}
-        assertEquals(null, map.put(new MultiKey(null, null), null));
+        assertEquals(null, map.put(new MultiKey<K>(null, null), null));
         try {
-            map.put(null, new Object());
+            map.put(null, (V) new Object());
             fail();
         } catch (NullPointerException ex) {}
     }
@@ -135,14 +140,14 @@
     //-----------------------------------------------------------------------
     public void testMultiKeyGet() {
         resetFull();
-        MultiKeyMap multimap = (MultiKeyMap) map;
-        MultiKey[] keys = getMultiKeyKeys();
-        Object[] values = getSampleValues();
-        
+        MultiKeyMap<K, V> multimap = getMap();
+        MultiKey<K>[] keys = getMultiKeyKeys();
+        V[] values = getSampleValues();
+
         for (int i = 0; i < keys.length; i++) {
-            MultiKey key = keys[i];
-            Object value = values[i];
-            
+            MultiKey<K> key = keys[i];
+            V value = values[i];
+
             switch (key.size()) {
                 case 2:
                 assertEquals(value, multimap.get(key.getKey(0), key.getKey(1)));
@@ -185,17 +190,15 @@
             }
         }
     }
-    
+
     public void testMultiKeyContainsKey() {
         resetFull();
-        MultiKeyMap multimap = (MultiKeyMap) map;
-        MultiKey[] keys = getMultiKeyKeys();
-        Object[] values = getSampleValues();
-        
+        MultiKeyMap<K, V> multimap = getMap();
+        MultiKey<K>[] keys = getMultiKeyKeys();
+
         for (int i = 0; i < keys.length; i++) {
-            MultiKey key = keys[i];
-            Object value = values[i];
-            
+            MultiKey<K> key = keys[i];
+
             switch (key.size()) {
                 case 2:
                 assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
@@ -238,24 +241,24 @@
             }
         }
     }
-    
+
     public void testMultiKeyPut() {
-        MultiKey[] keys = getMultiKeyKeys();
-        Object[] values = getSampleValues();
-        
+        MultiKey<K>[] keys = getMultiKeyKeys();
+        V[] values = getSampleValues();
+
         for (int i = 0; i < keys.length; i++) {
-            MultiKeyMap multimap = new MultiKeyMap();
-            
-            MultiKey key = keys[i];
-            Object value = values[i];
-            
+            MultiKeyMap<K, V> multimap = new MultiKeyMap<K, V>();
+
+            MultiKey<K> key = keys[i];
+            V value = values[i];
+
             switch (key.size()) {
                 case 2:
                 assertEquals(null, multimap.put(key.getKey(0), key.getKey(1), value));
                 assertEquals(1, multimap.size());
                 assertEquals(value, multimap.get(key.getKey(0), key.getKey(1)));
                 assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
-                assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1))));
+                assertEquals(true, multimap.containsKey(new MultiKey<K>(key.getKey(0), key.getKey(1))));
                 assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), null));
                 assertEquals(1, multimap.size());
                 assertEquals(null, multimap.get(key.getKey(0), key.getKey(1)));
@@ -266,7 +269,7 @@
                 assertEquals(1, multimap.size());
                 assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2)));
                 assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2)));
-                assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2))));
+                assertEquals(true, multimap.containsKey(new MultiKey<K>(key.getKey(0), key.getKey(1), key.getKey(2))));
                 assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), null));
                 assertEquals(1, multimap.size());
                 assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2)));
@@ -277,7 +280,7 @@
                 assertEquals(1, multimap.size());
                 assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
                 assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
-                assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))));
+                assertEquals(true, multimap.containsKey(new MultiKey<K>(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3))));
                 assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), null));
                 assertEquals(1, multimap.size());
                 assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3)));
@@ -288,7 +291,7 @@
                 assertEquals(1, multimap.size());
                 assertEquals(value, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
                 assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
-                assertEquals(true, multimap.containsKey(new MultiKey(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))));
+                assertEquals(true, multimap.containsKey(new MultiKey<K>(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4))));
                 assertEquals(value, multimap.put(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4), null));
                 assertEquals(1, multimap.size());
                 assertEquals(null, multimap.get(key.getKey(0), key.getKey(1), key.getKey(2), key.getKey(3), key.getKey(4)));
@@ -299,19 +302,19 @@
             }
         }
     }
-    
+
     public void testMultiKeyRemove() {
-        MultiKey[] keys = getMultiKeyKeys();
-        Object[] values = getSampleValues();
-        
+        MultiKey<K>[] keys = getMultiKeyKeys();
+        V[] values = getSampleValues();
+
         for (int i = 0; i < keys.length; i++) {
             resetFull();
-            MultiKeyMap multimap = (MultiKeyMap) map;
+            MultiKeyMap<K, V> multimap = getMap();
             int size = multimap.size();
-            
-            MultiKey key = keys[i];
-            Object value = values[i];
-            
+
+            MultiKey<K> key = keys[i];
+            V value = values[i];
+
             switch (key.size()) {
                 case 2:
                 assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
@@ -350,86 +353,88 @@
             }
         }
     }
-    
+
     public void testMultiKeyRemoveAll1() {
         resetFull();
-        MultiKeyMap multimap = (MultiKeyMap) map;
+        MultiKeyMap<K, V> multimap = getMap();
         assertEquals(12, multimap.size());
-        
+
         multimap.removeAll(I1);
         assertEquals(8, multimap.size());
-        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
-            MultiKey key = (MultiKey) it.next();
+        for (MapIterator<MultiKey<? extends K>, V> it = multimap.mapIterator(); it.hasNext();) {
+            MultiKey<? extends K> key = it.next();
             assertEquals(false, I1.equals(key.getKey(0)));
         }
     }
-    
+
     public void testMultiKeyRemoveAll2() {
         resetFull();
-        MultiKeyMap multimap = (MultiKeyMap) map;
+        MultiKeyMap<K, V> multimap = getMap();
         assertEquals(12, multimap.size());
-        
+
         multimap.removeAll(I2, I3);
         assertEquals(9, multimap.size());
-        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
-            MultiKey key = (MultiKey) it.next();
+        for (MapIterator<MultiKey<? extends K>, V> it = multimap.mapIterator(); it.hasNext();) {
+            MultiKey<? extends K> key = it.next();
             assertEquals(false, I2.equals(key.getKey(0)) && I3.equals(key.getKey(1)));
         }
     }
-    
+
     public void testMultiKeyRemoveAll3() {
         resetFull();
-        MultiKeyMap multimap = (MultiKeyMap) map;
+        MultiKeyMap<K, V> multimap = getMap();
         assertEquals(12, multimap.size());
-        
+
         multimap.removeAll(I1, I1, I2);
         assertEquals(9, multimap.size());
-        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
-            MultiKey key = (MultiKey) it.next();
+        for (MapIterator<MultiKey<? extends K>, V> it = multimap.mapIterator(); it.hasNext();) {
+            MultiKey<? extends K> key = it.next();
             assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2)));
         }
     }
-    
+
     public void testMultiKeyRemoveAll4() {
         resetFull();
-        MultiKeyMap multimap = (MultiKeyMap) map;
+        MultiKeyMap<K, V> multimap = getMap();
         assertEquals(12, multimap.size());
-        
+
         multimap.removeAll(I1, I1, I2, I3);
         assertEquals(10, multimap.size());
-        for (MapIterator it = multimap.mapIterator(); it.hasNext();) {
-            MultiKey key = (MultiKey) it.next();
+        for (MapIterator<MultiKey<? extends K>, V> it = multimap.mapIterator(); it.hasNext();) {
+            MultiKey<? extends K> key = it.next();
             assertEquals(false, I1.equals(key.getKey(0)) && I1.equals(key.getKey(1)) && I2.equals(key.getKey(2)) && key.size() >= 4 && I3.equals(key.getKey(3)));
         }
     }
-    
+
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testClone() {
-        MultiKeyMap map = new MultiKeyMap();
-        map.put(new MultiKey(I1, I2), "1-2");
-        Map cloned = (Map) map.clone();
+        MultiKeyMap<K, V> map = new MultiKeyMap<K, V>();
+        map.put(new MultiKey<K>((K) I1, (K) I2), (V) "1-2");
+        Map<MultiKey<? extends K>, V> cloned = map.clone();
         assertEquals(map.size(), cloned.size());
-        assertSame(map.get(new MultiKey(I1, I2)), cloned.get(new MultiKey(I1, I2)));
+        assertSame(map.get(new MultiKey<K>((K) I1, (K) I2)), cloned.get(new MultiKey<K>((K) I1, (K) I2)));
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testLRUMultiKeyMap() {
-        MultiKeyMap map = MultiKeyMap.decorate(new LRUMap(2));
-        map.put(I1, I2, "1-2");
-        map.put(I1, I3, "1-3");
+        MultiKeyMap<K, V> map = MultiKeyMap.decorate(new LRUMap<MultiKey<? extends K>, V>(2));
+        map.put((K) I1, (K) I2, (V) "1-2");
+        map.put((K) I1, (K) I3, (V) "1-1");
         assertEquals(2, map.size());
-        map.put(I1, I4, "1-4");
+        map.put((K) I1, (K) I4, (V) "1-4");
         assertEquals(2, map.size());
         assertEquals(true, map.containsKey(I1, I3));
         assertEquals(true, map.containsKey(I1, I4));
         assertEquals(false, map.containsKey(I1, I2));
-        
-        MultiKeyMap cloned = (MultiKeyMap) map.clone();
+
+        MultiKeyMap<K, V> cloned = map.clone();
         assertEquals(2, map.size());
         assertEquals(true, cloned.containsKey(I1, I3));
         assertEquals(true, cloned.containsKey(I1, I4));
         assertEquals(false, cloned.containsKey(I1, I2));
-        cloned.put(I1, I5, "1-5");
+        cloned.put((K) I1, (K) I5, (V) "1-5");
         assertEquals(2, cloned.size());
         assertEquals(true, cloned.containsKey(I1, I4));
         assertEquals(true, cloned.containsKey(I1, I5));
@@ -450,4 +455,12 @@
 //            (java.io.Serializable) map,
 //            "D:/dev/collections/data/test/MultiKeyMap.fullCollection.version3.1.obj");
 //    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public MultiKeyMap<K, V> getMap() {
+        return (MultiKeyMap<K, V>) super.getMap();
+    }
 }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestPredicatedSortedMap.java Tue Sep 15 05:29:56 2009
@@ -27,10 +27,10 @@
 import junit.framework.TestSuite;
 
 import org.apache.commons.collections.Predicate;
-import org.apache.commons.collections.PredicateUtils;
+import org.apache.commons.collections.functors.TruePredicate;
 
 /**
- * Extension of {@link TestPredicatedMap} for exercising the 
+ * Extension of {@link TestPredicatedMap} for exercising the
  * {@link PredicatedSortedMap} implementation.
  *
  * @since Commons Collections 3.0
@@ -38,46 +38,43 @@
  *
  * @author Phil Steitz
  */
-public class TestPredicatedSortedMap extends AbstractTestSortedMap{
-    
-    protected static final Predicate truePredicate = PredicateUtils.truePredicate();
-    protected static final Predicate testPredicate = new Predicate() {
+public class TestPredicatedSortedMap<K, V> extends AbstractTestSortedMap<K, V> {
+
+    protected static final Predicate<Object> truePredicate = TruePredicate.truePredicate();
+
+    protected static final Predicate<Object> testPredicate = new Predicate<Object>() {
         public boolean evaluate(Object o) {
             return (o instanceof String);
         }
     };
-    
+
     public TestPredicatedSortedMap(String testName) {
         super(testName);
     }
-    
+
     public static Test suite() {
         return new TestSuite(TestPredicatedSortedMap.class);
     }
-    
+
     public static void main(String args[]) {
         String[] testCaseName = { TestPredicatedSortedMap.class.getName()};
         junit.textui.TestRunner.main(testCaseName);
     }
 
     //-----------------------------------------------------------------------
-    protected SortedMap decorateMap(SortedMap map, Predicate keyPredicate, 
-        Predicate valuePredicate) {
+    protected SortedMap<K, V> decorateMap(SortedMap<K, V> map, Predicate<? super K> keyPredicate,
+        Predicate<? super V> valuePredicate) {
         return PredicatedSortedMap.decorate(map, keyPredicate, valuePredicate);
     }
-    
-    public Map makeEmptyMap() {
-        return decorateMap(new TreeMap(), truePredicate, truePredicate);
-    }
-   
-    public Map makeTestMap() {
-        return decorateMap(new TreeMap(), testPredicate, testPredicate);
-    } 
-    
-    public SortedMap makeTestSortedMap() {
-        return decorateMap(new TreeMap(), testPredicate, testPredicate);
+
+    public SortedMap<K, V> makeObject() {
+        return decorateMap(new TreeMap<K, V>(), truePredicate, truePredicate);
     }
-    
+
+    public SortedMap<K, V> makeTestMap() {
+        return decorateMap(new TreeMap<K, V>(), testPredicate, testPredicate);
+    }
+
     public boolean isSubMapViewsSerializable() {
         // TreeMap sub map views have a bug in deserialization.
         return false;
@@ -89,28 +86,30 @@
 
     // from TestPredicatedMap
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testEntrySet() {
-        SortedMap map = makeTestSortedMap();
+        SortedMap<K, V> map = makeTestMap();
         assertTrue("returned entryset should not be null",
             map.entrySet() != null);
-        map = decorateMap(new TreeMap(), null, null);
-        map.put("oneKey", "oneValue");
+        map = decorateMap(new TreeMap<K, V>(), null, null);
+        map.put((K) "oneKey", (V) "oneValue");
         assertTrue("returned entryset should contain one entry",
-            map.entrySet().size() == 1); 
+            map.entrySet().size() == 1);
         map = decorateMap(map, null, null);
     }
-    
+
+    @SuppressWarnings("unchecked")
     public void testPut() {
-        Map map = makeTestMap();
+        Map<K, V> map = makeTestMap();
         try {
-            map.put("Hi", new Integer(3));
+            map.put((K) "Hi", (V) new Integer(3));
             fail("Illegal value should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
         }
 
         try {
-            map.put(new Integer(3), "Hi");
+            map.put((K) new Integer(3), (V) "Hi");
             fail("Illegal key should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
@@ -119,11 +118,11 @@
         assertTrue(!map.containsKey(new Integer(3)));
         assertTrue(!map.containsValue(new Integer(3)));
 
-        Map map2 = new HashMap();
-        map2.put("A", "a");
-        map2.put("B", "b");
-        map2.put("C", "c");
-        map2.put("c", new Integer(3));
+        Map<K, V> map2 = new HashMap<K, V>();
+        map2.put((K) "A", (V) "a");
+        map2.put((K) "B", (V) "b");
+        map2.put((K) "C", (V) "c");
+        map2.put((K) "c", (V) new Integer(3));
 
         try {
             map.putAll(map2);
@@ -132,52 +131,53 @@
             // expected
         }
 
-        map.put("E", "e");
-        Iterator iterator = map.entrySet().iterator();
+        map.put((K) "E", (V) "e");
+        Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
         try {
-            Map.Entry entry = (Map.Entry)iterator.next();
-            entry.setValue(new Integer(3));
+            Map.Entry<K, V> entry = iterator.next();
+            entry.setValue((V) new Integer(3));
             fail("Illegal value should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
         }
-        
-        map.put("F", "f");
+
+        map.put((K) "F", (V) "f");
         iterator = map.entrySet().iterator();
-        Map.Entry entry = (Map.Entry)iterator.next();
-        entry.setValue("x");
-        
+        Map.Entry<K, V> entry = iterator.next();
+        entry.setValue((V) "x");
+
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testSortOrder() {
-        SortedMap map = makeTestSortedMap();
-        map.put("A",  "a");
-        map.put("B", "b");
+        SortedMap<K, V> map = makeTestMap();
+        map.put((K) "A",  (V) "a");
+        map.put((K) "B", (V) "b");
         try {
-            map.put(null, "c");
+            map.put(null, (V) "c");
             fail("Null key should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
         }
-        map.put("C", "c");
+        map.put((K) "C", (V) "c");
         try {
-            map.put("D", null);
+            map.put((K) "D", null);
             fail("Null value should raise IllegalArgument");
         } catch (IllegalArgumentException e) {
             // expected
         }
         assertEquals("First key should be A", "A", map.firstKey());
         assertEquals("Last key should be C", "C", map.lastKey());
-        assertEquals("First key in tail map should be B", 
-            "B", map.tailMap("B").firstKey());
-        assertEquals("Last key in head map should be B", 
-            "B", map.headMap("C").lastKey());
+        assertEquals("First key in tail map should be B",
+            "B", map.tailMap((K) "B").firstKey());
+        assertEquals("Last key in head map should be B",
+            "B", map.headMap((K) "C").lastKey());
         assertEquals("Last key in submap should be B",
-            "B", map.subMap("A","C").lastKey());
-        
-        Comparator c = map.comparator();
-        assertTrue("natural order, so comparator should be null", 
+           "B", map.subMap((K) "A",(K) "C").lastKey());
+
+        Comparator<? super K> c = map.comparator();
+        assertTrue("natural order, so comparator should be null",
             c == null);
     }
 
@@ -195,4 +195,4 @@
 //            (java.io.Serializable) map,
 //            "D:/dev/collections/data/test/PredicatedSortedMap.fullCollection.version3.1.obj");
 //    }
-}
\ No newline at end of file
+}

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java?rev=814997&r1=814996&r2=814997&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java (original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestReferenceIdentityMap.java Tue Sep 15 05:29:56 2009
@@ -24,9 +24,10 @@
 
 import org.apache.commons.collections.BulkTest;
 import org.apache.commons.collections.IterableMap;
+import org.apache.commons.collections.map.AbstractReferenceMap.ReferenceStrength;
 
 /**
- * Tests for ReferenceIdentityMap. 
+ * Tests for ReferenceIdentityMap.
  *
  * @version $Revision$
  *
@@ -34,7 +35,7 @@
  * @author Stephen Colebourne
  * @author Guilhem Lavaux
  */
-public class TestReferenceIdentityMap extends AbstractTestIterableMap {
+public class TestReferenceIdentityMap<K, V> extends AbstractTestIterableMap<K, V> {
 
     private static final Integer I1A = new Integer(1);
     private static final Integer I1B = new Integer(1);
@@ -54,15 +55,15 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    public Map makeEmptyMap() {
-        ReferenceIdentityMap map = new ReferenceIdentityMap(ReferenceIdentityMap.WEAK, ReferenceIdentityMap.WEAK);
-        return map;
+    public ReferenceIdentityMap<K, V> makeObject() {
+        return new ReferenceIdentityMap<K, V>(ReferenceStrength.WEAK, ReferenceStrength.WEAK);
     }
-    
-    public Map makeConfirmedMap() {
+
+    public Map<K, V> makeConfirmedMap() {
         // Testing against another [collections] class generally isn't a good idea,
-        // but the alternative is a JDK1.4 dependency in the tests
-        return new IdentityMap();
+        // but the closest alternative is IdentityHashMap, which propagates reference-equality down to keySet and values.
+        // arguably ReferenceIdentityMap should do the same but that's a later discussion.
+        return new IdentityMap<K, V>();
     }
 
     public boolean isAllowNullKey() {
@@ -78,11 +79,12 @@
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testBasics() {
-        IterableMap map = new ReferenceIdentityMap(ReferenceIdentityMap.HARD, ReferenceIdentityMap.HARD);
+        IterableMap<K, V> map = new ReferenceIdentityMap<K, V>(ReferenceStrength.HARD, ReferenceStrength.HARD);
         assertEquals(0, map.size());
-        
-        map.put(I1A, I2A);
+
+        map.put((K) I1A, (V) I2A);
         assertEquals(1, map.size());
         assertSame(I2A, map.get(I1A));
         assertSame(null, map.get(I1B));
@@ -90,8 +92,8 @@
         assertEquals(false, map.containsKey(I1B));
         assertEquals(true, map.containsValue(I2A));
         assertEquals(false, map.containsValue(I2B));
-        
-        map.put(I1A, I2B);
+
+        map.put((K) I1A, (V) I2B);
         assertEquals(1, map.size());
         assertSame(I2B, map.get(I1A));
         assertSame(null, map.get(I1B));
@@ -99,8 +101,8 @@
         assertEquals(false, map.containsKey(I1B));
         assertEquals(false, map.containsValue(I2A));
         assertEquals(true, map.containsValue(I2B));
-        
-        map.put(I1B, I2B);
+
+        map.put((K) I1B, (V) I2B);
         assertEquals(2, map.size());
         assertSame(I2B, map.get(I1A));
         assertSame(I2B, map.get(I1B));
@@ -109,45 +111,46 @@
         assertEquals(false, map.containsValue(I2A));
         assertEquals(true, map.containsValue(I2B));
     }
-    
+
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testHashEntry() {
-        IterableMap map = new ReferenceIdentityMap(ReferenceIdentityMap.HARD, ReferenceIdentityMap.HARD);
-        
-        map.put(I1A, I2A);
-        map.put(I1B, I2A);
-        
-        Map.Entry entry1 = (Map.Entry) map.entrySet().iterator().next();
-        Iterator it = map.entrySet().iterator();
-        Map.Entry entry2 = (Map.Entry) it.next();
-        Map.Entry entry3 = (Map.Entry) it.next();
-        
+        IterableMap<K, V> map = new ReferenceIdentityMap<K, V>(ReferenceStrength.HARD, ReferenceStrength.HARD);
+
+        map.put((K) I1A, (V) I2A);
+        map.put((K) I1B, (V) I2A);
+
+        Map.Entry<K, V> entry1 = map.entrySet().iterator().next();
+        Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
+        Map.Entry<K, V> entry2 = it.next();
+        Map.Entry<K, V> entry3 = it.next();
+
         assertEquals(true, entry1.equals(entry2));
         assertEquals(true, entry2.equals(entry1));
         assertEquals(false, entry1.equals(entry3));
     }
-    
-    
+
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testNullHandling() {
         resetFull();
-        assertEquals(null, map.get(null));
-        assertEquals(false, map.containsKey(null));
-        assertEquals(false, map.containsValue(null));
-        assertEquals(null, map.remove(null));
-        assertEquals(false, map.entrySet().contains(null));
-        assertEquals(false, map.keySet().contains(null));
-        assertEquals(false, map.values().contains(null));
+        assertEquals(null, getMap().get(null));
+        assertEquals(false, getMap().containsKey(null));
+        assertEquals(false, getMap().containsValue(null));
+        assertEquals(null, getMap().remove(null));
+        assertEquals(false, getMap().entrySet().contains(null));
+        assertEquals(false, getMap().keySet().contains(null));
+        assertEquals(false, getMap().values().contains(null));
         try {
-            map.put(null, null);
+            getMap().put(null, null);
             fail();
         } catch (NullPointerException ex) {}
         try {
-            map.put(new Object(), null);
+            getMap().put((K) new Object(), null);
             fail();
         } catch (NullPointerException ex) {}
         try {
-            map.put(null, new Object());
+            getMap().put(null, (V) new Object());
             fail();
         } catch (NullPointerException ex) {}
     }
@@ -263,19 +266,20 @@
     }
 */
 
-    WeakReference keyReference;
-    WeakReference valueReference;
+    WeakReference<K> keyReference;
+    WeakReference<V> valueReference;
+
+    @SuppressWarnings("unchecked")
+    private Map<K, V> buildRefMap() {
+        K key = (K) new Object();
+        V value = (V) new Object();
+
+        keyReference = new WeakReference<K>(key);
+        valueReference = new WeakReference<V>(value);
 
-    public Map buildRefMap() {
-        Object key = new Object();
-        Object value = new Object();
-        
-        keyReference = new WeakReference(key);
-        valueReference = new WeakReference(value);
-        
-        Map testMap = new ReferenceIdentityMap(ReferenceMap.WEAK, ReferenceMap.HARD, true);
+        Map<K, V> testMap = new ReferenceIdentityMap<K, V>(ReferenceStrength.WEAK, ReferenceStrength.HARD, true);
         testMap.put(key, value);
- 
+
         assertEquals("In map", value, testMap.get(key));
         assertNotNull("Weak reference released early (1)", keyReference.get());
         assertNotNull("Weak reference released early (2)", valueReference.get());
@@ -285,29 +289,31 @@
     /** Tests whether purge values setting works */
     public void testPurgeValues() throws Exception {
         // many thanks to Juozas Baliuka for suggesting this method
-        Map testMap = buildRefMap();
-        
+        Map<K, V> testMap = buildRefMap();
+
         int iterations = 0;
         int bytz = 2;
-        while(true) {
+        while (true) {
             System.gc();
-            if(iterations++ > 50){
+            if (iterations++ > 50) {
                 fail("Max iterations reached before resource released.");
             }
             testMap.isEmpty();
-            if( 
+            if (
                 keyReference.get() == null &&
                 valueReference.get() == null) {
                 break;
-                
+
             } else {
                 // create garbage:
+                @SuppressWarnings("unused")
                 byte[] b =  new byte[bytz];
                 bytz = bytz * 2;
             }
         }
     }
 
+    @SuppressWarnings("unused")
     private static void gc() {
         try {
             // trigger GC



Mime
View raw message