commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/decorators LazySortedMap.java LazyMap.java
Date Sat, 17 May 2003 14:11:10 GMT
scolebourne    2003/05/17 07:11:10

  Modified:    collections/src/java/org/apache/commons/collections/decorators
                        LazySortedMap.java LazyMap.java
  Log:
  Hold a Transformer internally, as wrap Factory as Transformer
  
  Revision  Changes    Path
  1.2       +5 -17     jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/LazySortedMap.java
  
  Index: LazySortedMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/LazySortedMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LazySortedMap.java	9 May 2003 16:42:35 -0000	1.1
  +++ LazySortedMap.java	17 May 2003 14:11:09 -0000	1.2
  @@ -162,29 +162,17 @@
   
       public SortedMap subMap(Object fromKey, Object toKey) {
           SortedMap map = getSortedMap().subMap(fromKey, toKey);
  -        if (factory instanceof Factory) {
  -            return new LazySortedMap(map, (Factory) factory);
  -        } else {
  -            return new LazySortedMap(map, (Transformer) factory);
  -        }
  +        return new LazySortedMap(map, factory);
       }
   
       public SortedMap headMap(Object toKey) {
           SortedMap map = getSortedMap().headMap(toKey);
  -        if (factory instanceof Factory) {
  -            return new LazySortedMap(map, (Factory) factory);
  -        } else {
  -            return new LazySortedMap(map, (Transformer) factory);
  -        }
  +        return new LazySortedMap(map, factory);
       }
   
       public SortedMap tailMap(Object fromKey) {
           SortedMap map = getSortedMap().tailMap(fromKey);
  -        if (factory instanceof Factory) {
  -            return new LazySortedMap(map, (Factory) factory);
  -        } else {
  -            return new LazySortedMap(map, (Transformer) factory);
  -        }
  +        return new LazySortedMap(map, factory);
       }
   
   }
  
  
  
  1.2       +8 -13     jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/LazyMap.java
  
  Index: LazyMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/LazyMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LazyMap.java	9 May 2003 16:42:35 -0000	1.1
  +++ LazyMap.java	17 May 2003 14:11:10 -0000	1.2
  @@ -61,6 +61,7 @@
   
   import org.apache.commons.collections.Factory;
   import org.apache.commons.collections.Transformer;
  +import org.apache.commons.collections.TransformerUtils;
   
   /**
    * <code>LazyMap</code> decorates another <code>Map</code>
  @@ -94,7 +95,7 @@
   public class LazyMap extends AbstractMapDecorator implements Map {
   
       /** The factory to use to construct elements */
  -    protected final Object factory;
  +    protected final Transformer factory;
   
       /**
        * Factory method to create a lazily instantiated map.
  @@ -130,7 +131,7 @@
           if (factory == null) {
               throw new IllegalArgumentException("Factory must not be null");
           }
  -        this.factory = factory;
  +        this.factory = TransformerUtils.asTransformer(factory);
       }
   
       /**
  @@ -152,15 +153,9 @@
       public Object get(Object key) {
           // create value for key if key is not currently in the map
           if (map.containsKey(key) == false) {
  -            if (factory instanceof Factory) {
  -                Object value = ((Factory) factory).create();
  -                map.put(key, value);
  -                return value;
  -            } else {
  -                Object value = ((Transformer) factory).transform(key);
  -                map.put(key, value);
  -                return value;
  -            }
  +            Object value = factory.transform(key);
  +            map.put(key, value);
  +            return value;
           }
           return map.get(key);
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message