You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2017/07/11 17:54:49 UTC
[04/77] [abbrv] commons-collections git commit: finish generics
(minus one class)
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java b/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java
index 135bb1f..b56e372 100644
--- a/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java
+++ b/src/test/org/apache/commons/collections/map/AbstractTestSortedMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -30,24 +30,24 @@ import org.apache.commons.collections.BulkTest;
* Abstract test class for {@link java.util.SortedMap} methods and contracts.
*
* @version $Revision$ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public abstract class AbstractTestSortedMap extends AbstractTestMap {
+public abstract class AbstractTestSortedMap<K, V> extends AbstractTestMap<K, V> {
/**
* JUnit constructor.
- *
+ *
* @param testName the test name
*/
public AbstractTestSortedMap(String testName) {
super(testName);
}
-
+
//-----------------------------------------------------------------------
/**
* Can't sort null keys.
- *
+ *
* @return false
*/
public boolean isAllowNullKey() {
@@ -56,53 +56,67 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
/**
* SortedMap uses TreeMap as its known comparison.
- *
+ *
* @return a map that is known to be valid
*/
- public Map makeConfirmedMap() {
- return new TreeMap();
+ public SortedMap<K, V> makeConfirmedMap() {
+ return new TreeMap<K, V>();
}
//-----------------------------------------------------------------------
public void testComparator() {
- SortedMap sm = (SortedMap) makeFullMap();
+// SortedMap<K, V> sm = makeFullMap();
// no tests I can think of
}
-
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract SortedMap<K, V> makeObject();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SortedMap<K, V> makeFullMap() {
+ return (SortedMap<K, V>) super.makeFullMap();
+ }
+
public void testFirstKey() {
- SortedMap sm = (SortedMap) makeFullMap();
+ SortedMap<K, V> sm = makeFullMap();
assertSame(sm.keySet().iterator().next(), sm.firstKey());
}
-
+
public void testLastKey() {
- SortedMap sm = (SortedMap) makeFullMap();
- Object obj = null;
- for (Iterator it = sm.keySet().iterator(); it.hasNext();) {
- obj = (Object) it.next();
+ SortedMap<K, V> sm = makeFullMap();
+ K obj = null;
+ for (Iterator<K> it = sm.keySet().iterator(); it.hasNext();) {
+ obj = it.next();
}
assertSame(obj, sm.lastKey());
}
-
- //-----------------------------------------------------------------------
+
+ //-----------------------------------------------------------------------
public BulkTest bulkTestHeadMap() {
- return new TestHeadMap(this);
+ return new TestHeadMap<K, V>(this);
}
public BulkTest bulkTestTailMap() {
- return new TestTailMap(this);
+ return new TestTailMap<K, V>(this);
}
public BulkTest bulkTestSubMap() {
- return new TestSubMap(this);
+ return new TestSubMap<K, V>(this);
}
- public static abstract class TestViewMap extends AbstractTestSortedMap {
- protected final AbstractTestMap main;
- protected final List subSortedKeys = new ArrayList();
- protected final List subSortedValues = new ArrayList();
- protected final List subSortedNewValues = new ArrayList();
-
- public TestViewMap(String name, AbstractTestMap main) {
+ public static abstract class TestViewMap <K, V> extends AbstractTestSortedMap<K, V> {
+ protected final AbstractTestMap<K, V> main;
+ protected final List<K> subSortedKeys = new ArrayList<K>();
+ protected final List<V> subSortedValues = new ArrayList<V>();
+ protected final List<V> subSortedNewValues = new ArrayList<V>();
+
+ public TestViewMap(String name, AbstractTestMap<K, V> main) {
super(name);
this.main = main;
}
@@ -130,17 +144,20 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
public BulkTest bulkTestSubMap() {
return null; // block infinite recursion
}
-
- public Object[] getSampleKeys() {
- return subSortedKeys.toArray();
+
+ @SuppressWarnings("unchecked")
+ public K[] getSampleKeys() {
+ return (K[]) subSortedKeys.toArray();
}
- public Object[] getSampleValues() {
- return subSortedValues.toArray();
+ @SuppressWarnings("unchecked")
+ public V[] getSampleValues() {
+ return (V[]) subSortedValues.toArray();
}
- public Object[] getNewSampleValues() {
- return subSortedNewValues.toArray();
+ @SuppressWarnings("unchecked")
+ public V[] getNewSampleValues() {
+ return (V[]) subSortedNewValues.toArray();
}
-
+
public boolean isAllowNullKey() {
return main.isAllowNullKey();
}
@@ -176,16 +193,16 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
// super.testFullMapCompatibility();
// }
}
-
- public static class TestHeadMap extends TestViewMap {
+
+ public static class TestHeadMap<K, V> extends TestViewMap<K, V> {
static final int SUBSIZE = 6;
- final Object toKey;
-
- public TestHeadMap(AbstractTestMap main) {
+ final K toKey;
+
+ public TestHeadMap(AbstractTestMap<K, V> main) {
super("SortedMap.HeadMap", main);
- SortedMap sm = (SortedMap) main.makeFullMap();
- for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ Map<K, V> sm = main.makeFullMap();
+ for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue());
}
@@ -194,18 +211,18 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
this.subSortedValues.subList(SUBSIZE, this.subSortedValues.size()).clear();
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(0, SUBSIZE));
}
- public Map makeEmptyMap() {
+ public SortedMap<K, V> makeObject() {
// done this way so toKey is correctly set in the returned map
- return ((SortedMap) main.makeEmptyMap()).headMap(toKey);
+ return ((SortedMap<K, V>) main.makeObject()).headMap(toKey);
}
- public Map makeFullMap() {
- return ((SortedMap) main.makeFullMap()).headMap(toKey);
+ public SortedMap<K, V> makeFullMap() {
+ return ((SortedMap<K, V>) main.makeFullMap()).headMap(toKey);
}
public void testHeadMapOutOfRange() {
if (isPutAddSupported() == false) return;
resetEmpty();
try {
- ((SortedMap) map).put(toKey, subSortedValues.get(0));
+ getMap().put(toKey, subSortedValues.get(0));
fail();
} catch (IllegalArgumentException ex) {}
verify();
@@ -225,17 +242,17 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
// "D:/dev/collections/data/test/FixedSizeSortedMap.fullCollection.version3.1.HeadMapView.obj");
// }
}
-
- public static class TestTailMap extends TestViewMap {
+
+ public static class TestTailMap <K, V> extends TestViewMap<K, V> {
static final int SUBSIZE = 6;
- final Object fromKey;
- final Object invalidKey;
-
- public TestTailMap(AbstractTestMap main) {
+ final K fromKey;
+ final K invalidKey;
+
+ public TestTailMap(AbstractTestMap<K, V> main) {
super("SortedMap.TailMap", main);
- SortedMap sm = (SortedMap) main.makeFullMap();
- for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ Map<K, V> sm = main.makeFullMap();
+ for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue());
}
@@ -245,18 +262,18 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
this.subSortedValues.subList(0, this.subSortedValues.size() - SUBSIZE).clear();
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(0, SUBSIZE));
}
- public Map makeEmptyMap() {
+ public SortedMap<K, V> makeObject() {
// done this way so toKey is correctly set in the returned map
- return ((SortedMap) main.makeEmptyMap()).tailMap(fromKey);
+ return ((SortedMap<K, V>) main.makeObject()).tailMap(fromKey);
}
- public Map makeFullMap() {
- return ((SortedMap) main.makeFullMap()).tailMap(fromKey);
+ public SortedMap<K, V> makeFullMap() {
+ return ((SortedMap<K, V>) main.makeFullMap()).tailMap(fromKey);
}
public void testTailMapOutOfRange() {
if (isPutAddSupported() == false) return;
resetEmpty();
try {
- ((SortedMap) map).put(invalidKey, subSortedValues.get(0));
+ getMap().put(invalidKey, subSortedValues.get(0));
fail();
} catch (IllegalArgumentException ex) {}
verify();
@@ -276,45 +293,45 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
// "D:/dev/collections/data/test/FixedSizeSortedMap.fullCollection.version3.1.TailMapView.obj");
// }
}
-
- public static class TestSubMap extends TestViewMap {
+
+ public static class TestSubMap<K, V> extends TestViewMap<K, V> {
static final int SUBSIZE = 3;
- final Object fromKey;
- final Object toKey;
-
- public TestSubMap(AbstractTestMap main) {
+ final K fromKey;
+ final K toKey;
+
+ public TestSubMap(AbstractTestMap<K, V> main) {
super("SortedMap.SubMap", main);
- SortedMap sm = (SortedMap) main.makeFullMap();
- for (Iterator it = sm.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
+ Map<K, V> sm = main.makeFullMap();
+ for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
+ Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue());
}
this.fromKey = this.subSortedKeys.get(SUBSIZE);
this.toKey = this.subSortedKeys.get(this.subSortedKeys.size() - SUBSIZE);
-
+
this.subSortedKeys.subList(0, SUBSIZE).clear();
this.subSortedKeys.subList(this.subSortedKeys.size() - SUBSIZE, this.subSortedKeys.size()).clear();
-
+
this.subSortedValues.subList(0, SUBSIZE).clear();
this.subSortedValues.subList(this.subSortedValues.size() - SUBSIZE, this.subSortedValues.size()).clear();
-
+
this.subSortedNewValues.addAll(Arrays.asList(main.getNewSampleValues()).subList(
SUBSIZE, this.main.getNewSampleValues().length - SUBSIZE));
}
-
- public Map makeEmptyMap() {
+
+ public SortedMap<K, V> makeObject() {
// done this way so toKey is correctly set in the returned map
- return ((SortedMap) main.makeEmptyMap()).subMap(fromKey, toKey);
+ return ((SortedMap<K, V>) main.makeObject()).subMap(fromKey, toKey);
}
- public Map makeFullMap() {
- return ((SortedMap) main.makeFullMap()).subMap(fromKey, toKey);
+ public SortedMap<K, V> makeFullMap() {
+ return ((SortedMap<K, V>) main.makeFullMap()).subMap(fromKey, toKey);
}
public void testSubMapOutOfRange() {
if (isPutAddSupported() == false) return;
resetEmpty();
try {
- ((SortedMap) map).put(toKey, subSortedValues.get(0));
+ getMap().put(toKey, subSortedValues.get(0));
fail();
} catch (IllegalArgumentException ex) {}
verify();
@@ -334,5 +351,20 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
// "D:/dev/collections/data/test/TransformedSortedMap.fullCollection.version3.1.SubMapView.obj");
// }
}
-
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SortedMap<K, V> getMap() {
+ return (SortedMap<K, V>) super.getMap();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SortedMap<K, V> getConfirmed() {
+ return (SortedMap<K, V>) super.getConfirmed();
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java b/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
index 29fe553..167a183 100644
--- a/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
+++ b/src/test/org/apache/commons/collections/map/TestCaseInsensitiveMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -27,12 +27,12 @@ import org.apache.commons.collections.BulkTest;
/**
* Tests for the {@link CaseInsensitiveMap} implementation.
- *
+ *
* @version $Revision$ $Date$
- *
+ *
* @author Commons-Collections team
*/
-public class TestCaseInsensitiveMap extends AbstractTestIterableMap {
+public class TestCaseInsensitiveMap<K, V> extends AbstractTestIterableMap<K, V> {
public TestCaseInsensitiveMap(String testName) {
super(testName);
@@ -41,74 +41,77 @@ public class TestCaseInsensitiveMap extends AbstractTestIterableMap {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestCaseInsensitiveMap.class);
}
- public Map makeEmptyMap() {
- return new CaseInsensitiveMap();
+ public CaseInsensitiveMap<K, V> makeObject() {
+ return new CaseInsensitiveMap<K, V>();
}
-
+
public String getCompatibilityVersion() {
return "3";
}
-
+
//-------------------------------------------------------------------------
-
+
+ @SuppressWarnings("unchecked")
public void testCaseInsensitive() {
- Map map = new CaseInsensitiveMap();
- map.put("One", "One");
- map.put("Two", "Two");
- assertEquals("One", (String) map.get("one"));
- assertEquals("One", (String) map.get("oNe"));
- map.put("two", "Three");
- assertEquals("Three", (String) map.get("Two"));
- }
-
+ Map<K, V> map = makeObject();
+ map.put((K) "One", (V) "One");
+ map.put((K) "Two", (V) "Two");
+ assertEquals("One", map.get("one"));
+ assertEquals("One", map.get("oNe"));
+ map.put((K) "two", (V) "Three");
+ assertEquals("Three", map.get("Two"));
+ }
+
+ @SuppressWarnings("unchecked")
public void testNullHandling() {
- Map map = new CaseInsensitiveMap();
- map.put("One", "One");
- map.put("Two", "Two");
- map.put(null, "Three");
- assertEquals("Three", (String) map.get(null));
- map.put(null, "Four");
- assertEquals("Four", (String) map.get(null));
- Set keys = map.keySet();
+ Map<K, V> map = makeObject();
+ map.put((K) "One", (V) "One");
+ map.put((K) "Two", (V) "Two");
+ map.put(null, (V) "Three");
+ assertEquals("Three", map.get(null));
+ map.put(null, (V) "Four");
+ assertEquals("Four", map.get(null));
+ Set<K> keys = map.keySet();
assertTrue(keys.contains("one"));
assertTrue(keys.contains("two"));
assertTrue(keys.contains(null));
assertTrue(keys.size() == 3);
}
-
+
public void testPutAll() {
- Map map = new HashMap();
+ Map<Object, String> map = new HashMap<Object, String>();
map.put("One", "One");
map.put("Two", "Two");
map.put("one", "Three");
map.put(null, "Four");
map.put(new Integer(20), "Five");
- Map caseInsensitiveMap = new CaseInsensitiveMap(map);
+ Map<Object, String> caseInsensitiveMap = new CaseInsensitiveMap<Object, String>(map);
assertTrue(caseInsensitiveMap.size() == 4); // ones collapsed
- Set keys = caseInsensitiveMap.keySet();
+ Set<Object> keys = caseInsensitiveMap.keySet();
assertTrue(keys.contains("one"));
assertTrue(keys.contains("two"));
assertTrue(keys.contains(null));
assertTrue(keys.contains(Integer.toString(20)));
assertTrue(keys.size() == 4);
- assertTrue(!caseInsensitiveMap.containsValue("One")
+ assertTrue(!caseInsensitiveMap.containsValue("One")
|| !caseInsensitiveMap.containsValue("Three")); // ones collaped
assertEquals(caseInsensitiveMap.get(null), "Four");
- }
+ }
+ @SuppressWarnings("unchecked")
public void testClone() {
- CaseInsensitiveMap map = new CaseInsensitiveMap(10);
- map.put("1", "1");
- Map cloned = (Map) map.clone();
+ CaseInsensitiveMap<K, V> map = new CaseInsensitiveMap<K, V>(10);
+ map.put((K) "1", (V) "1");
+ CaseInsensitiveMap<K, V> cloned = map.clone();
assertEquals(map.size(), cloned.size());
assertSame(map.get("1"), cloned.get("1"));
}
-
+
/*
public void testCreate() throws Exception {
resetEmpty();
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/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 076b58a..7fd3e6e 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 extends AbstractTestMap {
+public class TestCompositeMap<K, V> extends AbstractTestMap<K, V> {
/** used as a flag in MapMutator tests */
private boolean pass = false;
@@ -55,22 +55,20 @@ public class TestCompositeMap extends AbstractTestMap {
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeEmptyMap() {
- CompositeMap map = new CompositeMap();
- map.addComposited(new HashMap());
- map.setMutator(new CompositeMap.MapMutator() {
- public void resolveCollision(CompositeMap composite,
- Map existing,
- Map added,
- Collection intersect) {
+ public CompositeMap<K, V> makeObject() {
+ CompositeMap<K, V> map = new CompositeMap<K, V>();
+ map.addComposited(new HashMap<K, V>());
+ map.setMutator(new CompositeMap.MapMutator<K, V>() {
+ public void resolveCollision(CompositeMap<K, V> composite, Map<K, V> existing,
+ Map<K, V> added, Collection<K> intersect) {
// Do nothing
}
- public Object put(CompositeMap map, Map[] composited, Object key, Object value) {
+ public V put(CompositeMap<K, V> map, Map<K, V>[] composited, K key, V value) {
return composited[0].put(key, value);
}
- public void putAll(CompositeMap map, Map[] composited, Map t) {
+ public void putAll(CompositeMap<K, V> map, Map<K, V>[] composited, Map<? extends K, ? extends V> t) {
composited[0].putAll(t);
}
@@ -78,30 +76,33 @@ public class TestCompositeMap extends AbstractTestMap {
return map;
}
- private Map buildOne() {
- HashMap map = new HashMap();
- map.put("1", "one");
- map.put("2", "two");
+ @SuppressWarnings("unchecked")
+ private Map<K, V> buildOne() {
+ HashMap<K, V> map = new HashMap<K, V>();
+ map.put((K) "1", (V) "one");
+ map.put((K) "2", (V) "two");
return map;
}
- public Map buildTwo() {
- HashMap map = new HashMap();
- map.put("3", "three");
- map.put("4", "four");
+ @SuppressWarnings("unchecked")
+ public Map<K, V> buildTwo() {
+ HashMap<K, V> map = new HashMap<K, V>();
+ map.put((K) "3", (V) "three");
+ map.put((K) "4", (V) "four");
return map;
}
public void testGet() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo());
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
Assert.assertEquals("one", map.get("1"));
Assert.assertEquals("four", map.get("4"));
}
+ @SuppressWarnings("unchecked")
public void testAddComposited() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo());
- HashMap three = new HashMap();
- three.put("5", "five");
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+ HashMap<K, V> three = new HashMap<K, V>();
+ three.put((K) "5", (V) "five");
map.addComposited(three);
assertTrue(map.containsKey("5"));
try {
@@ -112,10 +113,11 @@ public class TestCompositeMap extends AbstractTestMap {
}
}
+ @SuppressWarnings("unchecked")
public void testRemoveComposited() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo());
- HashMap three = new HashMap();
- three.put("5", "five");
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+ HashMap<K, V> three = new HashMap<K, V>();
+ three.put((K) "5", (V) "five");
map.addComposited(three);
assertTrue(map.containsKey("5"));
@@ -127,10 +129,11 @@ public class TestCompositeMap extends AbstractTestMap {
}
+ @SuppressWarnings("unchecked")
public void testRemoveFromUnderlying() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo());
- HashMap three = new HashMap();
- three.put("5", "five");
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+ HashMap<K, V> three = new HashMap<K, V>();
+ three.put((K) "5", (V) "five");
map.addComposited(three);
assertTrue(map.containsKey("5"));
@@ -139,10 +142,11 @@ public class TestCompositeMap extends AbstractTestMap {
assertFalse(map.containsKey("5"));
}
+ @SuppressWarnings("unchecked")
public void testRemoveFromComposited() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo());
- HashMap three = new HashMap();
- three.put("5", "five");
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo());
+ HashMap<K, V> three = new HashMap<K, V>();
+ three.put((K) "5", (V) "five");
map.addComposited(three);
assertTrue(map.containsKey("5"));
@@ -152,21 +156,21 @@ public class TestCompositeMap extends AbstractTestMap {
}
public void testResolveCollision() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo(),
- new CompositeMap.MapMutator() {
- public void resolveCollision(CompositeMap composite,
- Map existing,
- Map added,
- Collection intersect) {
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo(),
+ new CompositeMap.MapMutator<K, V>() {
+ public void resolveCollision(CompositeMap<K, V> composite,
+ Map<K, V> existing,
+ Map<K, V> added,
+ Collection<K> intersect) {
pass = true;
}
- public Object put(CompositeMap map, Map[] composited, Object key,
- Object value) {
+ public V put(CompositeMap<K, V> map, Map<K, V>[] composited, K key,
+ V value) {
throw new UnsupportedOperationException();
}
- public void putAll(CompositeMap map, Map[] composited, Map t) {
+ public void putAll(CompositeMap<K, V> map, Map<K, V>[] composited, Map<? extends K, ? extends V> t) {
throw new UnsupportedOperationException();
}
});
@@ -175,47 +179,48 @@ public class TestCompositeMap extends AbstractTestMap {
assertTrue(pass);
}
+ @SuppressWarnings("unchecked")
public void testPut() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo(),
- new CompositeMap.MapMutator() {
- public void resolveCollision(CompositeMap composite,
- Map existing,
- Map added,
- Collection intersect) {
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo(),
+ new CompositeMap.MapMutator<K, V>() {
+ public void resolveCollision(CompositeMap<K, V> composite,
+ Map<K, V> existing,
+ Map<K, V> added,
+ Collection<K> intersect) {
throw new UnsupportedOperationException();
}
- public Object put(CompositeMap map, Map[] composited, Object key,
- Object value) {
+ public V put(CompositeMap<K, V> map, Map<K, V>[] composited, K key,
+ V value) {
pass = true;
- return "foo";
+ return (V) "foo";
}
- public void putAll(CompositeMap map, Map[] composited, Map t) {
+ public void putAll(CompositeMap<K, V> map, Map<K, V>[] composited, Map<? extends K, ? extends V> t) {
throw new UnsupportedOperationException();
}
});
- map.put("willy", "wonka");
+ map.put((K) "willy", (V) "wonka");
assertTrue(pass);
}
public void testPutAll() {
- CompositeMap map = new CompositeMap(buildOne(), buildTwo(),
- new CompositeMap.MapMutator() {
- public void resolveCollision(CompositeMap composite,
- Map existing,
- Map added,
- Collection intersect) {
+ CompositeMap<K, V> map = new CompositeMap<K, V>(buildOne(), buildTwo(),
+ new CompositeMap.MapMutator<K, V>() {
+ public void resolveCollision(CompositeMap<K, V> composite,
+ Map<K, V> existing,
+ Map<K, V> added,
+ Collection<K> intersect) {
throw new UnsupportedOperationException();
}
- public Object put(CompositeMap map, Map[] composited, Object key,
- Object value) {
+ public V put(CompositeMap<K, V> map, Map<K, V>[] composited, K key,
+ V value) {
throw new UnsupportedOperationException();
}
- public void putAll(CompositeMap map, Map[] composited, Map t) {
+ public void putAll(CompositeMap<K, V> map, Map<K, V>[] composited, Map<? extends K, ? extends V> t) {
pass = true;
}
});
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/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 fc2e1cd..ac0576a 100644
--- a/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
+++ b/src/test/org/apache/commons/collections/map/TestDefaultedMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -28,17 +28,17 @@ import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.functors.ConstantFactory;
/**
- * Extension of {@link TestMap} for exercising the
+ * Extension of {@link TestMap} for exercising the
* {@link DefaultedMap} implementation.
*
* @since Commons Collections 3.2
* @version $Revision: 155406 $ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public class TestDefaultedMap extends AbstractTestMap {
+public class TestDefaultedMap<K, V> extends AbstractTestMap<K, V> {
- protected static final Factory nullFactory = FactoryUtils.nullFactory();
+ protected final Factory<V> nullFactory = FactoryUtils.<V>nullFactory();
public TestDefaultedMap(String testName) {
super(testName);
@@ -53,20 +53,21 @@ public class TestDefaultedMap extends AbstractTestMap {
junit.textui.TestRunner.main(testCaseName);
}
- //-----------------------------------------------------------------------
- public Map makeEmptyMap() {
- return DefaultedMap.decorate(new HashMap(), nullFactory);
+ //-----------------------------------------------------------------------
+ public Map<K, V> makeObject() {
+ return DefaultedMap.decorate(new HashMap<K, V>(), nullFactory);
}
- //-----------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testMapGet() {
- Map map = new DefaultedMap("NULL");
-
+ Map<K, V> map = new DefaultedMap<K, V>((V) "NULL");
+
assertEquals(0, map.size());
assertEquals(false, map.containsKey("NotInMap"));
assertEquals("NULL", map.get("NotInMap"));
-
- map.put("Key", "Value");
+
+ map.put((K) "Key", (V) "Value");
assertEquals(1, map.size());
assertEquals(true, map.containsKey("Key"));
assertEquals("Value", map.get("Key"));
@@ -74,16 +75,17 @@ public class TestDefaultedMap extends AbstractTestMap {
assertEquals("NULL", map.get("NotInMap"));
}
+ @SuppressWarnings("unchecked")
public void testMapGet2() {
- HashMap base = new HashMap();
- Map map = DefaultedMap.decorate(base, "NULL");
-
+ HashMap<K, V> base = new HashMap<K, V>();
+ Map<K, V> map = DefaultedMap.decorate(base, (V) "NULL");
+
assertEquals(0, map.size());
assertEquals(0, base.size());
assertEquals(false, map.containsKey("NotInMap"));
assertEquals("NULL", map.get("NotInMap"));
-
- map.put("Key", "Value");
+
+ map.put((K) "Key", (V) "Value");
assertEquals(1, map.size());
assertEquals(1, base.size());
assertEquals(true, map.containsKey("Key"));
@@ -92,16 +94,17 @@ public class TestDefaultedMap extends AbstractTestMap {
assertEquals("NULL", map.get("NotInMap"));
}
+ @SuppressWarnings("unchecked")
public void testMapGet3() {
- HashMap base = new HashMap();
- Map map = DefaultedMap.decorate(base, ConstantFactory.getInstance("NULL"));
-
+ HashMap<K, V> base = new HashMap<K, V>();
+ Map<K, V> map = DefaultedMap.decorate(base, ConstantFactory.getInstance((V) "NULL"));
+
assertEquals(0, map.size());
assertEquals(0, base.size());
assertEquals(false, map.containsKey("NotInMap"));
assertEquals("NULL", map.get("NotInMap"));
-
- map.put("Key", "Value");
+
+ map.put((K) "Key", (V) "Value");
assertEquals(1, map.size());
assertEquals(1, base.size());
assertEquals(true, map.containsKey("Key"));
@@ -110,24 +113,25 @@ public class TestDefaultedMap extends AbstractTestMap {
assertEquals("NULL", map.get("NotInMap"));
}
+ @SuppressWarnings("unchecked")
public void testMapGet4() {
- HashMap base = new HashMap();
- Map map = DefaultedMap.decorate(base, new Transformer() {
- public Object transform(Object input) {
+ HashMap<K, V> base = new HashMap<K, V>();
+ Map<K, V> map = DefaultedMap.decorate(base, new Transformer<K, V>() {
+ public V transform(K input) {
if (input instanceof String) {
- return "NULL";
+ return (V) "NULL";
}
- return "NULL_OBJECT";
+ return (V) "NULL_OBJECT";
}
});
-
+
assertEquals(0, map.size());
assertEquals(0, base.size());
assertEquals(false, map.containsKey("NotInMap"));
assertEquals("NULL", map.get("NotInMap"));
assertEquals("NULL_OBJECT", map.get(new Integer(0)));
-
- map.put("Key", "Value");
+
+ map.put((K) "Key", (V) "Value");
assertEquals(1, map.size());
assertEquals(1, base.size());
assertEquals(true, map.containsKey("Key"));
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/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 6d24cc1..e70bd7a 100644
--- a/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java
+++ b/src/test/org/apache/commons/collections/map/TestFixedSizeMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -28,10 +28,10 @@ import junit.framework.TestSuite;
*
* @since Commons Collections 3.0
* @version $Revision$ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public class TestFixedSizeMap extends AbstractTestMap {
+public class TestFixedSizeMap<K, V> extends AbstractTestMap<K, V> {
public TestFixedSizeMap(String testName) {
super(testName);
@@ -46,16 +46,16 @@ public class TestFixedSizeMap extends AbstractTestMap {
junit.textui.TestRunner.main(testCaseName);
}
- public Map makeEmptyMap() {
- return FixedSizeMap.decorate(new HashMap());
+ public Map<K, V> makeObject() {
+ return FixedSizeMap.decorate(new HashMap<K, V>());
}
- public Map makeFullMap() {
- Map map = new HashMap();
+ public Map<K, V> makeFullMap() {
+ Map<K, V> map = new HashMap<K, V>();
addSampleMappings(map);
return FixedSizeMap.decorate(map);
}
-
+
public boolean isPutAddSupported() {
return false;
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java b/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java
index e244684..0d2aff6 100644
--- a/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java
+++ b/src/test/org/apache/commons/collections/map/TestFixedSizeSortedMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -16,7 +16,6 @@
*/
package org.apache.commons.collections.map;
-import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -30,10 +29,10 @@ import org.apache.commons.collections.BulkTest;
*
* @since Commons Collections 3.0
* @version $Revision$ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public class TestFixedSizeSortedMap extends AbstractTestSortedMap {
+public class TestFixedSizeSortedMap<K, V> extends AbstractTestSortedMap<K, V> {
public TestFixedSizeSortedMap(String testName) {
super(testName);
@@ -49,16 +48,16 @@ public class TestFixedSizeSortedMap extends AbstractTestSortedMap {
}
//-----------------------------------------------------------------------
- public Map makeEmptyMap() {
- return FixedSizeSortedMap.decorate(new TreeMap());
+ public SortedMap<K, V> makeObject() {
+ return FixedSizeSortedMap.decorate(new TreeMap<K, V>());
}
- public Map makeFullMap() {
- SortedMap map = new TreeMap();
+ public SortedMap<K, V> makeFullMap() {
+ SortedMap<K, V> map = new TreeMap<K, V>();
addSampleMappings(map);
return FixedSizeSortedMap.decorate(map);
}
-
+
public boolean isSubMapViewsSerializable() {
// TreeMap sub map views have a bug in deserialization.
return false;
@@ -76,7 +75,7 @@ public class TestFixedSizeSortedMap extends AbstractTestSortedMap {
public String getCompatibilityVersion() {
return "3.1";
}
-
+
// public void testCreate() throws Exception {
// resetEmpty();
// writeExternalFormToDisk(
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestFlat3Map.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/TestFlat3Map.java b/src/test/org/apache/commons/collections/map/TestFlat3Map.java
index 53a901e..fdf452e 100644
--- a/src/test/org/apache/commons/collections/map/TestFlat3Map.java
+++ b/src/test/org/apache/commons/collections/map/TestFlat3Map.java
@@ -5,9 +5,9 @@
* 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.
@@ -27,17 +27,18 @@ import junit.framework.Test;
import junit.textui.TestRunner;
import org.apache.commons.collections.BulkTest;
+import org.apache.commons.collections.IterableMap;
import org.apache.commons.collections.MapIterator;
import org.apache.commons.collections.iterators.AbstractTestMapIterator;
/**
* JUnit tests.
- *
+ *
* @version $Revision$ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public class TestFlat3Map extends AbstractTestIterableMap {
+public class TestFlat3Map<K, V> extends AbstractTestIterableMap<K, V> {
private static final Integer ONE = new Integer(1);
private static final Integer TWO = new Integer(2);
@@ -45,7 +46,7 @@ public class TestFlat3Map extends AbstractTestIterableMap {
private static final String TEN = "10";
private static final String TWENTY = "20";
private static final String THIRTY = "30";
-
+
public TestFlat3Map(String testName) {
super(testName);
}
@@ -53,75 +54,80 @@ public class TestFlat3Map extends AbstractTestIterableMap {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestFlat3Map.class);
}
- public Map makeEmptyMap() {
- return new Flat3Map();
+ public Flat3Map<K, V> makeObject() {
+ return new Flat3Map<K, V>();
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testEquals1() {
- Flat3Map map1 = new Flat3Map();
- map1.put("a", "testA");
- map1.put("b", "testB");
- Flat3Map map2 = new Flat3Map();
- map2.put("a", "testB");
- map2.put("b", "testA");
+ Flat3Map<K, V> map1 = makeObject();
+ map1.put((K) "a", (V) "testA");
+ map1.put((K) "b", (V) "testB");
+ Flat3Map<K, V> map2 = makeObject();
+ map2.put((K) "a", (V) "testB");
+ map2.put((K) "b", (V) "testA");
assertEquals(false, map1.equals(map2));
}
+ @SuppressWarnings("unchecked")
public void testEquals2() {
- Flat3Map map1 = new Flat3Map();
- map1.put("a", "testA");
- map1.put("b", "testB");
- Flat3Map map2 = new Flat3Map();
- map2.put("a", "testB");
- map2.put("c", "testA");
+ Flat3Map<K, V> map1 = makeObject();
+ map1.put((K) "a", (V) "testA");
+ map1.put((K) "b", (V) "testB");
+ Flat3Map<K, V> map2 = makeObject();
+ map2.put((K) "a", (V) "testB");
+ map2.put((K) "c", (V) "testA");
assertEquals(false, map1.equals(map2));
}
+ @SuppressWarnings("unchecked")
public void testClone2() {
- Flat3Map map = new Flat3Map();
+ Flat3Map<K, V> map = makeObject();
assertEquals(0, map.size());
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
assertEquals(2, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
assertSame(TEN, map.get(ONE));
assertSame(TWENTY, map.get(TWO));
- // clone works (size = 2)
- Flat3Map cloned = (Flat3Map) map.clone();
+ // clone works (size = 2)
+ Flat3Map<K, V> cloned = map.clone();
assertEquals(2, cloned.size());
assertEquals(true, cloned.containsKey(ONE));
assertEquals(true, cloned.containsKey(TWO));
assertSame(TEN, cloned.get(ONE));
assertSame(TWENTY, cloned.get(TWO));
-
+
// change original doesn't change clone
- map.put(TEN, ONE);
- map.put(TWENTY, TWO);
+ map.put((K) TEN, (V) ONE);
+ map.put((K) TWENTY, (V) TWO);
assertEquals(4, map.size());
assertEquals(2, cloned.size());
assertEquals(true, cloned.containsKey(ONE));
assertEquals(true, cloned.containsKey(TWO));
assertSame(TEN, cloned.get(ONE));
assertSame(TWENTY, cloned.get(TWO));
- }
+ }
+
+ @SuppressWarnings("unchecked")
public void testClone4() {
- Flat3Map map = new Flat3Map();
+ Flat3Map<K, V> map = makeObject();
assertEquals(0, map.size());
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(TEN, ONE);
- map.put(TWENTY, TWO);
-
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) TEN, (V) ONE);
+ map.put((K) TWENTY, (V) TWO);
+
// clone works (size = 4)
- Flat3Map cloned = (Flat3Map) map.clone();
+ Flat3Map<K, V> cloned = map.clone();
assertEquals(4, map.size());
assertEquals(4, cloned.size());
assertEquals(true, cloned.containsKey(ONE));
@@ -132,7 +138,7 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertSame(TWENTY, cloned.get(TWO));
assertSame(ONE, cloned.get(TEN));
assertSame(TWO, cloned.get(TWENTY));
-
+
// change original doesn't change clone
map.clear();
assertEquals(0, map.size());
@@ -146,9 +152,10 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertSame(ONE, cloned.get(TEN));
assertSame(TWO, cloned.get(TWENTY));
}
-
+
+ @SuppressWarnings("unchecked")
public void testSerialisation0() throws Exception {
- Flat3Map map = new Flat3Map();
+ Flat3Map<K, V> map = makeObject();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(map);
@@ -161,12 +168,13 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertEquals(0, map.size());
assertEquals(0, ser.size());
}
-
+
+ @SuppressWarnings("unchecked")
public void testSerialisation2() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
-
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(map);
@@ -183,14 +191,15 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertEquals(TEN, ser.get(ONE));
assertEquals(TWENTY, ser.get(TWO));
}
-
+
+ @SuppressWarnings("unchecked")
public void testSerialisation4() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(TEN, ONE);
- map.put(TWENTY, TWO);
-
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) TEN, (V) ONE);
+ map.put((K) TWENTY, (V) TWO);
+
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(map);
@@ -213,15 +222,16 @@ public class TestFlat3Map extends AbstractTestIterableMap {
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testEntryIteratorSetValue1() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- Iterator it = map.entrySet().iterator();
- Map.Entry entry = (Map.Entry) it.next();
- entry.setValue("NewValue");
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
+ Map.Entry<K, V> entry = it.next();
+ entry.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -231,16 +241,17 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testEntryIteratorSetValue2() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- Iterator it = map.entrySet().iterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
it.next();
- Map.Entry entry = (Map.Entry) it.next();
- entry.setValue("NewValue");
+ Map.Entry<K, V> entry = it.next();
+ entry.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -250,17 +261,18 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testEntryIteratorSetValue3() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- Iterator it = map.entrySet().iterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
it.next();
it.next();
- Map.Entry entry = (Map.Entry) it.next();
- entry.setValue("NewValue");
+ Map.Entry<K, V> entry = it.next();
+ entry.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -271,15 +283,16 @@ public class TestFlat3Map extends AbstractTestIterableMap {
}
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testMapIteratorSetValue1() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- MapIterator it = map.mapIterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ MapIterator<K, V> it = map.mapIterator();
it.next();
- it.setValue("NewValue");
+ it.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -289,16 +302,17 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testMapIteratorSetValue2() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- MapIterator it = map.mapIterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ MapIterator<K, V> it = map.mapIterator();
it.next();
it.next();
- it.setValue("NewValue");
+ it.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -308,17 +322,18 @@ public class TestFlat3Map extends AbstractTestIterableMap {
assertEquals(THIRTY, map.get(THREE));
}
+ @SuppressWarnings("unchecked")
public void testMapIteratorSetValue3() throws Exception {
- Flat3Map map = new Flat3Map();
- map.put(ONE, TEN);
- map.put(TWO, TWENTY);
- map.put(THREE, THIRTY);
-
- MapIterator it = map.mapIterator();
+ Flat3Map<K, V> map = makeObject();
+ map.put((K) ONE, (V) TEN);
+ map.put((K) TWO, (V) TWENTY);
+ map.put((K) THREE, (V) THIRTY);
+
+ MapIterator<K, V> it = map.mapIterator();
it.next();
it.next();
it.next();
- it.setValue("NewValue");
+ it.setValue((V) "NewValue");
assertEquals(3, map.size());
assertEquals(true, map.containsKey(ONE));
assertEquals(true, map.containsKey(TWO));
@@ -332,16 +347,16 @@ public class TestFlat3Map extends AbstractTestIterableMap {
public BulkTest bulkTestMapIterator() {
return new TestFlatMapIterator();
}
-
- public class TestFlatMapIterator extends AbstractTestMapIterator {
+
+ public class TestFlatMapIterator extends AbstractTestMapIterator<K, V> {
public TestFlatMapIterator() {
super("TestFlatMapIterator");
}
-
- public Object[] addSetValues() {
+
+ public V[] addSetValues() {
return TestFlat3Map.this.getNewSampleValues();
}
-
+
public boolean supportsRemove() {
return TestFlat3Map.this.isRemoveSupported();
}
@@ -350,32 +365,32 @@ public class TestFlat3Map extends AbstractTestIterableMap {
return TestFlat3Map.this.isSetValueSupported();
}
- public MapIterator makeEmptyMapIterator() {
+ public MapIterator<K, V> makeEmptyIterator() {
resetEmpty();
- return ((Flat3Map) TestFlat3Map.this.map).mapIterator();
+ return TestFlat3Map.this.getMap().mapIterator();
}
- public MapIterator makeFullMapIterator() {
+ public MapIterator<K, V> makeObject() {
resetFull();
- return ((Flat3Map) TestFlat3Map.this.map).mapIterator();
+ return TestFlat3Map.this.getMap().mapIterator();
}
-
- public Map getMap() {
+
+ public IterableMap<K, V> getMap() {
// assumes makeFullMapIterator() called first
- return TestFlat3Map.this.map;
+ return TestFlat3Map.this.getMap();
}
-
- public Map getConfirmedMap() {
+
+ public Map<K, V> getConfirmedMap() {
// assumes makeFullMapIterator() called first
- return TestFlat3Map.this.confirmed;
+ return TestFlat3Map.this.getConfirmed();
}
-
+
public void verify() {
super.verify();
TestFlat3Map.this.verify();
}
}
-
+
public String getCompatibilityVersion() {
return "3.1";
}
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestHashedMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/TestHashedMap.java b/src/test/org/apache/commons/collections/map/TestHashedMap.java
index 2f2e091..f22220f 100644
--- a/src/test/org/apache/commons/collections/map/TestHashedMap.java
+++ b/src/test/org/apache/commons/collections/map/TestHashedMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -16,8 +16,6 @@
*/
package org.apache.commons.collections.map;
-import java.util.Map;
-
import junit.framework.Test;
import junit.textui.TestRunner;
@@ -25,12 +23,12 @@ import org.apache.commons.collections.BulkTest;
/**
* JUnit tests.
- *
+ *
* @version $Revision$ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public class TestHashedMap extends AbstractTestIterableMap {
+public class TestHashedMap<K, V> extends AbstractTestIterableMap<K, V> {
public TestHashedMap(String testName) {
super(testName);
@@ -39,29 +37,30 @@ public class TestHashedMap extends AbstractTestIterableMap {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestHashedMap.class);
}
- public Map makeEmptyMap() {
- return new HashedMap();
+ public HashedMap<K, V> makeObject() {
+ return new HashedMap<K, V>();
}
-
+
public String getCompatibilityVersion() {
return "3";
}
+ @SuppressWarnings("unchecked")
public void testClone() {
- HashedMap map = new HashedMap(10);
- map.put("1", "1");
- Map cloned = (Map) map.clone();
+ HashedMap<K, V> map = new HashedMap<K, V>(10);
+ map.put((K) "1", (V) "1");
+ HashedMap<K, V> cloned = map.clone();
assertEquals(map.size(), cloned.size());
assertSame(map.get("1"), cloned.get("1"));
}
public void testInternalState() {
- HashedMap map = new HashedMap(42, 0.75f);
+ HashedMap<K, V> map = new HashedMap<K, V>(42, 0.75f);
assertEquals(0.75f, map.loadFactor, 0.1f);
assertEquals(0, map.size);
assertEquals(64, map.data.length);
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestIdentityMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/TestIdentityMap.java b/src/test/org/apache/commons/collections/map/TestIdentityMap.java
index 6b2df6e..b5b964f 100644
--- a/src/test/org/apache/commons/collections/map/TestIdentityMap.java
+++ b/src/test/org/apache/commons/collections/map/TestIdentityMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -30,13 +30,13 @@ import org.apache.commons.collections.IterableMap;
/**
* JUnit tests.
- *
+ *
* @version $Revision$ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public class TestIdentityMap extends AbstractTestObject {
-
+public class TestIdentityMap<K, V> extends AbstractTestObject {
+
private static final Integer I1A = new Integer(1);
private static final Integer I1B = new Integer(1);
private static final Integer I2A = new Integer(2);
@@ -49,26 +49,27 @@ public class TestIdentityMap extends AbstractTestObject {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return new TestSuite(TestIdentityMap.class);
// return BulkTest.makeSuite(TestIdentityMap.class); // causes race condition!
}
-
- public Object makeObject() {
- return new IdentityMap();
+
+ public IdentityMap<K, V> makeObject() {
+ return new IdentityMap<K, V>();
}
-
+
public String getCompatibilityVersion() {
return "3";
}
-
+
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testBasics() {
- IterableMap map = new IdentityMap();
+ IterableMap<K, V> map = new IdentityMap<K, V>();
assertEquals(0, map.size());
-
- map.put(I1A, I2A);
+
+ map.put((K) I1A, (V) I2A);
assertEquals(1, map.size());
assertSame(I2A, map.get(I1A));
assertSame(null, map.get(I1B));
@@ -76,8 +77,8 @@ public class TestIdentityMap extends AbstractTestObject {
assertEquals(false, map.containsKey(I1B));
assertEquals(true, map.containsValue(I2A));
assertEquals(false, map.containsValue(I2B));
-
- map.put(I1A, I2B);
+
+ map.put((K) I1A, (V) I2B);
assertEquals(1, map.size());
assertSame(I2B, map.get(I1A));
assertSame(null, map.get(I1B));
@@ -85,8 +86,8 @@ public class TestIdentityMap extends AbstractTestObject {
assertEquals(false, map.containsKey(I1B));
assertEquals(false, map.containsValue(I2A));
assertEquals(true, map.containsValue(I2B));
-
- map.put(I1B, I2B);
+
+ map.put((K) I1B, (V) I2B);
assertEquals(2, map.size());
assertSame(I2B, map.get(I1A));
assertSame(I2B, map.get(I1B));
@@ -95,45 +96,48 @@ public class TestIdentityMap extends AbstractTestObject {
assertEquals(false, map.containsValue(I2A));
assertEquals(true, map.containsValue(I2B));
}
-
+
//-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testHashEntry() {
- IterableMap map = new IdentityMap();
-
- map.put(I1A, I2A);
- map.put(I1B, I2A);
-
- Map.Entry entry1 = (Map.Entry) map.entrySet().iterator().next();
- Iterator it = map.entrySet().iterator();
- Map.Entry entry2 = (Map.Entry) it.next();
- Map.Entry entry3 = (Map.Entry) it.next();
-
+ IterableMap<K, V> map = new IdentityMap<K, V>();
+
+ map.put((K) I1A, (V) I2A);
+ map.put((K) I1B, (V) I2A);
+
+ Map.Entry<K, V> entry1 = map.entrySet().iterator().next();
+ Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
+ Map.Entry<K, V> entry2 = it.next();
+ Map.Entry<K, V> entry3 = it.next();
+
assertEquals(true, entry1.equals(entry2));
assertEquals(true, entry2.equals(entry1));
assertEquals(false, entry1.equals(entry3));
}
-
+
/**
* Compare the current serialized form of the Map
* against the canonical version in CVS.
*/
+ @SuppressWarnings("unchecked")
public void testEmptyMapCompatibility() throws IOException, ClassNotFoundException {
// test to make sure the canonical form has been preserved
- Map map = (Map) makeObject();
+ Map<K, V> map = makeObject();
if (map instanceof Serializable && !skipSerializedCanonicalTests()) {
Map map2 = (Map) readExternalFormFromDisk(getCanonicalEmptyCollectionName(map));
assertEquals("Map is empty", 0, map2.size());
}
}
+ @SuppressWarnings("unchecked")
public void testClone() {
- IdentityMap map = new IdentityMap(10);
- map.put("1", "1");
- Map cloned = (Map) map.clone();
+ IdentityMap<K, V> map = new IdentityMap<K, V>(10);
+ map.put((K) "1", (V) "1");
+ Map<K, V> cloned = map.clone();
assertEquals(map.size(), cloned.size());
assertSame(map.get("1"), cloned.get("1"));
}
-
+
// public void testCreate() throws Exception {
// Map map = new IdentityMap();
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/IdentityMap.emptyCollection.version3.obj");
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/map/TestLRUMap.java
----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/map/TestLRUMap.java b/src/test/org/apache/commons/collections/map/TestLRUMap.java
index bee6678..22c3e67 100644
--- a/src/test/org/apache/commons/collections/map/TestLRUMap.java
+++ b/src/test/org/apache/commons/collections/map/TestLRUMap.java
@@ -5,9 +5,9 @@
* 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.
@@ -30,12 +30,12 @@ import org.apache.commons.collections.ResettableIterator;
/**
* JUnit tests.
- *
+ *
* @version $Revision$ $Date$
- *
+ *
* @author Stephen Colebourne
*/
-public class TestLRUMap extends AbstractTestOrderedMap {
+public class TestLRUMap<K, V> extends AbstractTestOrderedMap<K, V> {
public TestLRUMap(String testName) {
super(testName);
@@ -44,19 +44,27 @@ public class TestLRUMap extends AbstractTestOrderedMap {
public static void main(String[] args) {
TestRunner.run(suite());
}
-
+
public static Test suite() {
return BulkTest.makeSuite(TestLRUMap.class);
}
- public Map makeEmptyMap() {
- return new LRUMap();
+ public LRUMap<K, V> makeObject() {
+ return new LRUMap<K, V>();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public LRUMap<K, V> makeFullMap() {
+ return (LRUMap<K, V>) super.makeFullMap();
}
public boolean isGetStructuralModify() {
return true;
}
-
+
public String getCompatibilityVersion() {
return "3";
}
@@ -64,169 +72,174 @@ public class TestLRUMap extends AbstractTestOrderedMap {
//-----------------------------------------------------------------------
public void testLRU() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
- Object[] keys = getSampleKeys();
- Object[] values = getSampleValues();
- Iterator it = null;
-
- LRUMap map = new LRUMap(2);
+ K[] keys = getSampleKeys();
+ V[] values = getSampleValues();
+ Iterator<K> kit;
+ Iterator<V> vit;
+
+ LRUMap<K, V> map = new LRUMap<K, V>(2);
assertEquals(0, map.size());
assertEquals(false, map.isFull());
assertEquals(2, map.maxSize());
-
+
map.put(keys[0], values[0]);
assertEquals(1, map.size());
assertEquals(false, map.isFull());
assertEquals(2, map.maxSize());
-
+
map.put(keys[1], values[1]);
assertEquals(2, map.size());
assertEquals(true, map.isFull());
assertEquals(2, map.maxSize());
- it = map.keySet().iterator();
- assertSame(keys[0], it.next());
- assertSame(keys[1], it.next());
- it = map.values().iterator();
- assertSame(values[0], it.next());
- assertSame(values[1], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[0], kit.next());
+ assertSame(keys[1], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[0], vit.next());
+ assertSame(values[1], vit.next());
map.put(keys[2], values[2]);
assertEquals(2, map.size());
assertEquals(true, map.isFull());
assertEquals(2, map.maxSize());
- it = map.keySet().iterator();
- assertSame(keys[1], it.next());
- assertSame(keys[2], it.next());
- it = map.values().iterator();
- assertSame(values[1], it.next());
- assertSame(values[2], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[1], kit.next());
+ assertSame(keys[2], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[1], vit.next());
+ assertSame(values[2], vit.next());
map.put(keys[2], values[0]);
assertEquals(2, map.size());
assertEquals(true, map.isFull());
assertEquals(2, map.maxSize());
- it = map.keySet().iterator();
- assertSame(keys[1], it.next());
- assertSame(keys[2], it.next());
- it = map.values().iterator();
- assertSame(values[1], it.next());
- assertSame(values[0], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[1], kit.next());
+ assertSame(keys[2], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[1], vit.next());
+ assertSame(values[0], vit.next());
map.put(keys[1], values[3]);
assertEquals(2, map.size());
assertEquals(true, map.isFull());
assertEquals(2, map.maxSize());
- it = map.keySet().iterator();
- assertSame(keys[2], it.next());
- assertSame(keys[1], it.next());
- it = map.values().iterator();
- assertSame(values[0], it.next());
- assertSame(values[3], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[2], kit.next());
+ assertSame(keys[1], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[0], vit.next());
+ assertSame(values[3], vit.next());
}
-
- //-----------------------------------------------------------------------
+
+ //-----------------------------------------------------------------------
+ @SuppressWarnings("unchecked")
public void testReset() {
resetEmpty();
- OrderedMap ordered = (OrderedMap) map;
- ((ResettableIterator) ordered.mapIterator()).reset();
-
+ OrderedMap<K, V> ordered = getMap();
+ ((ResettableIterator<K>) ordered.mapIterator()).reset();
+
resetFull();
- ordered = (OrderedMap) map;
- List list = new ArrayList(ordered.keySet());
- ResettableIterator it = (ResettableIterator) ordered.mapIterator();
+ ordered = getMap();
+ List<K> list = new ArrayList<K>(ordered.keySet());
+ ResettableIterator<K> it = (ResettableIterator<K>) ordered.mapIterator();
assertSame(list.get(0), it.next());
assertSame(list.get(1), it.next());
it.reset();
assertSame(list.get(0), it.next());
}
-
+
//-----------------------------------------------------------------------
public void testAccessOrder() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
- Object[] keys = getSampleKeys();
- Object[] values = getSampleValues();
- Iterator it = null;
-
+ K[] keys = getSampleKeys();
+ V[] values = getSampleValues();
+ Iterator<K> kit = null;
+ Iterator<V> vit = null;
+
resetEmpty();
map.put(keys[0], values[0]);
map.put(keys[1], values[1]);
- it = map.keySet().iterator();
- assertSame(keys[0], it.next());
- assertSame(keys[1], it.next());
- it = map.values().iterator();
- assertSame(values[0], it.next());
- assertSame(values[1], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[0], kit.next());
+ assertSame(keys[1], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[0], vit.next());
+ assertSame(values[1], vit.next());
// no change to order
map.put(keys[1], values[1]);
- it = map.keySet().iterator();
- assertSame(keys[0], it.next());
- assertSame(keys[1], it.next());
- it = map.values().iterator();
- assertSame(values[0], it.next());
- assertSame(values[1], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[0], kit.next());
+ assertSame(keys[1], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[0], vit.next());
+ assertSame(values[1], vit.next());
// no change to order
map.put(keys[1], values[2]);
- it = map.keySet().iterator();
- assertSame(keys[0], it.next());
- assertSame(keys[1], it.next());
- it = map.values().iterator();
- assertSame(values[0], it.next());
- assertSame(values[2], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[0], kit.next());
+ assertSame(keys[1], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[0], vit.next());
+ assertSame(values[2], vit.next());
// change to order
map.put(keys[0], values[3]);
- it = map.keySet().iterator();
- assertSame(keys[1], it.next());
- assertSame(keys[0], it.next());
- it = map.values().iterator();
- assertSame(values[2], it.next());
- assertSame(values[3], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[1], kit.next());
+ assertSame(keys[0], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[2], vit.next());
+ assertSame(values[3], vit.next());
// change to order
map.get(keys[1]);
- it = map.keySet().iterator();
- assertSame(keys[0], it.next());
- assertSame(keys[1], it.next());
- it = map.values().iterator();
- assertSame(values[3], it.next());
- assertSame(values[2], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[0], kit.next());
+ assertSame(keys[1], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[3], vit.next());
+ assertSame(values[2], vit.next());
// change to order
map.get(keys[0]);
- it = map.keySet().iterator();
- assertSame(keys[1], it.next());
- assertSame(keys[0], it.next());
- it = map.values().iterator();
- assertSame(values[2], it.next());
- assertSame(values[3], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[1], kit.next());
+ assertSame(keys[0], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[2], vit.next());
+ assertSame(values[3], vit.next());
// no change to order
map.get(keys[0]);
- it = map.keySet().iterator();
- assertSame(keys[1], it.next());
- assertSame(keys[0], it.next());
- it = map.values().iterator();
- assertSame(values[2], it.next());
- assertSame(values[3], it.next());
+ kit = map.keySet().iterator();
+ assertSame(keys[1], kit.next());
+ assertSame(keys[0], kit.next());
+ vit = map.values().iterator();
+ assertSame(values[2], vit.next());
+ assertSame(values[3], vit.next());
}
-
+
+ @SuppressWarnings("unchecked")
public void testClone() {
- LRUMap map = new LRUMap(10);
- map.put("1", "1");
- Map cloned = (Map) map.clone();
+ LRUMap<K, V> map = new LRUMap<K, V>(10);
+ map.put((K) "1", (V) "1");
+ Map<K, V> cloned = map.clone();
assertEquals(map.size(), cloned.size());
assertSame(map.get("1"), cloned.get("1"));
}
-
+
+ @SuppressWarnings("unchecked")
public void testRemoveLRU() {
MockLRUMapSubclass map = new MockLRUMapSubclass(2);
assertNull(map.entry);
- map.put("A", "a");
+ map.put((K) "A", "a");
assertNull(map.entry);
- map.put("B", "b");
+ map.put((K) "B", "b");
assertNull(map.entry);
- map.put("C", "c"); // removes oldest, which is A=a
+ map.put((K) "C", "c"); // removes oldest, which is A=a
assertNotNull(map.entry);
assertEquals("A", map.key);
assertEquals("a", map.value);
@@ -236,32 +249,34 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(true, map.containsKey("B"));
assertEquals(true, map.containsKey("C"));
}
-
- static class MockLRUMapSubclass extends LRUMap {
- LinkEntry entry;
- Object key;
- Object value;
+
+ @SuppressWarnings("serial")
+ static class MockLRUMapSubclass<K, V> extends LRUMap<K, V> {
+ LinkEntry<K, V> entry;
+ K key;
+ V value;
MockLRUMapSubclass(int size) {
super(size);
}
- protected boolean removeLRU(LinkEntry entry) {
+ protected boolean removeLRU(LinkEntry<K, V> entry) {
this.entry = entry;
this.key = entry.getKey();
this.value = entry.getValue();
return true;
}
}
-
+
+ @SuppressWarnings("unchecked")
public void testRemoveLRUBlocksRemove() {
- MockLRUMapSubclassBlocksRemove map = new MockLRUMapSubclassBlocksRemove(2, false);
+ MockLRUMapSubclassBlocksRemove<K, V> map = new MockLRUMapSubclassBlocksRemove<K, V>(2, false);
assertEquals(0, map.size());
- map.put("A", "a");
+ map.put((K) "A", (V) "a");
assertEquals(1, map.size());
- map.put("B", "b");
+ map.put((K) "B", (V) "b");
assertEquals(2, map.size());
- map.put("C", "c"); // should remove oldest, which is A=a, but this is blocked
+ map.put((K) "C", (V) "c"); // should remove oldest, which is A=a, but this is blocked
assertEquals(3, map.size());
assertEquals(2, map.maxSize());
assertEquals(true, map.containsKey("A"));
@@ -269,39 +284,42 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(true, map.containsKey("C"));
}
+ @SuppressWarnings("unchecked")
public void testRemoveLRUBlocksRemoveScan() {
- MockLRUMapSubclassBlocksRemove map = new MockLRUMapSubclassBlocksRemove(2, true);
+ MockLRUMapSubclassBlocksRemove<K, V> map = new MockLRUMapSubclassBlocksRemove<K, V>(2, true);
assertEquals(0, map.size());
- map.put("A", "a");
+ map.put((K) "A", (V) "a");
assertEquals(1, map.size());
- map.put("B", "b");
+ map.put((K) "B", (V) "b");
assertEquals(2, map.size());
- map.put("C", "c"); // should remove oldest, which is A=a, but this is blocked
+ map.put((K) "C", (V) "c"); // should remove oldest, which is A=a, but this is blocked
assertEquals(3, map.size());
assertEquals(2, map.maxSize());
assertEquals(true, map.containsKey("A"));
assertEquals(true, map.containsKey("B"));
assertEquals(true, map.containsKey("C"));
}
-
- static class MockLRUMapSubclassBlocksRemove extends LRUMap {
+
+ @SuppressWarnings("serial")
+ static class MockLRUMapSubclassBlocksRemove<K, V> extends LRUMap<K, V> {
MockLRUMapSubclassBlocksRemove(int size, boolean scanUntilRemove) {
super(size, scanUntilRemove);
}
- protected boolean removeLRU(LinkEntry entry) {
+ protected boolean removeLRU(LinkEntry<K, V> entry) {
return false;
}
}
-
+
+ @SuppressWarnings("unchecked")
public void testRemoveLRUFirstBlocksRemove() {
- MockLRUMapSubclassFirstBlocksRemove map = new MockLRUMapSubclassFirstBlocksRemove(2);
+ MockLRUMapSubclassFirstBlocksRemove<K, V> map = new MockLRUMapSubclassFirstBlocksRemove<K, V>(2);
assertEquals(0, map.size());
- map.put("A", "a");
+ map.put((K) "A", (V) "a");
assertEquals(1, map.size());
- map.put("B", "b");
+ map.put((K) "B", (V) "b");
assertEquals(2, map.size());
- map.put("C", "c"); // should remove oldest, which is A=a but this is blocked - so advance to B=b
+ map.put((K) "C", (V) "c"); // should remove oldest, which is A=a but this is blocked - so advance to B=b
assertEquals(2, map.size());
assertEquals(2, map.maxSize());
assertEquals(true, map.containsKey("A"));
@@ -309,12 +327,13 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(true, map.containsKey("C"));
}
- static class MockLRUMapSubclassFirstBlocksRemove extends LRUMap {
+ @SuppressWarnings("serial")
+ static class MockLRUMapSubclassFirstBlocksRemove<K, V> extends LRUMap<K, V> {
MockLRUMapSubclassFirstBlocksRemove(int size) {
super(size, true);
}
- protected boolean removeLRU(LinkEntry entry) {
+ protected boolean removeLRU(LinkEntry<K, V> entry) {
if ("a".equals(entry.getValue())) {
return false;
} else {
@@ -339,6 +358,7 @@ public class TestLRUMap extends AbstractTestOrderedMap {
}
}
+ @SuppressWarnings("unchecked")
public void testInternalState_Buckets() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
SingleHashCode one = new SingleHashCode("1");
@@ -348,12 +368,12 @@ public class TestLRUMap extends AbstractTestOrderedMap {
SingleHashCode five = new SingleHashCode("5");
SingleHashCode six = new SingleHashCode("6");
- LRUMap map = new LRUMap(3, 1.0f);
+ LRUMap<K, V> map = new LRUMap<K, V>(3, 1.0f);
int hashIndex = map.hashIndex(map.hash(one), 4);
- map.put(one, "A");
- map.put(two, "B");
- map.put(three, "C");
-
+ map.put((K) one, (V) "A");
+ map.put((K) two, (V) "B");
+ map.put((K) three, (V) "C");
+
assertEquals(4, map.data.length);
assertEquals(3, map.size);
assertEquals(null, map.header.next);
@@ -363,9 +383,9 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(three, map.data[hashIndex].key);
assertEquals(two, map.data[hashIndex].next.key);
assertEquals(one, map.data[hashIndex].next.next.key);
-
- map.put(four, "D"); // reuses last in next list
-
+
+ map.put((K) four, (V) "D"); // reuses last in next list
+
assertEquals(4, map.data.length);
assertEquals(3, map.size);
assertEquals(null, map.header.next);
@@ -375,9 +395,9 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(four, map.data[hashIndex].key);
assertEquals(three, map.data[hashIndex].next.key);
assertEquals(two, map.data[hashIndex].next.next.key);
-
+
map.get(three);
-
+
assertEquals(4, map.data.length);
assertEquals(3, map.size);
assertEquals(null, map.header.next);
@@ -387,9 +407,9 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(four, map.data[hashIndex].key);
assertEquals(three, map.data[hashIndex].next.key);
assertEquals(two, map.data[hashIndex].next.next.key);
-
- map.put(five, "E"); // reuses last in next list
-
+
+ map.put((K) five, (V) "E"); // reuses last in next list
+
assertEquals(4, map.data.length);
assertEquals(3, map.size);
assertEquals(null, map.header.next);
@@ -399,10 +419,10 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(five, map.data[hashIndex].key);
assertEquals(four, map.data[hashIndex].next.key);
assertEquals(three, map.data[hashIndex].next.next.key);
-
+
map.get(three);
map.get(five);
-
+
assertEquals(4, map.data.length);
assertEquals(3, map.size);
assertEquals(null, map.header.next);
@@ -412,9 +432,9 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(five, map.data[hashIndex].key);
assertEquals(four, map.data[hashIndex].next.key);
assertEquals(three, map.data[hashIndex].next.next.key);
-
- map.put(six, "F"); // reuses middle in next list
-
+
+ map.put((K) six, (V) "F"); // reuses middle in next list
+
assertEquals(4, map.data.length);
assertEquals(3, map.size);
assertEquals(null, map.header.next);
@@ -426,21 +446,18 @@ public class TestLRUMap extends AbstractTestOrderedMap {
assertEquals(three, map.data[hashIndex].next.next.key);
}
+ @SuppressWarnings("unchecked")
public void testInternalState_getEntry_int() {
if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
SingleHashCode one = new SingleHashCode("1");
SingleHashCode two = new SingleHashCode("2");
SingleHashCode three = new SingleHashCode("3");
- SingleHashCode four = new SingleHashCode("4");
- SingleHashCode five = new SingleHashCode("5");
- SingleHashCode six = new SingleHashCode("6");
- LRUMap map = new LRUMap(3, 1.0f);
- int hashIndex = map.hashIndex(map.hash(one), 4);
- map.put(one, "A");
- map.put(two, "B");
- map.put(three, "C");
-
+ LRUMap<K, V> map = new LRUMap<K, V>(3, 1.0f);
+ map.put((K) one, (V) "A");
+ map.put((K) two, (V) "B");
+ map.put((K) three, (V) "C");
+
assertEquals(one, map.getEntry(0).key);
assertEquals(two, map.getEntry(1).key);
assertEquals(three, map.getEntry(2).key);
@@ -460,4 +477,12 @@ public class TestLRUMap extends AbstractTestOrderedMap {
// resetFull();
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LRUMap.fullCollection.version3.obj");
// }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public LRUMap<K, V> getMap() {
+ return (LRUMap<K, V>) super.getMap();
+ }
}