[COLLECTIONS-470] Renamed TransformedMap class in splitmap package to TransformedSplitMap.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1491944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e34831a65
commit
ed085d064c
|
@ -81,7 +81,7 @@ New classes
|
||||||
o [COLLECTIONS-241] PassiveExpiringMap - map decorator which passively expires entries. Thanks to Elifarley Callado Coelho.
|
o [COLLECTIONS-241] PassiveExpiringMap - map decorator which passively expires entries. Thanks to Elifarley Callado Coelho.
|
||||||
o [COLLECTIONS-8 ] ComparatorPredicate - predicate to compare objects against a fixed instance. Thanks to Rune Peter Bjørnstad.
|
o [COLLECTIONS-8 ] ComparatorPredicate - predicate to compare objects against a fixed instance. Thanks to Rune Peter Bjørnstad.
|
||||||
o [None ] Put / Get - interfaces for split maps
|
o [None ] Put / Get - interfaces for split maps
|
||||||
o [None ] SplitMapUtils / splitmap.TransformedMap - utilities and implementation for split maps
|
o [None ] SplitMapUtils / splitmap.TransformedSplitMap - utilities and implementation for split maps
|
||||||
|
|
||||||
|
|
||||||
New methods in *Utils
|
New methods in *Utils
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately
|
Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately
|
||||||
after a difference has been found.
|
after a difference has been found.
|
||||||
</action>
|
</action>
|
||||||
|
<action issue="COLLECTIONS-470" dev="tn" type="update" due-to="sebb">
|
||||||
|
Renamed class "TransformedMap" in package "splitmap" to "TransformedSplitMap" to avoid
|
||||||
|
name clash with similar class in package "map".
|
||||||
|
</action>
|
||||||
<action issue="COLLECTIONS-466" dev="tn" type="update">
|
<action issue="COLLECTIONS-466" dev="tn" type="update">
|
||||||
Replaced "Collection" with "Iterable" for method arguments where applicable.
|
Replaced "Collection" with "Iterable" for method arguments where applicable.
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -40,7 +40,7 @@ import org.apache.commons.collections4.Transformer;
|
||||||
* <p>
|
* <p>
|
||||||
* This class is Serializable from Commons Collections 3.1.
|
* This class is Serializable from Commons Collections 3.1.
|
||||||
* <p>
|
* <p>
|
||||||
* @see org.apache.commons.collections4.splitmap.TransformedMap
|
* @see org.apache.commons.collections4.splitmap.TransformedSplitMap
|
||||||
*
|
*
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
|
|
|
@ -58,7 +58,7 @@ import org.apache.commons.collections4.map.LinkedMap;
|
||||||
* @see org.apache.commons.collections4.SplitMapUtils#readableMap(Get)
|
* @see org.apache.commons.collections4.SplitMapUtils#readableMap(Get)
|
||||||
* @see org.apache.commons.collections4.SplitMapUtils#writableMap(Put)
|
* @see org.apache.commons.collections4.SplitMapUtils#writableMap(Put)
|
||||||
*/
|
*/
|
||||||
public class TransformedMap<J, K, U, V> extends AbstractIterableGetMapDecorator<K, V>
|
public class TransformedSplitMap<J, K, U, V> extends AbstractIterableGetMapDecorator<K, V>
|
||||||
implements Put<J, U>, Serializable {
|
implements Put<J, U>, Serializable {
|
||||||
|
|
||||||
/** Serialization version */
|
/** Serialization version */
|
||||||
|
@ -87,10 +87,10 @@ public class TransformedMap<J, K, U, V> extends AbstractIterableGetMapDecorator<
|
||||||
* @return a new transformed map
|
* @return a new transformed map
|
||||||
* @throws IllegalArgumentException if map is null
|
* @throws IllegalArgumentException if map is null
|
||||||
*/
|
*/
|
||||||
public static <J, K, U, V> TransformedMap<J, K, U, V> transformingMap(final Map<K, V> map,
|
public static <J, K, U, V> TransformedSplitMap<J, K, U, V> transformingMap(final Map<K, V> map,
|
||||||
final Transformer<? super J, ? extends K> keyTransformer,
|
final Transformer<? super J, ? extends K> keyTransformer,
|
||||||
final Transformer<? super U, ? extends V> valueTransformer) {
|
final Transformer<? super U, ? extends V> valueTransformer) {
|
||||||
return new TransformedMap<J, K, U, V>(map, keyTransformer, valueTransformer);
|
return new TransformedSplitMap<J, K, U, V>(map, keyTransformer, valueTransformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -107,7 +107,7 @@ public class TransformedMap<J, K, U, V> extends AbstractIterableGetMapDecorator<
|
||||||
* means no conversion
|
* means no conversion
|
||||||
* @throws IllegalArgumentException if map is null
|
* @throws IllegalArgumentException if map is null
|
||||||
*/
|
*/
|
||||||
protected TransformedMap(final Map<K, V> map, final Transformer<? super J, ? extends K> keyTransformer,
|
protected TransformedSplitMap(final Map<K, V> map, final Transformer<? super J, ? extends K> keyTransformer,
|
||||||
final Transformer<? super U, ? extends V> valueTransformer) {
|
final Transformer<? super U, ? extends V> valueTransformer) {
|
||||||
super(map);
|
super(map);
|
||||||
if (keyTransformer == null) {
|
if (keyTransformer == null) {
|
|
@ -27,10 +27,10 @@ import org.apache.commons.collections4.Transformer;
|
||||||
import org.apache.commons.collections4.Unmodifiable;
|
import org.apache.commons.collections4.Unmodifiable;
|
||||||
import org.apache.commons.collections4.functors.NOPTransformer;
|
import org.apache.commons.collections4.functors.NOPTransformer;
|
||||||
import org.apache.commons.collections4.map.HashedMap;
|
import org.apache.commons.collections4.map.HashedMap;
|
||||||
import org.apache.commons.collections4.splitmap.TransformedMap;
|
import org.apache.commons.collections4.splitmap.TransformedSplitMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TransformedMap}
|
* Tests for {@link TransformedSplitMap}
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
|
@ -38,7 +38,7 @@ import org.apache.commons.collections4.splitmap.TransformedMap;
|
||||||
@SuppressWarnings("boxing")
|
@SuppressWarnings("boxing")
|
||||||
public class SplitMapUtilsTest extends BulkTest {
|
public class SplitMapUtilsTest extends BulkTest {
|
||||||
private Map<String, Integer> backingMap;
|
private Map<String, Integer> backingMap;
|
||||||
private TransformedMap<String, String, String, Integer> transformedMap;
|
private TransformedSplitMap<String, String, String, Integer> transformedMap;
|
||||||
|
|
||||||
private final Transformer<String, Integer> stringToInt = new Transformer<String, Integer>() {
|
private final Transformer<String, Integer> stringToInt = new Transformer<String, Integer>() {
|
||||||
public Integer transform(final String input) {
|
public Integer transform(final String input) {
|
||||||
|
@ -54,7 +54,7 @@ public class SplitMapUtilsTest extends BulkTest {
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
backingMap = new HashMap<String, Integer>();
|
backingMap = new HashMap<String, Integer>();
|
||||||
transformedMap = TransformedMap.transformingMap(backingMap, NOPTransformer.<String> nopTransformer(),
|
transformedMap = TransformedSplitMap.transformingMap(backingMap, NOPTransformer.<String> nopTransformer(),
|
||||||
stringToInt);
|
stringToInt);
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
transformedMap.put(String.valueOf(i), String.valueOf(i));
|
transformedMap.put(String.valueOf(i), String.valueOf(i));
|
||||||
|
|
|
@ -26,17 +26,13 @@ import org.apache.commons.collections4.Transformer;
|
||||||
import org.apache.commons.collections4.functors.NOPTransformer;
|
import org.apache.commons.collections4.functors.NOPTransformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TransformedMap}
|
* Tests for {@link TransformedSplitMap}
|
||||||
*
|
|
||||||
* TODO fix version, add Serialization tests
|
|
||||||
* FIXME the serialization result is stored as TransformedSplitMap.versionX.obj
|
|
||||||
* to distinguish it from the one for o.a.c.c.map.TransformedMap.
|
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("boxing")
|
@SuppressWarnings("boxing")
|
||||||
public class TransformedMapTest extends BulkTest {
|
public class TransformedSplitMapTest extends BulkTest {
|
||||||
|
|
||||||
private final Transformer<Integer, String> intToString = new Transformer<Integer, String>() {
|
private final Transformer<Integer, String> intToString = new Transformer<Integer, String>() {
|
||||||
public String transform(final Integer input) {
|
public String transform(final Integer input) {
|
||||||
|
@ -56,13 +52,13 @@ public class TransformedMapTest extends BulkTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public TransformedMapTest(final String testName) {
|
public TransformedSplitMapTest(final String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
public void testTransformedMap() {
|
public void testTransformedMap() {
|
||||||
final TransformedMap<Integer, String, Object, Class<?>> map = TransformedMap.transformingMap(
|
final TransformedSplitMap<Integer, String, Object, Class<?>> map = TransformedSplitMap.transformingMap(
|
||||||
new HashMap<String, Class<?>>(), intToString, objectToClass);
|
new HashMap<String, Class<?>>(), intToString, objectToClass);
|
||||||
|
|
||||||
final Integer[] k = new Integer[] { 0, 1, 2, 3, 4, 5, 6 };
|
final Integer[] k = new Integer[] { 0, 1, 2, 3, 4, 5, 6 };
|
||||||
|
@ -86,7 +82,7 @@ public class TransformedMapTest extends BulkTest {
|
||||||
assertEquals(objectToClass.transform(v[0]), map.remove(intToString.transform(k[0])));
|
assertEquals(objectToClass.transform(v[0]), map.remove(intToString.transform(k[0])));
|
||||||
assertEquals(--sz, map.size());
|
assertEquals(--sz, map.size());
|
||||||
|
|
||||||
final TransformedMap<String, String, String, Integer> map2 = TransformedMap.transformingMap(
|
final TransformedSplitMap<String, String, String, Integer> map2 = TransformedSplitMap.transformingMap(
|
||||||
new HashMap<String, Integer>(), NOPTransformer.<String> nopTransformer(), stringToInt);
|
new HashMap<String, Integer>(), NOPTransformer.<String> nopTransformer(), stringToInt);
|
||||||
assertEquals(0, map2.size());
|
assertEquals(0, map2.size());
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
|
@ -106,8 +102,9 @@ public class TransformedMapTest extends BulkTest {
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
public void testMapIterator() {
|
public void testMapIterator() {
|
||||||
final TransformedMap<String, String, String, Integer> map = TransformedMap.transformingMap(
|
final TransformedSplitMap<String, String, String, Integer> map =
|
||||||
new HashMap<String, Integer>(), NOPTransformer.<String> nopTransformer(), stringToInt);
|
TransformedSplitMap.transformingMap(new HashMap<String, Integer>(),
|
||||||
|
NOPTransformer.<String> nopTransformer(), stringToInt);
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
map.put(String.valueOf(i), String.valueOf(i));
|
map.put(String.valueOf(i), String.valueOf(i));
|
||||||
|
@ -121,22 +118,23 @@ public class TransformedMapTest extends BulkTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyMap() throws IOException, ClassNotFoundException {
|
public void testEmptyMap() throws IOException, ClassNotFoundException {
|
||||||
final TransformedMap<String, String, String, String> map = TransformedMap.transformingMap(
|
final TransformedSplitMap<String, String, String, String> map =
|
||||||
new HashMap<String, String>(),
|
TransformedSplitMap.transformingMap(new HashMap<String, String>(),
|
||||||
NOPTransformer.<String>nopTransformer(),
|
NOPTransformer.<String>nopTransformer(),
|
||||||
NOPTransformer.<String>nopTransformer() );
|
NOPTransformer.<String>nopTransformer() );
|
||||||
|
|
||||||
final ObjectInputStream in = new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"/TransformedSplitMap.emptyCollection.version4.obj" ) );
|
final ObjectInputStream in =
|
||||||
|
new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"/TransformedSplitMap.emptyCollection.version4.obj" ) );
|
||||||
final Object readObject = in.readObject();
|
final Object readObject = in.readObject();
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
final TransformedMap<?, ?, ?, ?> readMap = (TransformedMap<?, ?, ?, ?>) readObject;
|
final TransformedSplitMap<?, ?, ?, ?> readMap = (TransformedSplitMap<?, ?, ?, ?>) readObject;
|
||||||
assertTrue( "Map should be empty", readMap.size() == 0 );
|
assertTrue( "Map should be empty", readMap.size() == 0 );
|
||||||
assertEquals( map.entrySet(), readMap.entrySet() );
|
assertEquals( map.entrySet(), readMap.entrySet() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFullMap() throws IOException, ClassNotFoundException {
|
public void testFullMap() throws IOException, ClassNotFoundException {
|
||||||
final TransformedMap<String, String, String, String> map = TransformedMap.transformingMap(
|
final TransformedSplitMap<String, String, String, String> map = TransformedSplitMap.transformingMap(
|
||||||
new HashMap<String, String>(),
|
new HashMap<String, String>(),
|
||||||
NOPTransformer.<String>nopTransformer(),
|
NOPTransformer.<String>nopTransformer(),
|
||||||
NOPTransformer.<String>nopTransformer() );
|
NOPTransformer.<String>nopTransformer() );
|
||||||
|
@ -145,17 +143,18 @@ public class TransformedMapTest extends BulkTest {
|
||||||
map.put( "e", "f" );
|
map.put( "e", "f" );
|
||||||
map.put( "g", "h" );
|
map.put( "g", "h" );
|
||||||
|
|
||||||
final ObjectInputStream in = new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"TransformedSplitMap.fullCollection.version4.obj" ) );
|
final ObjectInputStream in =
|
||||||
|
new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"TransformedSplitMap.fullCollection.version4.obj" ) );
|
||||||
final Object readObject = in.readObject();
|
final Object readObject = in.readObject();
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
final TransformedMap<?, ?, ?, ?> readMap = (TransformedMap<?, ?, ?, ?>) readObject;
|
final TransformedSplitMap<?, ?, ?, ?> readMap = (TransformedSplitMap<?, ?, ?, ?>) readObject;
|
||||||
assertFalse( "Map should not be empty", readMap.size() == 0 );
|
assertFalse( "Map should not be empty", readMap.size() == 0 );
|
||||||
assertEquals( map.entrySet(), readMap.entrySet() );
|
assertEquals( map.entrySet(), readMap.entrySet() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testCreate() throws IOException {
|
// public void testCreate() throws IOException {
|
||||||
// TransformedMap<String, String, String, String> map = TransformedMap.transformingMap(
|
// TransformedSplitMap<String, String, String, String> map = TransformedSplitMap.transformingMap(
|
||||||
// new HashMap<String, String>(),
|
// new HashMap<String, String>(),
|
||||||
// NOPTransformer.<String>nopTransformer(),
|
// NOPTransformer.<String>nopTransformer(),
|
||||||
// NOPTransformer.<String>nopTransformer() );
|
// NOPTransformer.<String>nopTransformer() );
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue