commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skes...@apache.org
Subject svn commit: r572176 - in /commons/proper/collections/branches/collections_jdk5_branch/src: java/org/apache/commons/collections/map/ test/org/apache/commons/collections/map/
Date Sun, 02 Sep 2007 22:04:43 GMT
Author: skestle
Date: Sun Sep  2 15:04:41 2007
New Revision: 572176

URL: http://svn.apache.org/viewvc?rev=572176&view=rev
Log:
Generified LazySortedMap to fix build errors

Modified:
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazySortedMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazyMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazySortedMap.java

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazySortedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazySortedMap.java?rev=572176&r1=572175&r2=572176&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazySortedMap.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/LazySortedMap.java
Sun Sep  2 15:04:41 2007
@@ -58,9 +58,9 @@
  * @author Stephen Colebourne
  * @author Paul Jack
  */
-public class LazySortedMap
-        extends LazyMap<Object, Object>
-        implements SortedMap<Object, Object> {
+public class LazySortedMap<K,V>
+        extends LazyMap<K,V>
+        implements SortedMap<K,V> {
 
     /** Serialization version */
     private static final long serialVersionUID = 2715322183617658933L;
@@ -71,9 +71,11 @@
      * @param map  the map to decorate, must not be null
      * @param factory  the factory to use, must not be null
      * @throws IllegalArgumentException if map or factory is null
+     * @deprecated
      */
-    public static SortedMap decorate(SortedMap map, Factory factory) {
-        return new LazySortedMap(map, factory);
+    @Deprecated
+    public static <K,V> SortedMap<K,V> decorate(SortedMap<K,V> map, Factory<?
extends V> factory) {
+        return getLazySortedMap(map, factory);
     }
 
     /**
@@ -83,10 +85,34 @@
      * @param factory  the factory to use, must not be null
      * @throws IllegalArgumentException if map or factory is null
      */
-    public static SortedMap decorate(SortedMap map, Transformer factory) {
-        return new LazySortedMap(map, factory);
+	public static <K, V> SortedMap<K, V> getLazySortedMap(SortedMap<K, V>
map, Factory<? extends V> factory) {
+		return new LazySortedMap<K,V>(map, factory);
+	}
+
+	/**
+	 * Factory method to create a lazily instantiated sorted map.
+	 * 
+	 * @param map  the map to decorate, must not be null
+	 * @param factory  the factory to use, must not be null
+	 * @throws IllegalArgumentException if map or factory is null
+	 * @deprecated
+	 */
+	@Deprecated
+    public static <K,V> SortedMap<K,V> decorate(SortedMap<K,V> map, Transformer<?
super K, ? extends V> factory) {
+        return getLazySortedMap(map, factory);
     }
 
+    /**
+     * Factory method to create a lazily instantiated sorted map.
+     * 
+     * @param map  the map to decorate, must not be null
+     * @param factory  the factory to use, must not be null
+     * @throws IllegalArgumentException if map or factory is null
+     */
+	public static <K, V> SortedMap<K, V> getLazySortedMap(SortedMap<K, V>
map, Transformer<? super K, ? extends V> factory) {
+		return new LazySortedMap<K,V>(map, factory);
+	}
+
     //-----------------------------------------------------------------------
     /**
      * Constructor that wraps (not copies).
@@ -95,7 +121,7 @@
      * @param factory  the factory to use, must not be null
      * @throws IllegalArgumentException if map or factory is null
      */
-    protected LazySortedMap(SortedMap map, Factory factory) {
+    protected LazySortedMap(SortedMap<K,V> map, Factory<? extends V> factory)
{
         super(map, factory);
     }
 
@@ -106,7 +132,7 @@
      * @param factory  the factory to use, must not be null
      * @throws IllegalArgumentException if map or factory is null
      */
-    protected LazySortedMap(SortedMap map, Transformer factory) {
+    protected LazySortedMap(SortedMap<K,V> map, Transformer<? super K, ? extends
V> factory) {
         super(map, factory);
     }
 
@@ -116,36 +142,36 @@
      * 
      * @return the decorated map
      */
-    protected SortedMap getSortedMap() {
-        return (SortedMap) map;
+    protected SortedMap<K,V> getSortedMap() {
+        return (SortedMap<K,V>) map;
     }
 
     //-----------------------------------------------------------------------
-    public Object firstKey() {
+    public K firstKey() {
         return getSortedMap().firstKey();
     }
 
-    public Object lastKey() {
+    public K lastKey() {
         return getSortedMap().lastKey();
     }
 
-    public Comparator comparator() {
+    public Comparator<? super K> comparator() {
         return getSortedMap().comparator();
     }
 
-    public SortedMap subMap(Object fromKey, Object toKey) {
-        SortedMap map = getSortedMap().subMap(fromKey, toKey);
-        return new LazySortedMap(map, factory);
+    public SortedMap<K,V> subMap(K fromKey, K toKey) {
+        SortedMap<K,V> map = getSortedMap().subMap(fromKey, toKey);
+        return new LazySortedMap<K,V>(map, factory);
     }
 
-    public SortedMap headMap(Object toKey) {
-        SortedMap map = getSortedMap().headMap(toKey);
-        return new LazySortedMap(map, factory);
+    public SortedMap<K,V> headMap(K toKey) {
+        SortedMap<K,V> map = getSortedMap().headMap(toKey);
+        return new LazySortedMap<K,V>(map, factory);
     }
 
-    public SortedMap tailMap(Object fromKey) {
-        SortedMap map = getSortedMap().tailMap(fromKey);
-        return new LazySortedMap(map, factory);
+    public SortedMap<K,V> tailMap(K fromKey) {
+        SortedMap<K,V> map = getSortedMap().tailMap(fromKey);
+        return new LazySortedMap<K,V>(map, factory);
     }
 
 }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazyMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazyMap.java?rev=572176&r1=572175&r2=572176&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazyMap.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazyMap.java
Sun Sep  2 15:04:41 2007
@@ -38,7 +38,6 @@
 public class TestLazyMap extends AbstractTestMap {
     
 	private static final Factory<Integer> oneFactory = FactoryUtils.constantFactory(1);
-    private static final Factory<Object> nullFactory = FactoryUtils.nullFactory();
     
     public TestLazyMap(String testName) {
         super(testName);

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazySortedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazySortedMap.java?rev=572176&r1=572175&r2=572176&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazySortedMap.java
(original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestLazySortedMap.java
Sun Sep  2 15:04:41 2007
@@ -16,18 +16,18 @@
  */
 package org.apache.commons.collections.map;
 
+import static org.apache.commons.collections.map.LazySortedMap.getLazySortedMap;
+
 import java.util.Comparator;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
 import org.apache.commons.collections.Factory;
 import org.apache.commons.collections.FactoryUtils;
 import org.apache.commons.collections.Transformer;
 import org.apache.commons.collections.TransformerUtils;
+import org.junit.Test;
 
 /**
  * Extension of {@link TestLazyMap} for exercising the 
@@ -40,59 +40,54 @@
  */
 public class TestLazySortedMap extends AbstractTestSortedMap {
     
-    protected static final Factory oneFactory = FactoryUtils.constantFactory("One");
-    protected static final Factory nullFactory = FactoryUtils.nullFactory();
-    
+	private static final Factory<Integer> oneFactory = FactoryUtils.constantFactory(1);
+   
     public TestLazySortedMap(String testName) {
         super(testName);
     }
     
-    public static Test suite() {
-        return new TestSuite(TestLazySortedMap.class);
-    }
-    
     public static void main(String args[]) {
         String[] testCaseName = { TestLazySortedMap.class.getName()};
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    //-----------------------------------------------------------------------    
-    protected SortedMap decorateMap(SortedMap map, Factory factory) {
-        return LazySortedMap.decorate(map, factory);
-    }
-    
-    public Map makeEmptyMap() {
-        return decorateMap(new TreeMap(), nullFactory);
+    @Override
+	public <K,V> Map<K,V> makeEmptyMap() {
+        return getLazySortedMap(new TreeMap<K,V>(), FactoryUtils.<V>nullFactory());
     }
     
-    protected SortedMap makeTestSortedMap(Factory factory) {
-        return decorateMap(new TreeMap(), factory);
+    private <K,V> SortedMap<K,V> makeTestSortedMap(Factory<V> factory)
{
+        return getLazySortedMap(new TreeMap<K,V>(), factory);
     }
     
-    public boolean isSubMapViewsSerializable() {
-        // TreeMap sub map views have a bug in deserialization.
+    @Override
+	public boolean isSubMapViewsSerializable() {
+        // TODO TreeMap sub map views have a bug in deserialization.
         return false;
     }
 
-    public boolean isAllowNullKey() {
+    @Override
+	public boolean isAllowNullKey() {
         return false;
     }
 
     // from TestLazyMap
     //-----------------------------------------------------------------------
+    @Override
     public void testMapGet() {
-        Map map = makeTestSortedMap(oneFactory);
+    	//TODO eliminate need for this via superclass - see svn history.
+    }
+    
+    @Test
+    public void mapGet() {
+        Map<Integer, Number> map = getLazySortedMap(new TreeMap<Integer,Number>(),
oneFactory);
         assertEquals(0, map.size());
-        String s1 = (String) map.get("Five");
-        assertEquals("One", s1);
+        Number i1 = map.get(5);
+        assertEquals(1, i1);
         assertEquals(1, map.size());
-        String s2 = (String) map.get(new String(new char[] {'F','i','v','e'}));
-        assertEquals("One", s2);
-        assertEquals(1, map.size());
-        assertSame(s1, s2);
-        
-        map = makeTestSortedMap(nullFactory);
-        Object o = map.get("Five");
+
+        map = getLazySortedMap(new TreeMap<Integer,Number>(), FactoryUtils.<Number>nullFactory());
+        Number o = map.get(5);
         assertEquals(null,o);
         assertEquals(1, map.size());
         
@@ -100,10 +95,10 @@
     
     //-----------------------------------------------------------------------
     public void testSortOrder() {
-        SortedMap map = makeTestSortedMap(oneFactory);
-        map.put("A",  "a");
+        SortedMap<String, Number> map = getLazySortedMap(new TreeMap<String,Number>(),
oneFactory);
+        map.put("A",  5);
         map.get("B"); // Entry with value "One" created
-        map.put("C", "c");
+        map.put("C", 8);
         assertEquals("First key should be A", map.firstKey(), "A");
         assertEquals("Last key should be C", map.lastKey(), "C");
         assertEquals("First key in tail map should be B", 
@@ -113,30 +108,31 @@
         assertEquals("Last key in submap should be B",
            map.subMap("A","C").lastKey(), "B");
         
-        Comparator c = map.comparator();
+        Comparator<?> c = map.comparator();
         assertTrue("natural order, so comparator should be null", 
             c == null);      
     } 
     
     public void testTransformerDecorate() {
-        Transformer transformer = TransformerUtils.asTransformer(oneFactory);
-        SortedMap map = LazySortedMap.decorate(new TreeMap(), transformer);     
+        Transformer<Object, Integer> transformer = TransformerUtils.asTransformer(oneFactory);
+        SortedMap<Integer, Number> map = getLazySortedMap(new TreeMap<Integer, Number>(),
transformer);     
         assertTrue(map instanceof LazySortedMap);  
          try {
-            map = LazySortedMap.decorate(new TreeMap(), (Transformer) null);
+            map = getLazySortedMap(new TreeMap<Integer, Number>(), (Transformer<Integer,
Number>) null);
             fail("Expecting IllegalArgumentException for null transformer");
         } catch (IllegalArgumentException e) {
             // expected
         }
         try {
-            map = LazySortedMap.decorate(null, transformer);
+            map = getLazySortedMap((SortedMap<Integer,Number>) null, transformer);
             fail("Expecting IllegalArgumentException for null map");
         } catch (IllegalArgumentException e) {
             // expected
         } 
     }
     
-    public String getCompatibilityVersion() {
+    @Override
+	public String getCompatibilityVersion() {
         return "3.1";
     }
 



Mime
View raw message