Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.

Also see the following revisions:

    ------------------------------------------------------------------------
    r740150 | mbenson | 2009-02-02 15:24:00 -0800 (Mon, 02 Feb 2009) | 1 line
    
    make all [collections] maps implement IterableMap
    ------------------------------------------------------------------------


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815122 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2009-09-15 05:57:20 +00:00
parent 628bcc433a
commit 5e234b76ad
1 changed files with 66 additions and 41 deletions

View File

@ -32,99 +32,116 @@ import org.apache.commons.collections.iterators.AbstractTestMapIterator;
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
public abstract class AbstractTestIterableMap extends AbstractTestMap { public abstract class AbstractTestIterableMap<K, V> extends AbstractTestMap<K, V> {
/** /**
* JUnit constructor. * JUnit constructor.
* *
* @param testName the test name * @param testName the test name
*/ */
public AbstractTestIterableMap(String testName) { public AbstractTestIterableMap(String testName) {
super(testName); super(testName);
} }
/**
* {@inheritDoc}
*/
@Override
public abstract IterableMap<K, V> makeObject();
/**
* {@inheritDoc}
*/
@Override
public IterableMap<K, V> makeFullMap() {
return (IterableMap<K, V>) super.makeFullMap();
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public void testFailFastEntrySet() { public void testFailFastEntrySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) return;
if (isFailFastExpected() == false) return;
resetFull(); resetFull();
Iterator it = map.entrySet().iterator(); Iterator<Map.Entry<K, V>> it = getMap().entrySet().iterator();
Map.Entry val = (Map.Entry) it.next(); Map.Entry<K, V> val = it.next();
map.remove(val.getKey()); getMap().remove(val.getKey());
try { try {
it.next(); it.next();
fail(); fail();
} catch (ConcurrentModificationException ex) {} } catch (ConcurrentModificationException ex) {}
resetFull(); resetFull();
it = map.entrySet().iterator(); it = getMap().entrySet().iterator();
it.next(); it.next();
map.clear(); getMap().clear();
try { try {
it.next(); it.next();
fail(); fail();
} catch (ConcurrentModificationException ex) {} } catch (ConcurrentModificationException ex) {}
} }
public void testFailFastKeySet() { public void testFailFastKeySet() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) return;
if (isFailFastExpected() == false) return;
resetFull(); resetFull();
Iterator it = map.keySet().iterator(); Iterator<K> it = getMap().keySet().iterator();
Object val = it.next(); K val = it.next();
map.remove(val); getMap().remove(val);
try { try {
it.next(); it.next();
fail(); fail();
} catch (ConcurrentModificationException ex) {} } catch (ConcurrentModificationException ex) {}
resetFull(); resetFull();
it = map.keySet().iterator(); it = getMap().keySet().iterator();
it.next(); it.next();
map.clear(); getMap().clear();
try { try {
it.next(); it.next();
fail(); fail();
} catch (ConcurrentModificationException ex) {} } catch (ConcurrentModificationException ex) {}
} }
public void testFailFastValues() { public void testFailFastValues() {
if (isRemoveSupported() == false) return; if (isRemoveSupported() == false) return;
if (isFailFastExpected() == false) return;
resetFull(); resetFull();
Iterator it = map.values().iterator(); Iterator<V> it = getMap().values().iterator();
it.next(); it.next();
map.remove(map.keySet().iterator().next()); getMap().remove(getMap().keySet().iterator().next());
try { try {
it.next(); it.next();
fail(); fail();
} catch (ConcurrentModificationException ex) {} } catch (ConcurrentModificationException ex) {}
resetFull(); resetFull();
it = map.values().iterator(); it = getMap().values().iterator();
it.next(); it.next();
map.clear(); getMap().clear();
try { try {
it.next(); it.next();
fail(); fail();
} catch (ConcurrentModificationException ex) {} } catch (ConcurrentModificationException ex) {}
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
public BulkTest bulkTestMapIterator() { public BulkTest bulkTestMapIterator() {
return new InnerTestMapIterator(); return new InnerTestMapIterator();
} }
public class InnerTestMapIterator extends AbstractTestMapIterator { public class InnerTestMapIterator extends AbstractTestMapIterator<K, V> {
public InnerTestMapIterator() { public InnerTestMapIterator() {
super("InnerTestMapIterator"); super("InnerTestMapIterator");
} }
public Object[] addSetValues() { public V[] addSetValues() {
return AbstractTestIterableMap.this.getNewSampleValues(); return AbstractTestIterableMap.this.getNewSampleValues();
} }
public boolean supportsRemove() { public boolean supportsRemove() {
return AbstractTestIterableMap.this.isRemoveSupported(); return AbstractTestIterableMap.this.isRemoveSupported();
} }
public boolean isGetStructuralModify() { public boolean isGetStructuralModify() {
return AbstractTestIterableMap.this.isGetStructuralModify(); return AbstractTestIterableMap.this.isGetStructuralModify();
} }
@ -133,36 +150,44 @@ public abstract class AbstractTestIterableMap extends AbstractTestMap {
return AbstractTestIterableMap.this.isSetValueSupported(); return AbstractTestIterableMap.this.isSetValueSupported();
} }
public MapIterator makeEmptyMapIterator() { public MapIterator<K, V> makeEmptyIterator() {
resetEmpty(); resetEmpty();
return ((IterableMap) AbstractTestIterableMap.this.map).mapIterator(); return AbstractTestIterableMap.this.getMap().mapIterator();
} }
public MapIterator makeFullMapIterator() { public MapIterator<K, V> makeObject() {
resetFull(); resetFull();
return ((IterableMap) AbstractTestIterableMap.this.map).mapIterator(); return AbstractTestIterableMap.this.getMap().mapIterator();
} }
public Map getMap() { public Map<K, V> getMap() {
// assumes makeFullMapIterator() called first // assumes makeFullMapIterator() called first
return AbstractTestIterableMap.this.map; return AbstractTestIterableMap.this.getMap();
} }
public Map getConfirmedMap() { public Map<K, V> getConfirmedMap() {
// assumes makeFullMapIterator() called first // assumes makeFullMapIterator() called first
return AbstractTestIterableMap.this.confirmed; return AbstractTestIterableMap.this.getConfirmed();
} }
public void verify() { public void verify() {
super.verify(); super.verify();
AbstractTestIterableMap.this.verify(); AbstractTestIterableMap.this.verify();
} }
} }
// public void testCreate() throws Exception { // public void testCreate() throws Exception {
// resetEmpty(); // resetEmpty();
// writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.emptyCollection.version3.obj"); // writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.emptyCollection.version3.obj");
// resetFull(); // resetFull();
// writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.fullCollection.version3.obj"); // writeExternalFormToDisk((Serializable) map, "D:/dev/collections/data/test/HashedMap.fullCollection.version3.obj");
// } // }
/**
* {@inheritDoc}
*/
@Override
public IterableMap<K, V> getMap() {
return (IterableMap<K, V>) super.getMap();
}
} }