Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified in r738956, r471214 and/or r471578.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815006 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
76d2beab1a
commit
de0d3728b0
|
@ -33,33 +33,16 @@ package org.apache.commons.collections;
|
|||
* This is required so that "inverting" the map results in a map without
|
||||
* duplicate keys. See the {@link #put} method description for more information.
|
||||
*
|
||||
* @param <K> the type of the keys in the map
|
||||
* @param <V> the type of the values in the map
|
||||
*
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface BidiMap extends IterableMap {
|
||||
public interface BidiMap<K, V> extends IterableMap<K, V> {
|
||||
|
||||
/**
|
||||
* Obtains a <code>MapIterator</code> over the map.
|
||||
* <p>
|
||||
* A map iterator is an efficient way of iterating over maps.
|
||||
* It does not require that the map is stored using Map Entry objects
|
||||
* which can increase performance.
|
||||
* <pre>
|
||||
* BidiMap map = new DualHashBidiMap();
|
||||
* MapIterator it = map.mapIterator();
|
||||
* while (it.hasNext()) {
|
||||
* Object key = it.next();
|
||||
* Object value = it.getValue();
|
||||
* it.setValue("newValue");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @return a map iterator
|
||||
*/
|
||||
MapIterator mapIterator();
|
||||
|
||||
/**
|
||||
* Puts the key-value pair into the map, replacing any previous pair.
|
||||
* <p>
|
||||
|
@ -88,8 +71,8 @@ public interface BidiMap extends IterableMap {
|
|||
* @throws NullPointerException (optional) if the map limits the values to
|
||||
* non-null and null was specified
|
||||
*/
|
||||
Object put(Object key, Object value);
|
||||
|
||||
V put(K key, V value);
|
||||
|
||||
/**
|
||||
* Gets the key that is currently mapped to the specified value.
|
||||
* <p>
|
||||
|
@ -106,8 +89,8 @@ public interface BidiMap extends IterableMap {
|
|||
* @throws NullPointerException (optional) if the map limits the values to
|
||||
* non-null and null was specified
|
||||
*/
|
||||
Object getKey(Object value);
|
||||
|
||||
K getKey(Object value);
|
||||
|
||||
/**
|
||||
* Removes the key-value pair that is currently mapped to the specified
|
||||
* value (optional operation).
|
||||
|
@ -127,8 +110,8 @@ public interface BidiMap extends IterableMap {
|
|||
* @throws UnsupportedOperationException if this method is not supported
|
||||
* by the implementation
|
||||
*/
|
||||
Object removeValue(Object value);
|
||||
|
||||
K removeValue(Object value);
|
||||
|
||||
/**
|
||||
* Gets a view of this map where the keys and values are reversed.
|
||||
* <p>
|
||||
|
@ -141,6 +124,6 @@ public interface BidiMap extends IterableMap {
|
|||
*
|
||||
* @return an inverted bidirectional map
|
||||
*/
|
||||
BidiMap inverseBidiMap();
|
||||
|
||||
BidiMap<V, K> inverseBidiMap();
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.Collection;
|
|||
* also implement {@link java.util.List}, {@link java.util.Set} or
|
||||
* {@link Bag}.
|
||||
*
|
||||
* @param <E> the type of the elements in the buffer
|
||||
* @since Commons Collections 2.1
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
|
@ -43,7 +44,7 @@ import java.util.Collection;
|
|||
* @author Paul Jack
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface Buffer extends Collection {
|
||||
public interface Buffer<E> extends Collection<E> {
|
||||
|
||||
/**
|
||||
* Gets and removes the next object from the buffer.
|
||||
|
@ -51,7 +52,7 @@ public interface Buffer extends Collection {
|
|||
* @return the next object in the buffer, which is also removed
|
||||
* @throws BufferUnderflowException if the buffer is already empty
|
||||
*/
|
||||
Object remove();
|
||||
E remove();
|
||||
|
||||
/**
|
||||
* Gets the next object from the buffer without removing it.
|
||||
|
@ -59,6 +60,6 @@ public interface Buffer extends Collection {
|
|||
* @return the next object in the buffer, which is not removed
|
||||
* @throws BufferUnderflowException if the buffer is empty
|
||||
*/
|
||||
Object get();
|
||||
E get();
|
||||
|
||||
}
|
||||
|
|
|
@ -23,25 +23,27 @@ package org.apache.commons.collections;
|
|||
* key-value pair. This interface defines the minimum key value, with just the
|
||||
* two get methods.
|
||||
*
|
||||
* @param <K> the type of the key
|
||||
* @param <V> the type of the value
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface KeyValue {
|
||||
public interface KeyValue<K, V> {
|
||||
|
||||
/**
|
||||
* Gets the key from the pair.
|
||||
*
|
||||
* @return the key
|
||||
*/
|
||||
Object getKey();
|
||||
K getKey();
|
||||
|
||||
/**
|
||||
* Gets the value from the pair.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
Object getValue();
|
||||
V getValue();
|
||||
|
||||
}
|
||||
|
|
|
@ -23,12 +23,15 @@ package org.apache.commons.collections;
|
|||
* Implementations should allow a value to be looked up from a key and
|
||||
* a key to be looked up from a value with equal performance.
|
||||
*
|
||||
* @param <K> the type of the keys in the map
|
||||
* @param <V> the type of the values in the map
|
||||
*
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface OrderedBidiMap extends BidiMap, OrderedMap {
|
||||
public interface OrderedBidiMap<K, V> extends BidiMap<K, V>, OrderedMap<K, V> {
|
||||
|
||||
/**
|
||||
* Gets a view of this map where the keys and values are reversed.
|
||||
|
@ -45,20 +48,6 @@ public interface OrderedBidiMap extends BidiMap, OrderedMap {
|
|||
*
|
||||
* @return an inverted bidirectional map
|
||||
*/
|
||||
public BidiMap inverseBidiMap();
|
||||
|
||||
/**
|
||||
* Gets a view of this map where the keys and values are reversed.
|
||||
* <p>
|
||||
* Changes to one map will be visible in the other and vice versa.
|
||||
* This enables both directions of the map to be accessed equally.
|
||||
* <p>
|
||||
* Implementations should seek to avoid creating a new object every time this
|
||||
* method is called. See <code>AbstractMap.values()</code> etc. Calling this
|
||||
* method on the inverse map should return the original.
|
||||
*
|
||||
* @return an inverted bidirectional map
|
||||
*/
|
||||
public OrderedBidiMap inverseOrderedBidiMap();
|
||||
|
||||
public OrderedBidiMap<V, K> inverseBidiMap();
|
||||
|
||||
}
|
||||
|
|
|
@ -20,40 +20,33 @@ package org.apache.commons.collections;
|
|||
* Defines a map that maintains order and allows both forward and backward
|
||||
* iteration through that order.
|
||||
*
|
||||
* @param <K> the type of the keys in the map
|
||||
* @param <V> the type of the values in the map
|
||||
*
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface OrderedMap extends IterableMap {
|
||||
|
||||
public interface OrderedMap<K, V> extends IterableMap<K, V> {
|
||||
|
||||
/**
|
||||
* Obtains an <code>OrderedMapIterator</code> over the map.
|
||||
* <p>
|
||||
* A ordered map iterator is an efficient way of iterating over maps
|
||||
* in both directions.
|
||||
* <pre>
|
||||
* BidiMap map = new TreeBidiMap();
|
||||
* MapIterator it = map.mapIterator();
|
||||
* while (it.hasNext()) {
|
||||
* Object key = it.next();
|
||||
* Object value = it.getValue();
|
||||
* it.setValue("newValue");
|
||||
* Object previousKey = it.previous();
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @return a map iterator
|
||||
*/
|
||||
OrderedMapIterator orderedMapIterator();
|
||||
|
||||
OrderedMapIterator<K, V> mapIterator();
|
||||
|
||||
/**
|
||||
* Gets the first key currently in this map.
|
||||
*
|
||||
* @return the first key currently in this map
|
||||
* @throws java.util.NoSuchElementException if this map is empty
|
||||
*/
|
||||
public Object firstKey();
|
||||
public K firstKey();
|
||||
|
||||
/**
|
||||
* Gets the last key currently in this map.
|
||||
|
@ -61,15 +54,15 @@ public interface OrderedMap extends IterableMap {
|
|||
* @return the last key currently in this map
|
||||
* @throws java.util.NoSuchElementException if this map is empty
|
||||
*/
|
||||
public Object lastKey();
|
||||
|
||||
public K lastKey();
|
||||
|
||||
/**
|
||||
* Gets the next key after the one specified.
|
||||
*
|
||||
* @param key the key to search for next from
|
||||
* @return the next key, null if no match or at end
|
||||
*/
|
||||
public Object nextKey(Object key);
|
||||
public K nextKey(K key);
|
||||
|
||||
/**
|
||||
* Gets the previous key before the one specified.
|
||||
|
@ -77,6 +70,6 @@ public interface OrderedMap extends IterableMap {
|
|||
* @param key the key to search for previous from
|
||||
* @return the previous key, null if no match or at start
|
||||
*/
|
||||
public Object previousKey(Object key);
|
||||
|
||||
public K previousKey(K key);
|
||||
|
||||
}
|
||||
|
|
|
@ -16,18 +16,22 @@
|
|||
*/
|
||||
package org.apache.commons.collections;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Defines an iterator that operates over an ordered <code>Map</code>.
|
||||
* <p>
|
||||
* This iterator allows both forward and reverse iteration through the map.
|
||||
*
|
||||
*
|
||||
* @param <K> the type of the keys in the map
|
||||
* @param <V> the type of the values in the map
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface OrderedMapIterator extends MapIterator, OrderedIterator {
|
||||
|
||||
public interface OrderedMapIterator<K, V> extends MapIterator<K, V>, OrderedIterator<K> {
|
||||
|
||||
/**
|
||||
* Checks to see if there is a previous entry that can be iterated to.
|
||||
*
|
||||
|
@ -39,8 +43,8 @@ public interface OrderedMapIterator extends MapIterator, OrderedIterator {
|
|||
* Gets the previous <em>key</em> from the <code>Map</code>.
|
||||
*
|
||||
* @return the previous key in the iteration
|
||||
* @throws java.util.NoSuchElementException if the iteration is finished
|
||||
* @throws NoSuchElementException if the iteration is finished
|
||||
*/
|
||||
Object previous();
|
||||
K previous();
|
||||
|
||||
}
|
||||
|
|
|
@ -23,12 +23,13 @@ import java.util.Iterator;
|
|||
* <p>
|
||||
* This interface allows an iterator to be repeatedly reused.
|
||||
*
|
||||
* @param <E> the type to iterate over
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface ResettableIterator extends Iterator {
|
||||
public interface ResettableIterator<E> extends Iterator<E> {
|
||||
|
||||
/**
|
||||
* Resets the iterator back to the position at which the iterator
|
||||
|
|
|
@ -22,12 +22,13 @@ import java.util.Comparator;
|
|||
* Defines a type of <code>Bag</code> that maintains a sorted order among
|
||||
* its unique representative members.
|
||||
*
|
||||
* @param <E> the type to iterate over
|
||||
* @since Commons Collections 2.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Chuck Burdick
|
||||
*/
|
||||
public interface SortedBag extends Bag {
|
||||
public interface SortedBag<E> extends Bag<E> {
|
||||
|
||||
/**
|
||||
* Returns the comparator associated with this sorted set, or null
|
||||
|
@ -35,20 +36,20 @@ public interface SortedBag extends Bag {
|
|||
*
|
||||
* @return the comparator in use, or null if natural ordering
|
||||
*/
|
||||
public Comparator comparator();
|
||||
public Comparator<? super E> comparator();
|
||||
|
||||
/**
|
||||
* Returns the first (lowest) member.
|
||||
*
|
||||
* @return the first element in the sorted bag
|
||||
*/
|
||||
public Object first();
|
||||
public E first();
|
||||
|
||||
/**
|
||||
* Returns the last (highest) member.
|
||||
*
|
||||
* @return the last element in the sorted bag
|
||||
*/
|
||||
public Object last();
|
||||
|
||||
public E last();
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.commons.collections;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.SortedMap;
|
||||
|
||||
/**
|
||||
|
@ -25,12 +26,14 @@ import java.util.SortedMap;
|
|||
* Implementations should allow a value to be looked up from a key and
|
||||
* a key to be looked up from a value with equal performance.
|
||||
*
|
||||
* @param <K> the type of the keys in the map
|
||||
* @param <V> the type of the values in the map
|
||||
* @since Commons Collections 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public interface SortedBidiMap extends OrderedBidiMap, SortedMap {
|
||||
public interface SortedBidiMap<K, V> extends OrderedBidiMap<K, V>, SortedMap<K, V> {
|
||||
|
||||
/**
|
||||
* Gets a view of this map where the keys and values are reversed.
|
||||
|
@ -47,23 +50,11 @@ public interface SortedBidiMap extends OrderedBidiMap, SortedMap {
|
|||
*
|
||||
* @return an inverted bidirectional map
|
||||
*/
|
||||
public BidiMap inverseBidiMap();
|
||||
|
||||
public SortedBidiMap<V, K> inverseBidiMap();
|
||||
|
||||
/**
|
||||
* Gets a view of this map where the keys and values are reversed.
|
||||
* <p>
|
||||
* Changes to one map will be visible in the other and vice versa.
|
||||
* This enables both directions of the map to be accessed as a <code>SortedMap</code>.
|
||||
* <p>
|
||||
* Implementations should seek to avoid creating a new object every time this
|
||||
* method is called. See <code>AbstractMap.values()</code> etc. Calling this
|
||||
* method on the inverse map should return the original.
|
||||
* <p>
|
||||
* The inverse map returned by <code>inverseBidiMap()</code> should be the
|
||||
* same object as returned by this method.
|
||||
*
|
||||
* @return an inverted bidirectional map
|
||||
* Get the comparator used for the values in the value-to-key map aspect.
|
||||
* @return Comparator<? super V>
|
||||
*/
|
||||
public SortedBidiMap inverseSortedBidiMap();
|
||||
|
||||
public Comparator<? super V> valueComparator();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
import org.apache.commons.collections.Predicate;
|
||||
import org.apache.commons.collections.PredicateUtils;
|
||||
import org.apache.commons.collections.functors.TruePredicate;
|
||||
|
||||
/**
|
||||
* Extension of {@link AbstractTestCollection} for exercising the
|
||||
|
@ -36,12 +36,12 @@ import org.apache.commons.collections.PredicateUtils;
|
|||
*
|
||||
* @author Phil Steitz
|
||||
*/
|
||||
public class TestPredicatedCollection extends AbstractTestCollection {
|
||||
public class TestPredicatedCollection<E> extends AbstractTestCollection<E> {
|
||||
|
||||
public TestPredicatedCollection(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestPredicatedCollection.class);
|
||||
}
|
||||
|
@ -50,86 +50,84 @@ public class TestPredicatedCollection extends AbstractTestCollection {
|
|||
String[] testCaseName = { TestPredicatedCollection.class.getName()};
|
||||
junit.textui.TestRunner.main(testCaseName);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
protected Predicate truePredicate = PredicateUtils.truePredicate();
|
||||
|
||||
protected Collection decorateCollection(Collection collection,
|
||||
Predicate predicate) {
|
||||
protected Predicate<E> truePredicate = TruePredicate.<E>truePredicate();
|
||||
|
||||
protected Collection<E> decorateCollection(
|
||||
Collection<E> collection, Predicate<E> predicate) {
|
||||
return PredicatedCollection.decorate(collection, predicate);
|
||||
}
|
||||
|
||||
public Collection makeCollection() {
|
||||
return decorateCollection(new ArrayList(), truePredicate);
|
||||
|
||||
public Collection<E> makeObject() {
|
||||
return decorateCollection(new ArrayList<E>(), truePredicate);
|
||||
}
|
||||
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
|
||||
public Collection<E> makeConfirmedCollection() {
|
||||
return new ArrayList<E>();
|
||||
}
|
||||
|
||||
public Object[] getFullElements() {
|
||||
return new Object[] {"1", "3", "5", "7", "2", "4", "6"};
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public E[] getFullElements() {
|
||||
return (E[]) new Object[] { "1", "3", "5", "7", "2", "4", "6" };
|
||||
}
|
||||
|
||||
public Collection makeFullCollection() {
|
||||
List list = new ArrayList();
|
||||
|
||||
public Collection<E> makeFullCollection() {
|
||||
List<E> list = new ArrayList<E>();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return decorateCollection(list, truePredicate);
|
||||
}
|
||||
|
||||
public Collection makeConfirmedFullCollection() {
|
||||
List list = new ArrayList();
|
||||
|
||||
public Collection<E> makeConfirmedFullCollection() {
|
||||
List<E> list = new ArrayList<E>();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return list;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
protected Predicate testPredicate =
|
||||
new Predicate() {
|
||||
public boolean evaluate(Object o) {
|
||||
//-----------------------------------------------------------------------
|
||||
protected Predicate<E> testPredicate =
|
||||
new Predicate<E>() {
|
||||
public boolean evaluate(E o) {
|
||||
return o instanceof String;
|
||||
}
|
||||
};
|
||||
|
||||
public Collection makeTestCollection() {
|
||||
return decorateCollection(new ArrayList(), testPredicate);
|
||||
|
||||
public Collection<E> makeTestCollection() {
|
||||
return decorateCollection(new ArrayList<E>(), testPredicate);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testIllegalAdd() {
|
||||
Collection c = makeTestCollection();
|
||||
Collection<E> c = makeTestCollection();
|
||||
Integer i = new Integer(3);
|
||||
try {
|
||||
c.add(i);
|
||||
c.add((E) i);
|
||||
fail("Integer should fail string predicate.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
assertTrue("Collection shouldn't contain illegal element",
|
||||
!c.contains(i));
|
||||
assertTrue("Collection shouldn't contain illegal element",
|
||||
!c.contains(i));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testIllegalAddAll() {
|
||||
Collection c = makeTestCollection();
|
||||
List elements = new ArrayList();
|
||||
elements.add("one");
|
||||
elements.add("two");
|
||||
elements.add(new Integer(3));
|
||||
elements.add("four");
|
||||
Collection<E> c = makeTestCollection();
|
||||
List<E> elements = new ArrayList<E>();
|
||||
elements.add((E) "one");
|
||||
elements.add((E) "two");
|
||||
elements.add((E) new Integer(3));
|
||||
elements.add((E) "four");
|
||||
try {
|
||||
c.addAll(elements);
|
||||
fail("Integer should fail string predicate.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
assertTrue("Collection shouldn't contain illegal element",
|
||||
!c.contains("one"));
|
||||
assertTrue("Collection shouldn't contain illegal element",
|
||||
!c.contains("two"));
|
||||
assertTrue("Collection shouldn't contain illegal element",
|
||||
!c.contains(new Integer(3)));
|
||||
assertTrue("Collection shouldn't contain illegal element",
|
||||
!c.contains("four"));
|
||||
assertTrue("Collection shouldn't contain illegal element", !c.contains("one"));
|
||||
assertTrue("Collection shouldn't contain illegal element", !c.contains("two"));
|
||||
assertTrue("Collection shouldn't contain illegal element", !c.contains(new Integer(3)));
|
||||
assertTrue("Collection shouldn't contain illegal element", !c.contains("four"));
|
||||
}
|
||||
|
||||
public String getCompatibilityVersion() {
|
||||
|
|
|
@ -24,7 +24,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Extension of {@link AbstractTestCollection} for exercising the
|
||||
* Extension of {@link AbstractTestCollection} for exercising the
|
||||
* {@link SynchronizedCollection} implementation.
|
||||
*
|
||||
* @since Commons Collections 3.1
|
||||
|
@ -33,33 +33,32 @@ import junit.framework.TestSuite;
|
|||
* @author Phil Steitz
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public class TestSynchronizedCollection extends AbstractTestCollection {
|
||||
|
||||
public class TestSynchronizedCollection<E> extends AbstractTestCollection<E> {
|
||||
|
||||
public TestSynchronizedCollection(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestSynchronizedCollection.class);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
String[] testCaseName = { TestSynchronizedCollection.class.getName()};
|
||||
junit.textui.TestRunner.main(testCaseName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Collection makeCollection() {
|
||||
return SynchronizedCollection.decorate(new ArrayList());
|
||||
}
|
||||
|
||||
public Collection makeConfirmedCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
return list;
|
||||
//-----------------------------------------------------------------------
|
||||
public Collection<E> makeObject() {
|
||||
return SynchronizedCollection.decorate(new ArrayList<E>());
|
||||
}
|
||||
|
||||
public Collection makeConfirmedFullCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
public Collection<E> makeConfirmedCollection() {
|
||||
return new ArrayList<E>();
|
||||
}
|
||||
|
||||
public Collection<E> makeConfirmedFullCollection() {
|
||||
ArrayList<E> list = new ArrayList<E>();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -36,16 +36,16 @@ import org.apache.commons.collections.TransformerUtils;
|
|||
*
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public class TestTransformedCollection extends AbstractTestCollection {
|
||||
public class TestTransformedCollection extends AbstractTestCollection<Object> {
|
||||
|
||||
private static class StringToInteger implements Transformer {
|
||||
private static class StringToInteger implements Transformer<Object, Object> {
|
||||
public Object transform(Object input) {
|
||||
return new Integer((String) input);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Transformer NOOP_TRANSFORMER = TransformerUtils.nopTransformer();
|
||||
public static final Transformer STRING_TO_INTEGER_TRANSFORMER = new StringToInteger();
|
||||
public static final Transformer<Object, Object> NOOP_TRANSFORMER = TransformerUtils.nopTransformer();
|
||||
public static final Transformer<Object, Object> STRING_TO_INTEGER_TRANSFORMER = new StringToInteger();
|
||||
|
||||
public TestTransformedCollection(String testName) {
|
||||
super(testName);
|
||||
|
@ -61,22 +61,22 @@ public class TestTransformedCollection extends AbstractTestCollection {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Collection makeConfirmedCollection() {
|
||||
return new ArrayList();
|
||||
public Collection<Object> makeConfirmedCollection() {
|
||||
return new ArrayList<Object>();
|
||||
}
|
||||
|
||||
public Collection makeConfirmedFullCollection() {
|
||||
List list = new ArrayList();
|
||||
public Collection<Object> makeConfirmedFullCollection() {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return list;
|
||||
}
|
||||
|
||||
public Collection makeCollection() {
|
||||
return TransformedCollection.decorate(new ArrayList(), NOOP_TRANSFORMER);
|
||||
public Collection<Object> makeObject() {
|
||||
return TransformedCollection.decorate(new ArrayList<Object>(), NOOP_TRANSFORMER);
|
||||
}
|
||||
|
||||
public Collection makeFullCollection() {
|
||||
List list = new ArrayList();
|
||||
public Collection<Object> makeFullCollection() {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return TransformedCollection.decorate(list, NOOP_TRANSFORMER);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class TestTransformedCollection extends AbstractTestCollection {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testTransformedCollection() {
|
||||
Collection coll = TransformedCollection.decorate(new ArrayList(), STRING_TO_INTEGER_TRANSFORMER);
|
||||
Collection<Object> coll = TransformedCollection.decorate(new ArrayList<Object>(), STRING_TO_INTEGER_TRANSFORMER);
|
||||
assertEquals(0, coll.size());
|
||||
Object[] els = getFullElements();
|
||||
for (int i = 0; i < els.length; i++) {
|
||||
|
|
|
@ -25,7 +25,7 @@ import junit.framework.Test;
|
|||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Extension of {@link AbstractTestCollection} for exercising the
|
||||
* Extension of {@link AbstractTestCollection} for exercising the
|
||||
* {@link UnmodifiableCollection} implementation.
|
||||
*
|
||||
* @since Commons Collections 3.0
|
||||
|
@ -34,39 +34,38 @@ import junit.framework.TestSuite;
|
|||
* @author Phil Steitz
|
||||
* @author Stephen Colebourne
|
||||
*/
|
||||
public class TestUnmodifiableCollection extends AbstractTestCollection {
|
||||
|
||||
public class TestUnmodifiableCollection<E> extends AbstractTestCollection<E> {
|
||||
|
||||
public TestUnmodifiableCollection(String testName) {
|
||||
super(testName);
|
||||
}
|
||||
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestUnmodifiableCollection.class);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]) {
|
||||
String[] testCaseName = { TestUnmodifiableCollection.class.getName()};
|
||||
junit.textui.TestRunner.main(testCaseName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public Collection makeCollection() {
|
||||
return UnmodifiableCollection.decorate(new ArrayList());
|
||||
//-----------------------------------------------------------------------
|
||||
public Collection<E> makeObject() {
|
||||
return UnmodifiableCollection.decorate(new ArrayList<E>());
|
||||
}
|
||||
|
||||
public Collection makeFullCollection() {
|
||||
List list = new ArrayList();
|
||||
|
||||
public Collection<E> makeFullCollection() {
|
||||
List<E> list = new ArrayList<E>();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return UnmodifiableCollection.decorate(list);
|
||||
}
|
||||
|
||||
public Collection makeConfirmedCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
return list;
|
||||
|
||||
public Collection<E> makeConfirmedCollection() {
|
||||
return new ArrayList<E>();
|
||||
}
|
||||
|
||||
public Collection makeConfirmedFullCollection() {
|
||||
ArrayList list = new ArrayList();
|
||||
public Collection<E> makeConfirmedFullCollection() {
|
||||
ArrayList<E> list = new ArrayList<E>();
|
||||
list.addAll(Arrays.asList(getFullElements()));
|
||||
return list;
|
||||
}
|
||||
|
@ -74,7 +73,7 @@ public class TestUnmodifiableCollection extends AbstractTestCollection {
|
|||
public boolean isAddSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isRemoveSupported() {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue