commons-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=815133&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:

    ------------------------------------------------------------------------
    r751858 | mbenson | 2009-03-09 14:45:53 -0700 (Mon, 09 Mar 2009) | 1 line
    
    generics
    ------------------------------------------------------------------------
    r740150 | mbenson | 2009-02-02 15:24:00 -0800 (Mon, 02 Feb 2009) | 1 line
    
    make all [collections] maps implement IterableMap
    ------------------------------------------------------------------------

Modified:
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestTransformedMap.java

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestTransformedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestTransformedMap.java?rev=815133&r1=815132&r2=815133&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestTransformedMap.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestTransformedMap.java
Tue Sep 15 05:57:39 2009
@@ -23,6 +23,8 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.commons.collections.IterableMap;
+import org.apache.commons.collections.Transformer;
 import org.apache.commons.collections.TransformerUtils;
 import org.apache.commons.collections.collection.TestTransformedCollection;
 
@@ -35,8 +37,8 @@
  *
  * @author Stephen Colebourne
  */
-public class TestTransformedMap extends AbstractTestMap {
-    
+public class TestTransformedMap<K, V> extends AbstractTestIterableMap<K, V> {
+
     public TestTransformedMap(String testName) {
         super(testName);
     }
@@ -51,32 +53,38 @@
     }
 
     //-----------------------------------------------------------------------
-    public Map makeEmptyMap() {
-        return TransformedMap.decorate(new HashMap(), TransformerUtils.nopTransformer(),
TransformerUtils.nopTransformer());
+    public IterableMap<K, V> makeObject() {
+        return TransformedMap.decorate(new HashMap<K, V>(), TransformerUtils.<K>
nopTransformer(),
+                TransformerUtils.<V> nopTransformer());
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testTransformedMap() {
-        Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
+        Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
 
-        Map map = TransformedMap.decorate(new HashMap(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER,
null);
+        Map<K, V> map = TransformedMap
+                .decorate(
+                        new HashMap<K, V>(),
+                        (Transformer<? super K, ? extends K>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER,
+                        null);
         assertEquals(0, map.size());
         for (int i = 0; i < els.length; i++) {
-            map.put(els[i], els[i]);
+            map.put((K) els[i], (V) els[i]);
             assertEquals(i + 1, map.size());
             assertEquals(true, map.containsKey(new Integer((String) els[i])));
             assertEquals(false, map.containsKey(els[i]));
             assertEquals(true, map.containsValue(els[i]));
             assertEquals(els[i], map.get(new Integer((String) els[i])));
         }
-        
+
         assertEquals(null, map.remove(els[0]));
         assertEquals(els[0], map.remove(new Integer((String) els[0])));
-        
+
         map = TransformedMap.decorate(new HashMap(), null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
         assertEquals(0, map.size());
         for (int i = 0; i < els.length; i++) {
-            map.put(els[i], els[i]);
+            map.put((K) els[i], (V) els[i]);
             assertEquals(i + 1, map.size());
             assertEquals(true, map.containsValue(new Integer((String) els[i])));
             assertEquals(false, map.containsValue(els[i]));
@@ -85,13 +93,13 @@
         }
 
         assertEquals(new Integer((String) els[0]), map.remove(els[0]));
-        
-        Set entrySet = map.entrySet();
-        Map.Entry[] array = (Map.Entry[]) entrySet.toArray(new Map.Entry[0]);
-        array[0].setValue("66");
+
+        Set<Map.Entry<K, V>> entrySet = map.entrySet();
+        Map.Entry<K, V>[] array = entrySet.toArray(new Map.Entry[0]);
+        array[0].setValue((V) "66");
         assertEquals(new Integer(66), array[0].getValue());
         assertEquals(new Integer(66), map.get(array[0].getKey()));
-        
+
         Map.Entry entry = (Map.Entry) entrySet.iterator().next();
         entry.setValue("88");
         assertEquals(new Integer(88), entry.getValue());
@@ -99,33 +107,43 @@
     }
 
     //-----------------------------------------------------------------------
+    @SuppressWarnings("unchecked")
     public void testFactory_Decorate() {
-        Map base = new HashMap();
-        base.put("A", "1");
-        base.put("B", "2");
-        base.put("C", "3");
-        
-        Map trans = TransformedMap.decorate(base, null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
+        Map<K, V> base = new HashMap<K, V>();
+        base.put((K) "A", (V) "1");
+        base.put((K) "B", (V) "2");
+        base.put((K) "C", (V) "3");
+
+        Map<K, V> trans = TransformedMap
+                .decorate(
+                        base,
+                        null,
+                        (Transformer<? super V, ? extends V>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
         assertEquals(3, trans.size());
         assertEquals("1", trans.get("A"));
         assertEquals("2", trans.get("B"));
         assertEquals("3", trans.get("C"));
-        trans.put("D", "4");
+        trans.put((K) "D", (V) "4");
         assertEquals(new Integer(4), trans.get("D"));
     }
 
+    @SuppressWarnings("unchecked")
     public void testFactory_decorateTransform() {
-        Map base = new HashMap();
-        base.put("A", "1");
-        base.put("B", "2");
-        base.put("C", "3");
-        
-        Map trans = TransformedMap.decorateTransform(base, null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
+        Map<K, V> base = new HashMap<K, V>();
+        base.put((K) "A", (V) "1");
+        base.put((K) "B", (V) "2");
+        base.put((K) "C", (V) "3");
+
+        Map<K, V> trans = TransformedMap
+                .decorateTransform(
+                        base,
+                        null,
+                        (Transformer<? super V, ? extends V>) TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
         assertEquals(3, trans.size());
         assertEquals(new Integer(1), trans.get("A"));
         assertEquals(new Integer(2), trans.get("B"));
         assertEquals(new Integer(3), trans.get("C"));
-        trans.put("D", "4");
+        trans.put((K) "D", (V) "4");
         assertEquals(new Integer(4), trans.get("D"));
     }
 



Mime
View raw message