make all [collections] maps implement IterableMap git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/branches/collections_jdk5_branch@740150 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/commons-collections/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-collections/commit/04956211 Tree: http://git-wip-us.apache.org/repos/asf/commons-collections/tree/04956211 Diff: http://git-wip-us.apache.org/repos/asf/commons-collections/diff/04956211 Branch: refs/heads/collections_jdk5_branch Commit: 049562110777529a3d4efba4b2197e3c29dc7935 Parents: bba9e0c Author: Matthew Jason Benson <mben...@apache.org> Authored: Mon Feb 2 23:24:00 2009 +0000 Committer: Matthew Jason Benson <mben...@apache.org> Committed: Mon Feb 2 23:24:00 2009 +0000 ---------------------------------------------------------------------- .../apache/commons/collections/BoundedMap.java | 4 +- .../apache/commons/collections/MapUtils.java | 12 +-- .../apache/commons/collections/MultiMap.java | 3 +- .../collections/map/AbstractIterableMap.java | 38 +++++++ .../collections/map/AbstractMapDecorator.java | 10 +- .../commons/collections/map/CompositeMap.java | 2 +- .../commons/collections/map/DefaultedMap.java | 3 +- .../map/EntrySetToMapIteratorAdapter.java | 106 +++++++++++++++++++ .../commons/collections/map/FixedSizeMap.java | 3 +- .../commons/collections/map/PredicatedMap.java | 3 +- .../collections/map/StaticBucketMap.java | 2 +- .../commons/collections/map/TransformedMap.java | 3 +- .../bidimap/AbstractTestBidiMap.java | 4 +- .../map/AbstractTestIterableMap.java | 3 + .../collections/map/AbstractTestMap.java | 20 ++++ .../collections/map/TestCompositeMap.java | 2 +- .../collections/map/TestDefaultedMap.java | 5 +- .../collections/map/TestFixedSizeMap.java | 8 +- .../commons/collections/map/TestLazyMap.java | 2 +- .../collections/map/TestPredicatedMap.java | 9 +- .../collections/map/TestStaticBucketMap.java | 10 +- .../collections/map/TestTransformedMap.java | 5 +- 22 files changed, 223 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/BoundedMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/BoundedMap.java b/src/java/org/apache/commons/collections/BoundedMap.java index 0a8123f..9f8ea67 100644 --- a/src/java/org/apache/commons/collections/BoundedMap.java +++ b/src/java/org/apache/commons/collections/BoundedMap.java @@ -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 @@ import java.util.Map; * * @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. http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/MapUtils.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/MapUtils.java b/src/java/org/apache/commons/collections/MapUtils.java index b3c33a9..ea017ff 100644 --- a/src/java/org/apache/commons/collections/MapUtils.java +++ b/src/java/org/apache/commons/collections/MapUtils.java @@ -1270,7 +1270,7 @@ public class MapUtils { * @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 @@ public class MapUtils { * @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 @@ public class MapUtils { * @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 @@ public class MapUtils { * @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 @@ public class MapUtils { * @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 @@ public class MapUtils { * @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); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/MultiMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/MultiMap.java b/src/java/org/apache/commons/collections/MultiMap.java index 388b56a..2b7333e 100644 --- a/src/java/org/apache/commons/collections/MultiMap.java +++ b/src/java/org/apache/commons/collections/MultiMap.java @@ -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 @@ import java.util.Map; * @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. http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/AbstractIterableMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/AbstractIterableMap.java b/src/java/org/apache/commons/collections/map/AbstractIterableMap.java new file mode 100644 index 0000000..2f812cb --- /dev/null +++ b/src/java/org/apache/commons/collections/map/AbstractIterableMap.java @@ -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()); + } +} http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java b/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java index b9197cc..821dc95 100644 --- a/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java +++ b/src/java/org/apache/commons/collections/map/AbstractMapDecorator.java @@ -20,6 +20,8 @@ import java.util.Collection; 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 @@ import java.util.Set; * @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 @@ public abstract class AbstractMapDecorator<K, V> implements Map<K, V> { return decorated().toString(); } + /** + * {@inheritDoc} + */ + public MapIterator<K, V> mapIterator() { + return new EntrySetToMapIteratorAdapter<K, V>(entrySet()); + } } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/CompositeMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/CompositeMap.java b/src/java/org/apache/commons/collections/map/CompositeMap.java index 264d7ec..432e492 100644 --- a/src/java/org/apache/commons/collections/map/CompositeMap.java +++ b/src/java/org/apache/commons/collections/map/CompositeMap.java @@ -42,7 +42,7 @@ import org.apache.commons.collections.set.CompositeSet; * * @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; http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/DefaultedMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/DefaultedMap.java b/src/java/org/apache/commons/collections/map/DefaultedMap.java index 2ecd36e..010de2f 100644 --- a/src/java/org/apache/commons/collections/map/DefaultedMap.java +++ b/src/java/org/apache/commons/collections/map/DefaultedMap.java @@ -24,6 +24,7 @@ import java.util.HashMap; 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 @@ public class DefaultedMap<K, V> extends AbstractMapDecorator<K, V> implements Se * @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"); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java b/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java new file mode 100644 index 0000000..a9d3f43 --- /dev/null +++ b/src/java/org/apache/commons/collections/map/EntrySetToMapIteratorAdapter.java @@ -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; + } +} http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/FixedSizeMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/FixedSizeMap.java b/src/java/org/apache/commons/collections/map/FixedSizeMap.java index 6c4ab3f..b293508 100644 --- a/src/java/org/apache/commons/collections/map/FixedSizeMap.java +++ b/src/java/org/apache/commons/collections/map/FixedSizeMap.java @@ -25,6 +25,7 @@ import java.util.Map; 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 @@ public class FixedSizeMap<K, V> * @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); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/PredicatedMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/PredicatedMap.java b/src/java/org/apache/commons/collections/map/PredicatedMap.java index 537fe35..eebce71 100644 --- a/src/java/org/apache/commons/collections/map/PredicatedMap.java +++ b/src/java/org/apache/commons/collections/map/PredicatedMap.java @@ -23,6 +23,7 @@ import java.io.Serializable; import java.util.Iterator; import java.util.Map; +import org.apache.commons.collections.IterableMap; import org.apache.commons.collections.Predicate; /** @@ -74,7 +75,7 @@ public class PredicatedMap<K, V> * @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); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/StaticBucketMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/StaticBucketMap.java b/src/java/org/apache/commons/collections/map/StaticBucketMap.java index 7486d70..fa03680 100644 --- a/src/java/org/apache/commons/collections/map/StaticBucketMap.java +++ b/src/java/org/apache/commons/collections/map/StaticBucketMap.java @@ -101,7 +101,7 @@ import org.apache.commons.collections.KeyValue; * @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; http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/java/org/apache/commons/collections/map/TransformedMap.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/commons/collections/map/TransformedMap.java b/src/java/org/apache/commons/collections/map/TransformedMap.java index 4df0f2e..56741fd 100644 --- a/src/java/org/apache/commons/collections/map/TransformedMap.java +++ b/src/java/org/apache/commons/collections/map/TransformedMap.java @@ -22,6 +22,7 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Map; +import org.apache.commons.collections.IterableMap; import org.apache.commons.collections.Transformer; /** @@ -69,7 +70,7 @@ public class TransformedMap<K, V> * @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); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java b/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java index 7f026db..148473d 100644 --- a/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/AbstractTestBidiMap.java @@ -26,7 +26,7 @@ import org.apache.commons.collections.BidiMap; 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 @@ import org.apache.commons.collections.map.AbstractTestMap; * @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); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java b/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java index 0e7b3e1..5213f93 100644 --- a/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java +++ b/src/test/org/apache/commons/collections/map/AbstractTestIterableMap.java @@ -60,6 +60,7 @@ public abstract class AbstractTestIterableMap<K, V> extends AbstractTestMap<K, V //----------------------------------------------------------------------- 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 abstract class AbstractTestIterableMap<K, V> extends AbstractTestMap<K, V 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 abstract class AbstractTestIterableMap<K, V> extends AbstractTestMap<K, V public void testFailFastValues() { if (isRemoveSupported() == false) return; + if (isFailFastExpected() == false) return; resetFull(); Iterator<V> it = getMap().values().iterator(); it.next(); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/AbstractTestMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/AbstractTestMap.java b/src/test/org/apache/commons/collections/map/AbstractTestMap.java index 47155f3..514f1cd 100644 --- a/src/test/org/apache/commons/collections/map/AbstractTestMap.java +++ b/src/test/org/apache/commons/collections/map/AbstractTestMap.java @@ -28,6 +28,7 @@ import java.util.Map.Entry; 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 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject { } /** + * 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 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject { 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. http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/TestCompositeMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestCompositeMap.java b/src/test/org/apache/commons/collections/map/TestCompositeMap.java index 7fd3e6e..0f89192 100644 --- a/src/test/org/apache/commons/collections/map/TestCompositeMap.java +++ b/src/test/org/apache/commons/collections/map/TestCompositeMap.java @@ -33,7 +33,7 @@ import java.util.Collection; * * @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; http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/TestDefaultedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestDefaultedMap.java b/src/test/org/apache/commons/collections/map/TestDefaultedMap.java index ac0576a..4f04930 100644 --- a/src/test/org/apache/commons/collections/map/TestDefaultedMap.java +++ b/src/test/org/apache/commons/collections/map/TestDefaultedMap.java @@ -24,6 +24,7 @@ import junit.framework.TestSuite; 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 @@ import org.apache.commons.collections.functors.ConstantFactory; * * @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 class TestDefaultedMap<K, V> extends AbstractTestMap<K, V> { } //----------------------------------------------------------------------- - public Map<K, V> makeObject() { + public IterableMap<K, V> makeObject() { return DefaultedMap.decorate(new HashMap<K, V>(), nullFactory); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java b/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java index e70bd7a..8ffb22c 100644 --- a/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java +++ b/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java @@ -19,6 +19,8 @@ package org.apache.commons.collections.map; 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 @@ import junit.framework.TestSuite; * * @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 @@ public class TestFixedSizeMap<K, V> extends AbstractTestMap<K, V> { 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); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/TestLazyMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestLazyMap.java b/src/test/org/apache/commons/collections/map/TestLazyMap.java index d3394fb..c7042b2 100644 --- a/src/test/org/apache/commons/collections/map/TestLazyMap.java +++ b/src/test/org/apache/commons/collections/map/TestLazyMap.java @@ -35,7 +35,7 @@ import org.junit.Test; * * @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); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/TestPredicatedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestPredicatedMap.java b/src/test/org/apache/commons/collections/map/TestPredicatedMap.java index 9edb140..99f6b79 100644 --- a/src/test/org/apache/commons/collections/map/TestPredicatedMap.java +++ b/src/test/org/apache/commons/collections/map/TestPredicatedMap.java @@ -23,6 +23,7 @@ import java.util.Map; 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 @@ import org.apache.commons.collections.functors.TruePredicate; * * @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 @@ public class TestPredicatedMap<K, V> extends AbstractTestMap<K, V> { } //----------------------------------------------------------------------- - 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); } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java b/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java index a9c1c70..31014a0 100644 --- a/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java +++ b/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java @@ -28,7 +28,7 @@ import org.apache.commons.collections.BulkTest; * * @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 @@ public class TestStaticBucketMap<K, V> extends AbstractTestMap<K, V> { return new StaticBucketMap<K, V>(30); } + /** + * {@inheritDoc} + */ + @Override + public boolean isFailFastExpected() { + return false; + } + public String[] ignoredTests() { String pre = "TestStaticBucketMap.bulkTestMap"; String post = ".testCollectionIteratorFailFast"; http://git-wip-us.apache.org/repos/asf/commons-collections/blob/04956211/src/test/org/apache/commons/collections/map/TestTransformedMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/map/TestTransformedMap.java b/src/test/org/apache/commons/collections/map/TestTransformedMap.java index 15f8a18..517bce2 100644 --- a/src/test/org/apache/commons/collections/map/TestTransformedMap.java +++ b/src/test/org/apache/commons/collections/map/TestTransformedMap.java @@ -23,6 +23,7 @@ import java.util.Set; 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 @@ import org.apache.commons.collections.collection.TestTransformedCollection; * * @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 class TestTransformedMap<K, V> extends AbstractTestMap<K, V> { } //----------------------------------------------------------------------- - public Map<K, V> makeObject() { + public IterableMap<K, V> makeObject() { return TransformedMap.decorate(new HashMap<K, V>(), TransformerUtils.<K> nopTransformer(), TransformerUtils.<V> nopTransformer()); }