mirror of
https://github.com/apache/commons-collections.git
synced 2025-03-01 14:29:06 +00:00
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@815111 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
116ed1136a
commit
f0ef1c8d0e
@ -26,7 +26,7 @@ import org.apache.commons.collections.BidiMap;
|
|||||||
import org.apache.commons.collections.BulkTest;
|
import org.apache.commons.collections.BulkTest;
|
||||||
import org.apache.commons.collections.MapIterator;
|
import org.apache.commons.collections.MapIterator;
|
||||||
import org.apache.commons.collections.iterators.AbstractTestMapIterator;
|
import org.apache.commons.collections.iterators.AbstractTestMapIterator;
|
||||||
import org.apache.commons.collections.map.AbstractTestMap;
|
import org.apache.commons.collections.map.AbstractTestIterableMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract test class for {@link BidiMap} methods and contracts.
|
* Abstract test class for {@link BidiMap} methods and contracts.
|
||||||
@ -36,60 +36,31 @@ import org.apache.commons.collections.map.AbstractTestMap;
|
|||||||
* @author Matthew Hawthorne
|
* @author Matthew Hawthorne
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
public abstract class AbstractTestBidiMap<K, V> extends AbstractTestIterableMap<K, V> {
|
||||||
|
|
||||||
// Test data.
|
|
||||||
private static final Object[][] entriesKV =
|
|
||||||
new Object[][] {
|
|
||||||
new Object[] { "key1", "value1" },
|
|
||||||
new Object[] { "key2", "value2" },
|
|
||||||
new Object[] { "key3", "value3" }
|
|
||||||
};
|
|
||||||
private static final Object[][] entriesVK =
|
|
||||||
new Object[][] {
|
|
||||||
new Object[] { "value1", "key1" },
|
|
||||||
new Object[] { "value2", "key2" },
|
|
||||||
new Object[] { "value3", "key3" }
|
|
||||||
};
|
|
||||||
protected final Object[][] entries;
|
|
||||||
|
|
||||||
public AbstractTestBidiMap(String testName) {
|
public AbstractTestBidiMap(String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
entries = entriesKV;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractTestBidiMap() {
|
public AbstractTestBidiMap() {
|
||||||
super("Inverse");
|
super("Inverse");
|
||||||
entries = entriesVK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
|
||||||
* Implement to create an empty <code>BidiMap</code>.
|
|
||||||
*
|
|
||||||
* @return an empty <code>BidiMap</code> implementation.
|
|
||||||
*/
|
|
||||||
public abstract BidiMap makeEmptyBidiMap();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override to create a full <code>BidiMap</code> other than the default.
|
* Override to create a full <code>BidiMap</code> other than the default.
|
||||||
*
|
*
|
||||||
* @return a full <code>BidiMap</code> implementation.
|
* @return a full <code>BidiMap</code> implementation.
|
||||||
*/
|
*/
|
||||||
public BidiMap makeFullBidiMap() {
|
@Override
|
||||||
final BidiMap map = makeEmptyBidiMap();
|
public BidiMap<K, V> makeFullMap() {
|
||||||
for (int i = 0; i < entries.length; i++) {
|
return (BidiMap<K, V>) super.makeFullMap();
|
||||||
map.put(entries[i][0], entries[i][1]);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override to return the empty BidiMap.
|
* Override to return the empty BidiMap.
|
||||||
*/
|
*/
|
||||||
public final Map makeEmptyMap() {
|
public abstract BidiMap<K, V> makeObject();
|
||||||
return makeEmptyBidiMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override to indicate to AbstractTestMap this is a BidiMap.
|
* Override to indicate to AbstractTestMap this is a BidiMap.
|
||||||
@ -97,7 +68,7 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
public boolean isAllowDuplicateValues() {
|
public boolean isAllowDuplicateValues() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override as DualHashBidiMap didn't exist until version 3.
|
* Override as DualHashBidiMap didn't exist until version 3.
|
||||||
*/
|
*/
|
||||||
@ -107,33 +78,34 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
|
|
||||||
// BidiPut
|
// BidiPut
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void testBidiPut() {
|
public void testBidiPut() {
|
||||||
if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
|
if (isPutAddSupported() == false || isPutChangeSupported() == false) return;
|
||||||
|
|
||||||
BidiMap map = makeEmptyBidiMap();
|
BidiMap<K, V> map = makeObject();
|
||||||
BidiMap inverse = map.inverseBidiMap();
|
BidiMap<V, K> inverse = map.inverseBidiMap();
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
assertEquals(map.size(), inverse.size());
|
assertEquals(map.size(), inverse.size());
|
||||||
|
|
||||||
map.put("A", "B");
|
map.put((K) "A", (V) "B");
|
||||||
assertEquals(1, map.size());
|
assertEquals(1, map.size());
|
||||||
assertEquals(map.size(), inverse.size());
|
assertEquals(map.size(), inverse.size());
|
||||||
assertEquals("B", map.get("A"));
|
assertEquals("B", map.get("A"));
|
||||||
assertEquals("A", inverse.get("B"));
|
assertEquals("A", inverse.get("B"));
|
||||||
|
|
||||||
map.put("A", "C");
|
map.put((K) "A", (V) "C");
|
||||||
assertEquals(1, map.size());
|
assertEquals(1, map.size());
|
||||||
assertEquals(map.size(), inverse.size());
|
assertEquals(map.size(), inverse.size());
|
||||||
assertEquals("C", map.get("A"));
|
assertEquals("C", map.get("A"));
|
||||||
assertEquals("A", inverse.get("C"));
|
assertEquals("A", inverse.get("C"));
|
||||||
|
|
||||||
map.put("B", "C");
|
map.put((K) "B", (V) "C");
|
||||||
assertEquals(1, map.size());
|
assertEquals(1, map.size());
|
||||||
assertEquals(map.size(), inverse.size());
|
assertEquals(map.size(), inverse.size());
|
||||||
assertEquals("C", map.get("B"));
|
assertEquals("C", map.get("B"));
|
||||||
assertEquals("B", inverse.get("C"));
|
assertEquals("B", inverse.get("C"));
|
||||||
|
|
||||||
map.put("E", "F");
|
map.put((K) "E", (V) "F");
|
||||||
assertEquals(2, map.size());
|
assertEquals(2, map.size());
|
||||||
assertEquals(map.size(), inverse.size());
|
assertEquals(map.size(), inverse.size());
|
||||||
assertEquals("F", map.get("E"));
|
assertEquals("F", map.get("E"));
|
||||||
@ -151,33 +123,33 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void verifyInverse() {
|
public void verifyInverse() {
|
||||||
assertEquals(map.size(), ((BidiMap) map).inverseBidiMap().size());
|
assertEquals(map.size(), ((BidiMap<K, V>) map).inverseBidiMap().size());
|
||||||
Map map1 = new HashMap(map);
|
Map<K, V> map1 = new HashMap<K, V>(map);
|
||||||
Map map2 = new HashMap(((BidiMap) map).inverseBidiMap());
|
Map<V, K> map2 = new HashMap<V, K>(((BidiMap<K, V>) map).inverseBidiMap());
|
||||||
Set keys1 = map1.keySet();
|
Set<K> keys1 = map1.keySet();
|
||||||
Set keys2 = map2.keySet();
|
Set<V> keys2 = map2.keySet();
|
||||||
Collection values1 = map1.values();
|
Collection<V> values1 = map1.values();
|
||||||
Collection values2 = map2.values();
|
Collection<K> values2 = map2.values();
|
||||||
assertEquals(true, keys1.containsAll(values2));
|
assertEquals(true, keys1.containsAll(values2));
|
||||||
assertEquals(true, values2.containsAll(keys1));
|
assertEquals(true, values2.containsAll(keys1));
|
||||||
assertEquals(true, values1.containsAll(keys2));
|
assertEquals(true, values1.containsAll(keys2));
|
||||||
assertEquals(true, keys2.containsAll(values1));
|
assertEquals(true, keys2.containsAll(values1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// testGetKey
|
// testGetKey
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiGetKey() {
|
public void testBidiGetKey() {
|
||||||
doTestGetKey(makeFullBidiMap(), entries[0][0], entries[0][1]);
|
doTestGetKey(makeFullMap(), getSampleKeys()[0], getSampleValues()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBidiGetKeyInverse() {
|
public void testBidiGetKeyInverse() {
|
||||||
doTestGetKey(
|
doTestGetKey(
|
||||||
makeFullBidiMap().inverseBidiMap(),
|
makeFullMap().inverseBidiMap(),
|
||||||
entries[0][1],
|
getSampleValues()[0],
|
||||||
entries[0][0]);
|
getSampleKeys()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void doTestGetKey(BidiMap map, Object key, Object value) {
|
private final void doTestGetKey(BidiMap<?, ?> map, Object key, Object value) {
|
||||||
assertEquals("Value not found for key.", value, map.get(key));
|
assertEquals("Value not found for key.", value, map.get(key));
|
||||||
assertEquals("Key not found for value.", key, map.getKey(value));
|
assertEquals("Key not found for value.", key, map.getKey(value));
|
||||||
}
|
}
|
||||||
@ -185,8 +157,8 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
// testInverse
|
// testInverse
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiInverse() {
|
public void testBidiInverse() {
|
||||||
final BidiMap map = makeFullBidiMap();
|
final BidiMap<K, V> map = makeFullMap();
|
||||||
final BidiMap inverseMap = map.inverseBidiMap();
|
final BidiMap<V, K> inverseMap = map.inverseBidiMap();
|
||||||
|
|
||||||
assertSame(
|
assertSame(
|
||||||
"Inverse of inverse is not equal to original.",
|
"Inverse of inverse is not equal to original.",
|
||||||
@ -195,26 +167,27 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Value not found for key.",
|
"Value not found for key.",
|
||||||
entries[0][0],
|
getSampleKeys()[0],
|
||||||
inverseMap.get(entries[0][1]));
|
inverseMap.get(getSampleValues()[0]));
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Key not found for value.",
|
"Key not found for value.",
|
||||||
entries[0][1],
|
getSampleValues()[0],
|
||||||
inverseMap.getKey(entries[0][0]));
|
inverseMap.getKey(getSampleKeys()[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiModifyEntrySet() {
|
public void testBidiModifyEntrySet() {
|
||||||
if (isSetValueSupported() == false) return;
|
if (isSetValueSupported() == false) return;
|
||||||
|
|
||||||
modifyEntrySet(makeFullBidiMap());
|
modifyEntrySet(makeFullMap());
|
||||||
modifyEntrySet(makeFullBidiMap().inverseBidiMap());
|
modifyEntrySet(makeFullMap().inverseBidiMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void modifyEntrySet(BidiMap map) {
|
@SuppressWarnings("unchecked")
|
||||||
|
private final <T> void modifyEntrySet(BidiMap<?, T> map) {
|
||||||
// Gets first entry
|
// Gets first entry
|
||||||
final Map.Entry entry = (Map.Entry)map.entrySet().iterator().next();
|
final Map.Entry<?, T> entry = map.entrySet().iterator().next();
|
||||||
|
|
||||||
// Gets key and value
|
// Gets key and value
|
||||||
final Object key = entry.getKey();
|
final Object key = entry.getKey();
|
||||||
@ -222,7 +195,7 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
|
|
||||||
// Sets new value
|
// Sets new value
|
||||||
final Object newValue = "newValue";
|
final Object newValue = "newValue";
|
||||||
entry.setValue(newValue);
|
entry.setValue((T) newValue);
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Modifying entrySet did not affect underlying Map.",
|
"Modifying entrySet did not affect underlying Map.",
|
||||||
@ -238,19 +211,19 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
public void testBidiClear() {
|
public void testBidiClear() {
|
||||||
if (isRemoveSupported() == false) {
|
if (isRemoveSupported() == false) {
|
||||||
try {
|
try {
|
||||||
makeFullBidiMap().clear();
|
makeFullMap().clear();
|
||||||
fail();
|
fail();
|
||||||
} catch(UnsupportedOperationException ex) {}
|
} catch(UnsupportedOperationException ex) {}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BidiMap map = makeFullBidiMap();
|
BidiMap<?, ?> map = makeFullMap();
|
||||||
map.clear();
|
map.clear();
|
||||||
assertTrue("Map was not cleared.", map.isEmpty());
|
assertTrue("Map was not cleared.", map.isEmpty());
|
||||||
assertTrue("Inverse map was not cleared.", map.inverseBidiMap().isEmpty());
|
assertTrue("Inverse map was not cleared.", map.inverseBidiMap().isEmpty());
|
||||||
|
|
||||||
// Tests clear on inverse
|
// Tests clear on inverse
|
||||||
map = makeFullBidiMap().inverseBidiMap();
|
map = makeFullMap().inverseBidiMap();
|
||||||
map.clear();
|
map.clear();
|
||||||
assertTrue("Map was not cleared.", map.isEmpty());
|
assertTrue("Map was not cleared.", map.isEmpty());
|
||||||
assertTrue("Inverse map was not cleared.", map.inverseBidiMap().isEmpty());
|
assertTrue("Inverse map was not cleared.", map.inverseBidiMap().isEmpty());
|
||||||
@ -261,32 +234,32 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
public void testBidiRemove() {
|
public void testBidiRemove() {
|
||||||
if (isRemoveSupported() == false) {
|
if (isRemoveSupported() == false) {
|
||||||
try {
|
try {
|
||||||
makeFullBidiMap().remove(entries[0][0]);
|
makeFullMap().remove(getSampleKeys()[0]);
|
||||||
fail();
|
fail();
|
||||||
} catch(UnsupportedOperationException ex) {}
|
} catch(UnsupportedOperationException ex) {}
|
||||||
try {
|
try {
|
||||||
makeFullBidiMap().removeValue(entries[0][1]);
|
makeFullMap().removeValue(getSampleValues()[0]);
|
||||||
fail();
|
fail();
|
||||||
} catch(UnsupportedOperationException ex) {}
|
} catch(UnsupportedOperationException ex) {}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(makeFullBidiMap(), entries[0][0]);
|
|
||||||
remove(makeFullBidiMap().inverseBidiMap(), entries[0][1]);
|
|
||||||
|
|
||||||
removeValue(makeFullBidiMap(), entries[0][1]);
|
remove(makeFullMap(), getSampleKeys()[0]);
|
||||||
removeValue(makeFullBidiMap().inverseBidiMap(), entries[0][0]);
|
remove(makeFullMap().inverseBidiMap(), getSampleValues()[0]);
|
||||||
|
|
||||||
assertEquals(null, makeFullBidiMap().removeValue("NotPresent"));
|
removeValue(makeFullMap(), getSampleValues()[0]);
|
||||||
|
removeValue(makeFullMap().inverseBidiMap(), getSampleKeys()[0]);
|
||||||
|
|
||||||
|
assertEquals(null, makeFullMap().removeValue("NotPresent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void remove(BidiMap map, Object key) {
|
private final void remove(BidiMap<?, ?> map, Object key) {
|
||||||
final Object value = map.remove(key);
|
final Object value = map.remove(key);
|
||||||
assertTrue("Key was not removed.", !map.containsKey(key));
|
assertTrue("Key was not removed.", !map.containsKey(key));
|
||||||
assertNull("Value was not removed.", map.getKey(value));
|
assertNull("Value was not removed.", map.getKey(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void removeValue(BidiMap map, Object value) {
|
private final void removeValue(BidiMap<?, ?> map, Object value) {
|
||||||
final Object key = map.removeValue(value);
|
final Object key = map.removeValue(value);
|
||||||
assertTrue("Key was not removed.", !map.containsKey(key));
|
assertTrue("Key was not removed.", !map.containsKey(key));
|
||||||
assertNull("Value was not removed.", map.getKey(value));
|
assertNull("Value was not removed.", map.getKey(value));
|
||||||
@ -295,11 +268,11 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiKeySetValuesOrder() {
|
public void testBidiKeySetValuesOrder() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Iterator keys = map.keySet().iterator();
|
Iterator<K> keys = map.keySet().iterator();
|
||||||
Iterator values = map.values().iterator();
|
Iterator<V> values = map.values().iterator();
|
||||||
for (; keys.hasNext() && values.hasNext();) {
|
for (; keys.hasNext() && values.hasNext();) {
|
||||||
Object key = keys.next();
|
K key = keys.next();
|
||||||
Object value = values.next();
|
V value = values.next();
|
||||||
assertSame(map.get(key), value);
|
assertSame(map.get(key), value);
|
||||||
}
|
}
|
||||||
assertEquals(false, keys.hasNext());
|
assertEquals(false, keys.hasNext());
|
||||||
@ -309,12 +282,12 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiRemoveByKeySet() {
|
public void testBidiRemoveByKeySet() {
|
||||||
if (isRemoveSupported() == false) return;
|
if (isRemoveSupported() == false) return;
|
||||||
|
|
||||||
removeByKeySet(makeFullBidiMap(), entries[0][0], entries[0][1]);
|
removeByKeySet(makeFullMap(), getSampleKeys()[0], getSampleValues()[0]);
|
||||||
removeByKeySet(makeFullBidiMap().inverseBidiMap(), entries[0][1], entries[0][0]);
|
removeByKeySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void removeByKeySet(BidiMap map, Object key, Object value) {
|
private final void removeByKeySet(BidiMap<?, ?> map, Object key, Object value) {
|
||||||
map.keySet().remove(key);
|
map.keySet().remove(key);
|
||||||
|
|
||||||
assertTrue("Key was not removed.", !map.containsKey(key));
|
assertTrue("Key was not removed.", !map.containsKey(key));
|
||||||
@ -331,13 +304,13 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiRemoveByEntrySet() {
|
public void testBidiRemoveByEntrySet() {
|
||||||
if (isRemoveSupported() == false) return;
|
if (isRemoveSupported() == false) return;
|
||||||
|
|
||||||
removeByEntrySet(makeFullBidiMap(), entries[0][0], entries[0][1]);
|
removeByEntrySet(makeFullMap(), getSampleKeys()[0], getSampleValues()[0]);
|
||||||
removeByEntrySet(makeFullBidiMap().inverseBidiMap(), entries[0][1], entries[0][0]);
|
removeByEntrySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void removeByEntrySet(BidiMap map, Object key, Object value) {
|
private final void removeByEntrySet(BidiMap<?, ?> map, Object key, Object value) {
|
||||||
Map temp = new HashMap();
|
Map<Object, Object> temp = new HashMap<Object, Object>();
|
||||||
temp.put(key, value);
|
temp.put(key, value);
|
||||||
map.entrySet().remove(temp.entrySet().iterator().next());
|
map.entrySet().remove(temp.entrySet().iterator().next());
|
||||||
|
|
||||||
@ -352,6 +325,14 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
!map.inverseBidiMap().containsKey(value));
|
!map.inverseBidiMap().containsKey(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public BidiMap<K, V> getMap() {
|
||||||
|
return (BidiMap<K, V>) super.getMap();
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public BulkTest bulkTestMapEntrySet() {
|
public BulkTest bulkTestMapEntrySet() {
|
||||||
return new TestBidiMapEntrySet();
|
return new TestBidiMapEntrySet();
|
||||||
@ -362,24 +343,24 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
public void testMapEntrySetIteratorEntrySetValueCrossCheck() {
|
public void testMapEntrySetIteratorEntrySetValueCrossCheck() {
|
||||||
Object key1 = getSampleKeys()[0];
|
K key1 = getSampleKeys()[0];
|
||||||
Object key2 = getSampleKeys()[1];
|
K key2 = getSampleKeys()[1];
|
||||||
Object newValue1 = getNewSampleValues()[0];
|
V newValue1 = getNewSampleValues()[0];
|
||||||
Object newValue2 = getNewSampleValues()[1];
|
V newValue2 = getNewSampleValues()[1];
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
// explicitly get entries as sample values/keys are connected for some maps
|
// explicitly get entries as sample values/keys are connected for some maps
|
||||||
// such as BeanMap
|
// such as BeanMap
|
||||||
Iterator it = TestBidiMapEntrySet.this.collection.iterator();
|
Iterator<Map.Entry<K, V>> it = TestBidiMapEntrySet.this.getCollection().iterator();
|
||||||
Map.Entry entry1 = getEntry(it, key1);
|
Map.Entry<K, V> entry1 = getEntry(it, key1);
|
||||||
it = TestBidiMapEntrySet.this.collection.iterator();
|
it = TestBidiMapEntrySet.this.getCollection().iterator();
|
||||||
Map.Entry entry2 = getEntry(it, key2);
|
Map.Entry<K, V> entry2 = getEntry(it, key2);
|
||||||
Iterator itConfirmed = TestBidiMapEntrySet.this.confirmed.iterator();
|
Iterator<Map.Entry<K, V>> itConfirmed = TestBidiMapEntrySet.this.getConfirmed().iterator();
|
||||||
Map.Entry entryConfirmed1 = getEntry(itConfirmed, key1);
|
Map.Entry<K, V> entryConfirmed1 = getEntry(itConfirmed, key1);
|
||||||
itConfirmed = TestBidiMapEntrySet.this.confirmed.iterator();
|
itConfirmed = TestBidiMapEntrySet.this.getConfirmed().iterator();
|
||||||
Map.Entry entryConfirmed2 = getEntry(itConfirmed, key2);
|
Map.Entry<K, V> entryConfirmed2 = getEntry(itConfirmed, key2);
|
||||||
TestBidiMapEntrySet.this.verify();
|
TestBidiMapEntrySet.this.verify();
|
||||||
|
|
||||||
if (isSetValueSupported() == false) {
|
if (isSetValueSupported() == false) {
|
||||||
try {
|
try {
|
||||||
entry1.setValue(newValue1);
|
entry1.setValue(newValue1);
|
||||||
@ -388,12 +369,12 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// these checked in superclass
|
// these checked in superclass
|
||||||
entry1.setValue(newValue1);
|
entry1.setValue(newValue1);
|
||||||
entryConfirmed1.setValue(newValue1);
|
entryConfirmed1.setValue(newValue1);
|
||||||
entry2.setValue(newValue2);
|
entry2.setValue(newValue2);
|
||||||
entryConfirmed2.setValue(newValue2);
|
entryConfirmed2.setValue(newValue2);
|
||||||
|
|
||||||
// at this point
|
// at this point
|
||||||
// key1=newValue1, key2=newValue2
|
// key1=newValue1, key2=newValue2
|
||||||
try {
|
try {
|
||||||
@ -402,15 +383,15 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
return; // simplest way of dealing with tricky situation
|
return; // simplest way of dealing with tricky situation
|
||||||
}
|
}
|
||||||
entryConfirmed2.setValue(newValue1);
|
entryConfirmed2.setValue(newValue1);
|
||||||
AbstractTestBidiMap.this.confirmed.remove(key1);
|
AbstractTestBidiMap.this.getConfirmed().remove(key1);
|
||||||
assertEquals(newValue1, entry2.getValue());
|
assertEquals(newValue1, entry2.getValue());
|
||||||
assertEquals(true, AbstractTestBidiMap.this.map.containsKey(entry2.getKey()));
|
assertEquals(true, AbstractTestBidiMap.this.getMap().containsKey(entry2.getKey()));
|
||||||
assertEquals(true, AbstractTestBidiMap.this.map.containsValue(newValue1));
|
assertEquals(true, AbstractTestBidiMap.this.getMap().containsValue(newValue1));
|
||||||
assertEquals(newValue1, AbstractTestBidiMap.this.map.get(entry2.getKey()));
|
assertEquals(newValue1, AbstractTestBidiMap.this.getMap().get(entry2.getKey()));
|
||||||
assertEquals(false, AbstractTestBidiMap.this.map.containsKey(key1));
|
assertEquals(false, AbstractTestBidiMap.this.getMap().containsKey(key1));
|
||||||
assertEquals(false, AbstractTestBidiMap.this.map.containsValue(newValue2));
|
assertEquals(false, AbstractTestBidiMap.this.getMap().containsValue(newValue2));
|
||||||
TestBidiMapEntrySet.this.verify();
|
TestBidiMapEntrySet.this.verify();
|
||||||
|
|
||||||
// check for ConcurrentModification
|
// check for ConcurrentModification
|
||||||
it.next(); // if you fail here, maybe you should be throwing an IAE, see above
|
it.next(); // if you fail here, maybe you should be throwing an IAE, see above
|
||||||
if (isRemoveSupported()) {
|
if (isRemoveSupported()) {
|
||||||
@ -418,72 +399,78 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BulkTest bulkTestInverseMap() {
|
public BulkTest bulkTestInverseMap() {
|
||||||
return new TestInverseBidiMap(this);
|
return new TestInverseBidiMap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestInverseBidiMap extends AbstractTestBidiMap {
|
public class TestInverseBidiMap extends AbstractTestBidiMap<V, K> {
|
||||||
final AbstractTestBidiMap main;
|
final AbstractTestBidiMap<K, V> main;
|
||||||
|
|
||||||
public TestInverseBidiMap(AbstractTestBidiMap main) {
|
public TestInverseBidiMap(AbstractTestBidiMap<K, V> main) {
|
||||||
super();
|
super();
|
||||||
this.main = main;
|
this.main = main;
|
||||||
}
|
}
|
||||||
public BidiMap makeEmptyBidiMap() {
|
|
||||||
return main.makeEmptyBidiMap().inverseBidiMap();
|
public BidiMap<V, K> makeObject() {
|
||||||
|
return main.makeObject().inverseBidiMap();
|
||||||
}
|
}
|
||||||
public BidiMap makeFullBidiMap() {
|
|
||||||
return main.makeFullBidiMap().inverseBidiMap();
|
public BidiMap<V, K> makeFullMap() {
|
||||||
|
return main.makeFullMap().inverseBidiMap();
|
||||||
}
|
}
|
||||||
public Map makeFullMap() {
|
|
||||||
return ((BidiMap) main.makeFullMap()).inverseBidiMap();
|
public V[] getSampleKeys() {
|
||||||
}
|
|
||||||
public Object[] getSampleKeys() {
|
|
||||||
return main.getSampleValues();
|
return main.getSampleValues();
|
||||||
}
|
}
|
||||||
public Object[] getSampleValues() {
|
public K[] getSampleValues() {
|
||||||
return main.getSampleKeys();
|
return main.getSampleKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCompatibilityVersion() {
|
public String getCompatibilityVersion() {
|
||||||
return main.getCompatibilityVersion();
|
return main.getCompatibilityVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowNullKey() {
|
public boolean isAllowNullKey() {
|
||||||
return main.isAllowNullKey();
|
return main.isAllowNullKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowNullValue() {
|
public boolean isAllowNullValue() {
|
||||||
return main.isAllowNullValue();
|
return main.isAllowNullValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPutAddSupported() {
|
public boolean isPutAddSupported() {
|
||||||
return main.isPutAddSupported();
|
return main.isPutAddSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPutChangeSupported() {
|
public boolean isPutChangeSupported() {
|
||||||
return main.isPutChangeSupported();
|
return main.isPutChangeSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSetValueSupported() {
|
public boolean isSetValueSupported() {
|
||||||
return main.isSetValueSupported();
|
return main.isSetValueSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemoveSupported() {
|
public boolean isRemoveSupported() {
|
||||||
return main.isRemoveSupported();
|
return main.isRemoveSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public BulkTest bulkTestBidiMapIterator() {
|
public BulkTest bulkTestBidiMapIterator() {
|
||||||
return new TestBidiMapIterator();
|
return new TestBidiMapIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestBidiMapIterator extends AbstractTestMapIterator {
|
public class TestBidiMapIterator extends AbstractTestMapIterator<K, V> {
|
||||||
public TestBidiMapIterator() {
|
public TestBidiMapIterator() {
|
||||||
super("TestBidiMapIterator");
|
super("TestBidiMapIterator");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] addSetValues() {
|
public V[] addSetValues() {
|
||||||
return AbstractTestBidiMap.this.getNewSampleValues();
|
return AbstractTestBidiMap.this.getNewSampleValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsRemove() {
|
public boolean supportsRemove() {
|
||||||
return AbstractTestBidiMap.this.isRemoveSupported();
|
return AbstractTestBidiMap.this.isRemoveSupported();
|
||||||
}
|
}
|
||||||
@ -492,43 +479,43 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
return AbstractTestBidiMap.this.isSetValueSupported();
|
return AbstractTestBidiMap.this.isSetValueSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapIterator makeEmptyMapIterator() {
|
public MapIterator<K, V> makeEmptyIterator() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
return ((BidiMap) AbstractTestBidiMap.this.map).mapIterator();
|
return AbstractTestBidiMap.this.getMap().mapIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapIterator makeFullMapIterator() {
|
public MapIterator<K, V> makeObject() {
|
||||||
resetFull();
|
resetFull();
|
||||||
return ((BidiMap) AbstractTestBidiMap.this.map).mapIterator();
|
return AbstractTestBidiMap.this.getMap().mapIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getMap() {
|
public BidiMap<K, V> getMap() {
|
||||||
// assumes makeFullMapIterator() called first
|
// assumes makeFullMapIterator() called first
|
||||||
return AbstractTestBidiMap.this.map;
|
return AbstractTestBidiMap.this.getMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getConfirmedMap() {
|
public Map<K, V> getConfirmedMap() {
|
||||||
// assumes makeFullMapIterator() called first
|
// assumes makeFullMapIterator() called first
|
||||||
return AbstractTestBidiMap.this.confirmed;
|
return AbstractTestBidiMap.this.getConfirmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verify() {
|
public void verify() {
|
||||||
super.verify();
|
super.verify();
|
||||||
AbstractTestBidiMap.this.verify();
|
AbstractTestBidiMap.this.verify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void testBidiMapIteratorSet() {
|
public void testBidiMapIteratorSet() {
|
||||||
Object newValue1 = getOtherValues()[0];
|
V newValue1 = getOtherValues()[0];
|
||||||
Object newValue2 = getOtherValues()[1];
|
V newValue2 = getOtherValues()[1];
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
BidiMap bidi = (BidiMap) map;
|
BidiMap<K, V> bidi = getMap();
|
||||||
MapIterator it = bidi.mapIterator();
|
MapIterator<K, V> it = bidi.mapIterator();
|
||||||
assertEquals(true, it.hasNext());
|
assertEquals(true, it.hasNext());
|
||||||
Object key1 = it.next();
|
K key1 = it.next();
|
||||||
|
|
||||||
if (isSetValueSupported() == false) {
|
if (isSetValueSupported() == false) {
|
||||||
try {
|
try {
|
||||||
it.setValue(newValue1);
|
it.setValue(newValue1);
|
||||||
@ -537,7 +524,7 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
it.setValue(newValue1);
|
it.setValue(newValue1);
|
||||||
confirmed.put(key1, newValue1);
|
confirmed.put(key1, newValue1);
|
||||||
assertSame(key1, it.getKey());
|
assertSame(key1, it.getKey());
|
||||||
@ -546,7 +533,7 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
assertEquals(true, bidi.containsValue(newValue1));
|
assertEquals(true, bidi.containsValue(newValue1));
|
||||||
assertEquals(newValue1, bidi.get(key1));
|
assertEquals(newValue1, bidi.get(key1));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
it.setValue(newValue1); // same value - should be OK
|
it.setValue(newValue1); // same value - should be OK
|
||||||
confirmed.put(key1, newValue1);
|
confirmed.put(key1, newValue1);
|
||||||
assertSame(key1, it.getKey());
|
assertSame(key1, it.getKey());
|
||||||
@ -555,8 +542,8 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
assertEquals(true, bidi.containsValue(newValue1));
|
assertEquals(true, bidi.containsValue(newValue1));
|
||||||
assertEquals(newValue1, bidi.get(key1));
|
assertEquals(newValue1, bidi.get(key1));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
Object key2 = it.next();
|
K key2 = it.next();
|
||||||
it.setValue(newValue2);
|
it.setValue(newValue2);
|
||||||
confirmed.put(key2, newValue2);
|
confirmed.put(key2, newValue2);
|
||||||
assertSame(key2, it.getKey());
|
assertSame(key2, it.getKey());
|
||||||
@ -565,7 +552,7 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
assertEquals(true, bidi.containsValue(newValue2));
|
assertEquals(true, bidi.containsValue(newValue2));
|
||||||
assertEquals(newValue2, bidi.get(key2));
|
assertEquals(newValue2, bidi.get(key2));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
// at this point
|
// at this point
|
||||||
// key1=newValue1, key2=newValue2
|
// key1=newValue1, key2=newValue2
|
||||||
try {
|
try {
|
||||||
@ -575,7 +562,7 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
return; // simplest way of dealing with tricky situation
|
return; // simplest way of dealing with tricky situation
|
||||||
}
|
}
|
||||||
confirmed.put(key2, newValue1);
|
confirmed.put(key2, newValue1);
|
||||||
AbstractTestBidiMap.this.confirmed.remove(key1);
|
AbstractTestBidiMap.this.getConfirmed().remove(key1);
|
||||||
assertEquals(newValue1, it.getValue());
|
assertEquals(newValue1, it.getValue());
|
||||||
assertEquals(true, bidi.containsKey(it.getKey()));
|
assertEquals(true, bidi.containsKey(it.getKey()));
|
||||||
assertEquals(true, bidi.containsValue(newValue1));
|
assertEquals(true, bidi.containsValue(newValue1));
|
||||||
@ -583,7 +570,7 @@ public abstract class AbstractTestBidiMap extends AbstractTestMap {
|
|||||||
assertEquals(false, bidi.containsKey(key1));
|
assertEquals(false, bidi.containsKey(key1));
|
||||||
assertEquals(false, bidi.containsValue(newValue2));
|
assertEquals(false, bidi.containsValue(newValue2));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
// check for ConcurrentModification
|
// check for ConcurrentModification
|
||||||
it.next(); // if you fail here, maybe you should be throwing an IAE, see above
|
it.next(); // if you fail here, maybe you should be throwing an IAE, see above
|
||||||
if (isRemoveSupported()) {
|
if (isRemoveSupported()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user