commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r815085 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/TransformedSortedMap.java
Date Tue, 15 Sep 2009 05:56:18 GMT
Author: bayard
Date: Tue Sep 15 05:56:18 2009
New Revision: 815085

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

    ------------------------------------------------------------------------
    r471189 | scolebourne | 2006-11-04 05:57:57 -0800 (Sat, 04 Nov 2006) | 1 line
    
    Remove getMap(), getOrderedMap() and getSortedMap() - use decorated()
    ------------------------------------------------------------------------

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

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/TransformedSortedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/TransformedSortedMap.java?rev=815085&r1=815084&r2=815085&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/TransformedSortedMap.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/TransformedSortedMap.java
Tue Sep 15 05:56:18 2009
@@ -43,9 +43,9 @@
  *
  * @author Stephen Colebourne
  */
-public class TransformedSortedMap
-        extends TransformedMap
-        implements SortedMap {
+public class TransformedSortedMap<K, V>
+        extends TransformedMap<K, V>
+        implements SortedMap<K, V> {
 
     /** Serialization version */
     private static final long serialVersionUID = -8751771676410385778L;
@@ -62,8 +62,10 @@
      * @param valueTransformer  the predicate to validate to values, null means no transformation
      * @throws IllegalArgumentException if the map is null
      */
-    public static SortedMap decorate(SortedMap map, Transformer keyTransformer, Transformer
valueTransformer) {
-        return new TransformedSortedMap(map, keyTransformer, valueTransformer);
+    public static <K, V> SortedMap<K, V> decorate(SortedMap<K, V> map,
+            Transformer<? super K, ? extends K> keyTransformer,
+            Transformer<? super V, ? extends V> valueTransformer) {
+        return new TransformedSortedMap<K, V>(map, keyTransformer, valueTransformer);
     }
 
     /**
@@ -80,12 +82,14 @@
      * @throws IllegalArgumentException if map is null
      * @since Commons Collections 3.2
      */
-    public static SortedMap decorateTransform(SortedMap map, Transformer keyTransformer,
Transformer valueTransformer) {
-        TransformedSortedMap decorated = new TransformedSortedMap(map, keyTransformer, valueTransformer);
+    public static <K, V> SortedMap<K, V> decorateTransform(SortedMap<K, V>
map,
+            Transformer<? super K, ? extends K> keyTransformer,
+            Transformer<? super V, ? extends V> valueTransformer) {
+        TransformedSortedMap<K, V> decorated = new TransformedSortedMap<K, V>(map,
keyTransformer, valueTransformer);
         if (map.size() > 0) {
-            Map transformed = decorated.transformMap(map);
+            Map<K, V> transformed = decorated.transformMap(map);
             decorated.clear();
-            decorated.getMap().putAll(transformed);  // avoids double transformation
+            decorated.decorated().putAll(transformed);  // avoids double transformation
         }
         return decorated;
     }
@@ -102,7 +106,9 @@
      * @param valueTransformer  the predicate to validate to values, null means no transformation
      * @throws IllegalArgumentException if the map is null
      */
-    protected TransformedSortedMap(SortedMap map, Transformer keyTransformer, Transformer
valueTransformer) {
+    protected TransformedSortedMap(SortedMap<K, V> map,
+            Transformer<? super K, ? extends K> keyTransformer,
+            Transformer<? super V, ? extends V> valueTransformer) {
         super(map, keyTransformer, valueTransformer);
     }
 
@@ -112,36 +118,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 TransformedSortedMap(map, keyTransformer, valueTransformer);
+    public SortedMap<K, V> subMap(K fromKey, K toKey) {
+        SortedMap<K, V> map = getSortedMap().subMap(fromKey, toKey);
+        return new TransformedSortedMap<K, V>(map, keyTransformer, valueTransformer);
     }
 
-    public SortedMap headMap(Object toKey) {
-        SortedMap map = getSortedMap().headMap(toKey);
-        return new TransformedSortedMap(map, keyTransformer, valueTransformer);
+    public SortedMap<K, V> headMap(K toKey) {
+        SortedMap<K, V> map = getSortedMap().headMap(toKey);
+        return new TransformedSortedMap<K, V>(map, keyTransformer, valueTransformer);
     }
 
-    public SortedMap tailMap(Object fromKey) {
-        SortedMap map = getSortedMap().tailMap(fromKey);
-        return new TransformedSortedMap(map, keyTransformer, valueTransformer);
+    public SortedMap<K, V> tailMap(K fromKey) {
+        SortedMap<K, V> map = getSortedMap().tailMap(fromKey);
+        return new TransformedSortedMap<K, V>(map, keyTransformer, valueTransformer);
     }
 
 }



Mime
View raw message