You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2009/02/03 00:24:01 UTC

svn commit: r740150 - in /commons/proper/collections/branches/collections_jdk5_branch/src: java/org/apache/commons/collections/ java/org/apache/commons/collections/map/ test/org/apache/commons/collections/bidimap/ test/org/apache/commons/collections/map/

Author: mbenson
Date: Mon Feb  2 23:24:00 2009
New Revision: 740150

URL: http://svn.apache.org/viewvc?rev=740150&view=rev
Log:
make all [collections] maps implement IterableMap

Added:
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractIterableMap.java   (with props)
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java   (with props)
Modified:
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BoundedMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MapUtils.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MultiMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/CompositeMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/DefaultedMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/FixedSizeMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/PredicatedMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/StaticBucketMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/TransformedMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestCompositeMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestFixedSizeMap.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/TestPredicatedMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java
    commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestTransformedMap.java

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BoundedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BoundedMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BoundedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/BoundedMap.java Mon Feb  2 23:24:00 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.collections;
 
-import java.util.Map;
-
 /**
  * Defines a map that is bounded in size.
  * <p>
@@ -30,7 +28,7 @@
  * 
  * @author Stephen Colebourne
  */
-public interface BoundedMap<K, V> extends Map<K, V> {
+public interface BoundedMap<K, V> extends IterableMap<K, V> {
 
     /**
      * Returns true if this map is full and no new elements can be added.

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MapUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MapUtils.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MapUtils.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MapUtils.java Mon Feb  2 23:24:00 2009
@@ -1270,7 +1270,7 @@
      * @return a predicated map backed by the given map
      * @throws IllegalArgumentException  if the Map is null
      */
-    public static <K, V> Map<K, V> predicatedMap(Map<K, V> map, Predicate<? super K> keyPred, Predicate<? super V> valuePred) {
+    public static <K, V> IterableMap<K, V> predicatedMap(Map<K, V> map, Predicate<? super K> keyPred, Predicate<? super V> valuePred) {
         return PredicatedMap.decorate(map, keyPred, valuePred);
     }
 
@@ -1295,7 +1295,7 @@
      * @return a transformed map backed by the given map
      * @throws IllegalArgumentException  if the Map is null
      */
-    public static <K, V> Map<K, V> transformedMap(Map<K, V> map,
+    public static <K, V> IterableMap<K, V> transformedMap(Map<K, V> map,
             Transformer<? super K, ? extends K> keyTransformer,
             Transformer<? super V, ? extends V> valueTransformer) {
         return TransformedMap.decorate(map, keyTransformer, valueTransformer);
@@ -1311,7 +1311,7 @@
      * @return a fixed-size map backed by that map
      * @throws IllegalArgumentException  if the Map is null
      */
-    public static <K, V> Map<K, V> fixedSizeMap(Map<K, V> map) {
+    public static <K, V> IterableMap<K, V> fixedSizeMap(Map<K, V> map) {
         return FixedSizeMap.decorate(map);
     }
 
@@ -1343,7 +1343,7 @@
      * @return a lazy map backed by the given map
      * @throws IllegalArgumentException  if the Map or Factory is null
      */
-    public static <K, V> Map<K, V> lazyMap(Map<K, V> map, Factory<? extends V> factory) {
+    public static <K, V> IterableMap<K, V> lazyMap(Map<K, V> map, Factory<? extends V> factory) {
         return LazyMap.getLazyMap(map, factory);
     }
 
@@ -1382,7 +1382,7 @@
      * @return a lazy map backed by the given map
      * @throws IllegalArgumentException  if the Map or Transformer is null
      */
-    public static <K, V> Map<K, V> lazyMap(Map<K, V> map, Transformer<? super K, ? extends V> transformerFactory) {
+    public static <K, V> IterableMap<K, V> lazyMap(Map<K, V> map, Transformer<? super K, ? extends V> transformerFactory) {
         return LazyMap.getLazyMap(map, transformerFactory);
     }
 
@@ -1397,7 +1397,7 @@
      * @return an ordered map backed by the given map
      * @throws IllegalArgumentException  if the Map is null
      */
-    public static <K, V> Map<K, V> orderedMap(Map<K, V> map) {
+    public static <K, V> IterableMap<K, V> orderedMap(Map<K, V> map) {
         return ListOrderedMap.decorate(map);
     }
 

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MultiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MultiMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MultiMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/MultiMap.java Mon Feb  2 23:24:00 2009
@@ -17,7 +17,6 @@
 package org.apache.commons.collections;
 
 import java.util.Collection;
-import java.util.Map;
 
 /** 
  * Defines a map that holds a collection of values against each key.
@@ -47,7 +46,7 @@
  * @author James Strachan
  * @author Stephen Colebourne
  */
-public interface MultiMap<K, V> extends Map<K, Object> {
+public interface MultiMap<K, V> extends IterableMap<K, Object> {
 
     /**
      * Removes a specific value from map.

Added: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractIterableMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractIterableMap.java?rev=740150&view=auto
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractIterableMap.java (added)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractIterableMap.java Mon Feb  2 23:24:00 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections.map;
+
+import org.apache.commons.collections.IterableMap;
+import org.apache.commons.collections.MapIterator;
+
+/**
+ * Provide a basic {@link IterableMap} implementation.
+ * @since Commons Collections 5
+ * @TODO fix version
+ * @version $Revision$ $Date$
+ * 
+ * @author Matt Benson
+ */
+public abstract class AbstractIterableMap<K, V> implements IterableMap<K, V> {
+
+    /**
+     * {@inheritDoc}
+     */
+    public MapIterator<K, V> mapIterator() {
+        return new EntrySetToMapIteratorAdapter<K, V>(entrySet());
+    }
+}

Propchange: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractIterableMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractIterableMap.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java Mon Feb  2 23:24:00 2009
@@ -20,6 +20,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.collections.MapIterator;
+
 /**
  * Provides a base decorator that enables additional functionality to be added
  * to a Map via decoration.
@@ -41,7 +43,7 @@
  * @author Daniel Rall
  * @author Stephen Colebourne
  */
-public abstract class AbstractMapDecorator<K, V> implements Map<K, V> {
+public abstract class AbstractMapDecorator<K, V> extends AbstractIterableMap<K, V> {
 
     /** The map to decorate */
     protected transient Map<K, V> map;
@@ -140,4 +142,10 @@
         return decorated().toString();
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public MapIterator<K, V> mapIterator() {
+        return new EntrySetToMapIteratorAdapter<K, V>(entrySet());
+    }
 }

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/CompositeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/CompositeMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/CompositeMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/CompositeMap.java Mon Feb  2 23:24:00 2009
@@ -42,7 +42,7 @@
  *
  * @author Brian McCallister
  */
-public class CompositeMap<K, V> implements Map<K, V> {
+public class CompositeMap<K, V> extends AbstractIterableMap<K, V> {
 
     /** Array of all maps in the composite */
     private Map<K, V>[] composite;

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/DefaultedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/DefaultedMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/DefaultedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/DefaultedMap.java Mon Feb  2 23:24:00 2009
@@ -24,6 +24,7 @@
 import java.util.Map;
 
 import org.apache.commons.collections.Factory;
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.Transformer;
 import org.apache.commons.collections.functors.ConstantTransformer;
 import org.apache.commons.collections.functors.FactoryTransformer;
@@ -95,7 +96,7 @@
      * @param factory  the factory to use to create entries, must not be null
      * @throws IllegalArgumentException if map or factory is null
      */
-    public static <K, V> Map<K, V> decorate(Map<K, V> map, Factory<? extends V> factory) {
+    public static <K, V> IterableMap<K, V> decorate(Map<K, V> map, Factory<? extends V> factory) {
         if (factory == null) {
             throw new IllegalArgumentException("Factory must not be null");
         }

Added: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java?rev=740150&view=auto
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java (added)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java Mon Feb  2 23:24:00 2009
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections.map;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.collections.MapIterator;
+import org.apache.commons.collections.ResettableIterator;
+
+/**
+ * Adapts a Map entrySet to the MapIterator interface.
+ * 
+ * @since Commons Collections 5
+ * @TODO fix version
+ * @version $Revision$ $Date$
+ * 
+ * @author Matt Benson
+ */
+public class EntrySetToMapIteratorAdapter<K, V> implements MapIterator<K, V>, ResettableIterator<K> {
+    private Set<Map.Entry<K, V>> entrySet;
+
+    private transient Iterator<Map.Entry<K, V>> iterator;
+    private transient Map.Entry<K, V> entry;
+
+    /**
+     * Create a new EntrySetToMapIteratorAdapter.
+     */
+    public EntrySetToMapIteratorAdapter(Set<Map.Entry<K, V>> entrySet) {
+        this.entrySet = entrySet;
+        reset();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public K getKey() {
+        return current().getKey();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public V getValue() {
+        return current().getValue();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public V setValue(V value) {
+        return current().setValue(value);
+    };
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean hasNext() {
+        return iterator.hasNext();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public K next() {
+        entry = iterator.next();
+        return getKey();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public synchronized void reset() {
+        iterator = entrySet.iterator();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void remove() {
+        iterator.remove();
+        entry = null;
+    }
+
+    private synchronized Map.Entry<K, V> current() {
+        if (entry == null) {
+            throw new IllegalStateException();
+        }
+        return entry;
+    }
+}

Propchange: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/FixedSizeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/FixedSizeMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/FixedSizeMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/FixedSizeMap.java Mon Feb  2 23:24:00 2009
@@ -25,6 +25,7 @@
 import java.util.Set;
 
 import org.apache.commons.collections.BoundedMap;
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.collection.UnmodifiableCollection;
 import org.apache.commons.collections.set.UnmodifiableSet;
 
@@ -68,7 +69,7 @@
      * @param map  the map to decorate, must not be null
      * @throws IllegalArgumentException if map is null
      */
-    public static <K, V> Map<K, V> decorate(Map<K, V> map) {
+    public static <K, V> IterableMap<K, V> decorate(Map<K, V> map) {
         return new FixedSizeMap<K, V>(map);
     }
 

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/PredicatedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/PredicatedMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/PredicatedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/PredicatedMap.java Mon Feb  2 23:24:00 2009
@@ -23,6 +23,7 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.Predicate;
 
 /**
@@ -74,7 +75,7 @@
      * @param valuePredicate  the predicate to validate to values, null means no check
      * @throws IllegalArgumentException if the map is null
      */
-    public static <K, V> Map<K, V> decorate(Map<K, V> map, Predicate<? super K> keyPredicate, Predicate<? super V> valuePredicate) {
+    public static <K, V> IterableMap<K, V> decorate(Map<K, V> map, Predicate<? super K> keyPredicate, Predicate<? super V> valuePredicate) {
         return new PredicatedMap<K, V>(map, keyPredicate, valuePredicate);
     }
 

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/StaticBucketMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/StaticBucketMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/StaticBucketMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/StaticBucketMap.java Mon Feb  2 23:24:00 2009
@@ -101,7 +101,7 @@
  * @author Janek Bogucki
  * @author Kazuya Ujihara
  */
-public final class StaticBucketMap<K, V> implements Map<K, V> {
+public final class StaticBucketMap<K, V> extends AbstractIterableMap<K, V> {
 
     /** The default number of buckets to use */
     private static final int DEFAULT_BUCKETS = 255;

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/TransformedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/TransformedMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/TransformedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/java/org/apache/commons/collections/map/TransformedMap.java Mon Feb  2 23:24:00 2009
@@ -22,6 +22,7 @@
 import java.io.Serializable;
 import java.util.Map;
 
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.Transformer;
 
 /**
@@ -69,7 +70,7 @@
      * @param valueTransformer  the transformer to use for value conversion, null means no transformation
      * @throws IllegalArgumentException if map is null
      */
-    public static <K, V> Map<K, V> decorate(Map<K, V> map,
+    public static <K, V> IterableMap<K, V> decorate(Map<K, V> map,
             Transformer<? super K, ? extends K> keyTransformer,
             Transformer<? super V, ? extends V> valueTransformer) {
         return new TransformedMap<K, V>(map, keyTransformer, valueTransformer);

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java Mon Feb  2 23:24:00 2009
@@ -26,7 +26,7 @@
 import org.apache.commons.collections.BulkTest;
 import org.apache.commons.collections.MapIterator;
 import org.apache.commons.collections.iterators.AbstractTestMapIterator;
-import org.apache.commons.collections.map.AbstractTestMap;
+import org.apache.commons.collections.map.AbstractTestIterableMap;
 
 /**
  * Abstract test class for {@link BidiMap} methods and contracts.
@@ -36,7 +36,7 @@
  * @author Matthew Hawthorne
  * @author Stephen Colebourne
  */
-public abstract class AbstractTestBidiMap<K, V> extends AbstractTestMap<K, V> {
+public abstract class AbstractTestBidiMap<K, V> extends AbstractTestIterableMap<K, V> {
 
     public AbstractTestBidiMap(String testName) {
         super(testName);

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java Mon Feb  2 23:24:00 2009
@@ -60,6 +60,7 @@
     //-----------------------------------------------------------------------
     public void testFailFastEntrySet() {
         if (isRemoveSupported() == false) return;
+        if (isFailFastExpected() == false) return;
         resetFull();
         Iterator<Map.Entry<K, V>> it = getMap().entrySet().iterator();
         Map.Entry<K, V> val = it.next();
@@ -81,6 +82,7 @@
 
     public void testFailFastKeySet() {
         if (isRemoveSupported() == false) return;
+        if (isFailFastExpected() == false) return;
         resetFull();
         Iterator<K> it = getMap().keySet().iterator();
         K val = it.next();
@@ -102,6 +104,7 @@
 
     public void testFailFastValues() {
         if (isRemoveSupported() == false) return;
+        if (isFailFastExpected() == false) return;
         resetFull();
         Iterator<V> it = getMap().values().iterator();
         it.next();

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/AbstractTestMap.java Mon Feb  2 23:24:00 2009
@@ -28,6 +28,7 @@
 
 import org.apache.commons.collections.AbstractTestObject;
 import org.apache.commons.collections.BulkTest;
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.collection.AbstractTestCollection;
 import org.apache.commons.collections.set.AbstractTestSet;
 
@@ -275,6 +276,18 @@
     }
 
     /**
+     * Returns true if the maps produced by
+     * {@link #makeEmptyMap()} and {@link #makeFullMap()}
+     * provide fail-fast behavior on their various iterators.
+     * <p>
+     * Default implementation returns true.
+     * Override if your collection class does not support fast failure.
+     */
+    public boolean isFailFastExpected() {
+        return true;
+    }
+
+    /**
      *  Returns the set of keys in the mappings used to test the map.  This
      *  method must return an array with the same length as {@link
      *  #getSampleValues()} and all array elements must be different. The
@@ -1701,6 +1714,13 @@
         assertTrue("Map's values should still equal HashMap's", test.isEmpty());
     }
 
+    /**
+     * All [collections] Map implementations should implement IterableMap.
+     */
+    public void testSubsetInterfaces() {
+        resetEmpty();
+        assertTrue(getMap() instanceof IterableMap);
+    }
 
     /**
      * Erases any leftover instance variables by setting them to null.

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestCompositeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestCompositeMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestCompositeMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestCompositeMap.java Mon Feb  2 23:24:00 2009
@@ -33,7 +33,7 @@
  *
  * @author Brian McCallister
  */
-public class TestCompositeMap<K, V> extends AbstractTestMap<K, V> {
+public class TestCompositeMap<K, V> extends AbstractTestIterableMap<K, V> {
     /** used as a flag in MapMutator tests */
     private boolean pass = false;
     

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestDefaultedMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestDefaultedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestDefaultedMap.java Mon Feb  2 23:24:00 2009
@@ -24,6 +24,7 @@
 
 import org.apache.commons.collections.Factory;
 import org.apache.commons.collections.FactoryUtils;
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.Transformer;
 import org.apache.commons.collections.functors.ConstantFactory;
 
@@ -36,7 +37,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TestDefaultedMap<K, V> extends AbstractTestMap<K, V> {
+public class TestDefaultedMap<K, V> extends AbstractTestIterableMap<K, V> {
 
     protected final Factory<V> nullFactory = FactoryUtils.<V>nullFactory();
 
@@ -54,7 +55,7 @@
     }
 
     //-----------------------------------------------------------------------
-    public Map<K, V> makeObject() {
+    public IterableMap<K, V> makeObject() {
         return DefaultedMap.decorate(new HashMap<K, V>(), nullFactory);
     }
 

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java Mon Feb  2 23:24:00 2009
@@ -19,6 +19,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.collections.IterableMap;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -31,7 +33,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TestFixedSizeMap<K, V> extends AbstractTestMap<K, V> {
+public class TestFixedSizeMap<K, V> extends AbstractTestIterableMap<K, V> {
 
     public TestFixedSizeMap(String testName) {
         super(testName);
@@ -46,11 +48,11 @@
         junit.textui.TestRunner.main(testCaseName);
     }
 
-    public Map<K, V> makeObject() {
+    public IterableMap<K, V> makeObject() {
         return FixedSizeMap.decorate(new HashMap<K, V>());
     }
 
-    public Map<K, V> makeFullMap() {
+    public IterableMap<K, V> makeFullMap() {
         Map<K, V> map = new HashMap<K, V>();
         addSampleMappings(map);
         return FixedSizeMap.decorate(map);

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=740150&r1=740149&r2=740150&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 Mon Feb  2 23:24:00 2009
@@ -35,7 +35,7 @@
  *
  * @author Phil Steitz
  */
-public class TestLazyMap<K, V> extends AbstractTestMap<K, V> {
+public class TestLazyMap<K, V> extends AbstractTestIterableMap<K, V> {
 
 	private static final Factory<Integer> oneFactory = FactoryUtils.constantFactory(1);
 

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestPredicatedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestPredicatedMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestPredicatedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestPredicatedMap.java Mon Feb  2 23:24:00 2009
@@ -23,6 +23,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.commons.collections.IterableMap;
 import org.apache.commons.collections.Predicate;
 import org.apache.commons.collections.functors.TruePredicate;
 
@@ -35,7 +36,7 @@
  *
  * @author Phil Steitz
  */
-public class TestPredicatedMap<K, V> extends AbstractTestMap<K, V> {
+public class TestPredicatedMap<K, V> extends AbstractTestIterableMap<K, V> {
 
     protected static final Predicate<Object> truePredicate = TruePredicate.<Object>truePredicate();
 
@@ -59,16 +60,16 @@
     }
 
     //-----------------------------------------------------------------------
-    protected Map<K, V> decorateMap(Map<K, V> map, Predicate<? super K> keyPredicate,
+    protected IterableMap<K, V> decorateMap(Map<K, V> map, Predicate<? super K> keyPredicate,
         Predicate<? super V> valuePredicate) {
         return PredicatedMap.decorate(map, keyPredicate, valuePredicate);
     }
 
-    public Map<K, V> makeObject() {
+    public IterableMap<K, V> makeObject() {
         return decorateMap(new HashMap<K, V>(), truePredicate, truePredicate);
     }
 
-    public Map<K, V> makeTestMap() {
+    public IterableMap<K, V> makeTestMap() {
         return decorateMap(new HashMap<K, V>(), testPredicate, testPredicate);
     }
 

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java Mon Feb  2 23:24:00 2009
@@ -28,7 +28,7 @@
  *
  * @author Michael A. Smith
  */
-public class TestStaticBucketMap<K, V> extends AbstractTestMap<K, V> {
+public class TestStaticBucketMap<K, V> extends AbstractTestIterableMap<K, V> {
 
     public TestStaticBucketMap(String name) {
         super(name);
@@ -47,6 +47,14 @@
         return new StaticBucketMap<K, V>(30);
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isFailFastExpected() {
+        return false;
+    }
+
     public String[] ignoredTests() {
         String pre = "TestStaticBucketMap.bulkTestMap";
         String post = ".testCollectionIteratorFailFast";

Modified: commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestTransformedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestTransformedMap.java?rev=740150&r1=740149&r2=740150&view=diff
==============================================================================
--- commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestTransformedMap.java (original)
+++ commons/proper/collections/branches/collections_jdk5_branch/src/test/org/apache/commons/collections/map/TestTransformedMap.java Mon Feb  2 23:24:00 2009
@@ -23,6 +23,7 @@
 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;
@@ -36,7 +37,7 @@
  *
  * @author Stephen Colebourne
  */
-public class TestTransformedMap<K, V> extends AbstractTestMap<K, V> {
+public class TestTransformedMap<K, V> extends AbstractTestIterableMap<K, V> {
 
     public TestTransformedMap(String testName) {
         super(testName);
@@ -52,7 +53,7 @@
     }
 
     //-----------------------------------------------------------------------
-    public Map<K, V> makeObject() {
+    public IterableMap<K, V> makeObject() {
         return TransformedMap.decorate(new HashMap<K, V>(), TransformerUtils.<K> nopTransformer(),
                 TransformerUtils.<V> nopTransformer());
     }