tab police
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1070674 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9a24ed01f7
commit
d1016f05a5
|
@ -1216,82 +1216,82 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject {
|
||||||
* Tests values.removeAll.
|
* Tests values.removeAll.
|
||||||
*/
|
*/
|
||||||
public void testValuesRemoveAll() {
|
public void testValuesRemoveAll() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Collection<V> values = getMap().values();
|
Collection<V> values = getMap().values();
|
||||||
List<V> sampleValuesAsList = Arrays.asList(getSampleValues());
|
List<V> sampleValuesAsList = Arrays.asList(getSampleValues());
|
||||||
if (!values.equals(sampleValuesAsList)) {
|
if (!values.equals(sampleValuesAsList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
assertFalse(values.removeAll(Collections.<V> emptySet()));
|
assertFalse(values.removeAll(Collections.<V> emptySet()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// if values.removeAll is unsupported, just skip this test
|
// if values.removeAll is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertEquals(sampleValuesAsList.size(), getMap().size());
|
assertEquals(sampleValuesAsList.size(), getMap().size());
|
||||||
try {
|
try {
|
||||||
assertTrue(values.removeAll(sampleValuesAsList));
|
assertTrue(values.removeAll(sampleValuesAsList));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// if values.removeAll is unsupported, just skip this test
|
// if values.removeAll is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(getMap().isEmpty());
|
assertTrue(getMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test values.retainAll.
|
* Test values.retainAll.
|
||||||
*/
|
*/
|
||||||
public void testValuesRetainAll() {
|
public void testValuesRetainAll() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Collection<V> values = getMap().values();
|
Collection<V> values = getMap().values();
|
||||||
List<V> sampleValuesAsList = Arrays.asList(getSampleValues());
|
List<V> sampleValuesAsList = Arrays.asList(getSampleValues());
|
||||||
if (!values.equals(sampleValuesAsList)) {
|
if (!values.equals(sampleValuesAsList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
assertFalse(values.retainAll(sampleValuesAsList));
|
assertFalse(values.retainAll(sampleValuesAsList));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// if values.retainAll is unsupported, just skip this test
|
// if values.retainAll is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertEquals(sampleValuesAsList.size(), getMap().size());
|
assertEquals(sampleValuesAsList.size(), getMap().size());
|
||||||
try {
|
try {
|
||||||
assertTrue(values.retainAll(Collections.<V> emptySet()));
|
assertTrue(values.retainAll(Collections.<V> emptySet()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// if values.retainAll is unsupported, just skip this test
|
// if values.retainAll is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(getMap().isEmpty());
|
assertTrue(getMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that values.iterator.remove changes the underlying map.
|
* Verifies that values.iterator.remove changes the underlying map.
|
||||||
*/
|
*/
|
||||||
public void testValuesIteratorRemoveChangesMap() {
|
public void testValuesIteratorRemoveChangesMap() {
|
||||||
resetFull();
|
resetFull();
|
||||||
List<V> sampleValuesAsList = Arrays.asList(getSampleValues());
|
List<V> sampleValuesAsList = Arrays.asList(getSampleValues());
|
||||||
Map<V, Integer> cardinality = CollectionUtils.getCardinalityMap(sampleValuesAsList);
|
Map<V, Integer> cardinality = CollectionUtils.getCardinalityMap(sampleValuesAsList);
|
||||||
Collection<V> values = getMap().values();
|
Collection<V> values = getMap().values();
|
||||||
for (Iterator<V> iter = values.iterator(); iter.hasNext();) {
|
for (Iterator<V> iter = values.iterator(); iter.hasNext();) {
|
||||||
V value = iter.next();
|
V value = iter.next();
|
||||||
Integer count = cardinality.get(value);
|
Integer count = cardinality.get(value);
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
cardinality.put(value, --count);
|
cardinality.put(value, --count);
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// if values.iterator.remove is unsupported, just skip this test
|
// if values.iterator.remove is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean expected = count > 0;
|
boolean expected = count > 0;
|
||||||
StringBuilder msg = new StringBuilder("Value should ");
|
StringBuilder msg = new StringBuilder("Value should ");
|
||||||
msg.append(expected ? "yet " : "no longer ");
|
msg.append(expected ? "yet " : "no longer ");
|
||||||
msg.append("be present in the underlying map");
|
msg.append("be present in the underlying map");
|
||||||
assertEquals(msg.toString(), expected, getMap().containsValue(value));
|
assertEquals(msg.toString(), expected, getMap().containsValue(value));
|
||||||
}
|
}
|
||||||
assertTrue(getMap().isEmpty());
|
assertTrue(getMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1324,18 +1324,18 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject {
|
||||||
Set<K> keys = getMap().keySet();
|
Set<K> keys = getMap().keySet();
|
||||||
List<K> sampleKeysAsList = Arrays.asList(getSampleKeys());
|
List<K> sampleKeysAsList = Arrays.asList(getSampleKeys());
|
||||||
if (!keys.equals(sampleKeysAsList)) {
|
if (!keys.equals(sampleKeysAsList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
assertFalse(keys.removeAll(Collections.<K> emptySet()));
|
assertFalse(keys.removeAll(Collections.<K> emptySet()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertEquals(sampleKeysAsList, keys);
|
assertEquals(sampleKeysAsList, keys);
|
||||||
try {
|
try {
|
||||||
assertTrue(keys.removeAll(sampleKeysAsList));
|
assertTrue(keys.removeAll(sampleKeysAsList));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(getMap().isEmpty());
|
assertTrue(getMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -1348,18 +1348,18 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject {
|
||||||
Set<K> keys = getMap().keySet();
|
Set<K> keys = getMap().keySet();
|
||||||
List<K> sampleKeysAsList = Arrays.asList(getSampleKeys());
|
List<K> sampleKeysAsList = Arrays.asList(getSampleKeys());
|
||||||
if (!keys.equals(sampleKeysAsList)) {
|
if (!keys.equals(sampleKeysAsList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
assertFalse(keys.retainAll(sampleKeysAsList));
|
assertFalse(keys.retainAll(sampleKeysAsList));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertEquals(sampleKeysAsList, keys);
|
assertEquals(sampleKeysAsList, keys);
|
||||||
try {
|
try {
|
||||||
assertTrue(keys.retainAll(Collections.<K> emptySet()));
|
assertTrue(keys.retainAll(Collections.<K> emptySet()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(getMap().isEmpty());
|
assertTrue(getMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -1370,13 +1370,13 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject {
|
||||||
public void testKeySetIteratorRemoveChangesMap() {
|
public void testKeySetIteratorRemoveChangesMap() {
|
||||||
resetFull();
|
resetFull();
|
||||||
for (Iterator<K> iter = getMap().keySet().iterator(); iter.hasNext();) {
|
for (Iterator<K> iter = getMap().keySet().iterator(); iter.hasNext();) {
|
||||||
K key = iter.next();
|
K key = iter.next();
|
||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertFalse(getMap().containsKey(key));
|
assertFalse(getMap().containsKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1386,91 +1386,91 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject {
|
||||||
* and testing if the entry was removed from the map.
|
* and testing if the entry was removed from the map.
|
||||||
*/
|
*/
|
||||||
public void testEntrySetRemoveChangesMap() {
|
public void testEntrySetRemoveChangesMap() {
|
||||||
resetFull();
|
resetFull();
|
||||||
K[] sampleKeys = getSampleKeys();
|
K[] sampleKeys = getSampleKeys();
|
||||||
V[] sampleValues = getSampleValues();
|
V[] sampleValues = getSampleValues();
|
||||||
Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
|
Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
|
||||||
for (int i = 0; i < sampleKeys.length; i++) {
|
for (int i = 0; i < sampleKeys.length; i++) {
|
||||||
try {
|
try {
|
||||||
entrySet.remove(new DefaultMapEntry<K, V>(sampleKeys[i], sampleValues[i]));
|
entrySet.remove(new DefaultMapEntry<K, V>(sampleKeys[i], sampleValues[i]));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// if entrySet removal is unsupported, just skip this test
|
// if entrySet removal is unsupported, just skip this test
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Entry should have been removed from the underlying map.",
|
"Entry should have been removed from the underlying map.",
|
||||||
!getMap().containsKey(sampleKeys[i]));
|
!getMap().containsKey(sampleKeys[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test entrySet.removeAll.
|
* Test entrySet.removeAll.
|
||||||
*/
|
*/
|
||||||
public void testEntrySetRemoveAll() {
|
public void testEntrySetRemoveAll() {
|
||||||
resetFull();
|
resetFull();
|
||||||
K[] sampleKeys = getSampleKeys();
|
K[] sampleKeys = getSampleKeys();
|
||||||
V[] sampleValues = getSampleValues();
|
V[] sampleValues = getSampleValues();
|
||||||
//verify map looks as expected:
|
//verify map looks as expected:
|
||||||
for (int i = 0; i < sampleKeys.length; i++) {
|
for (int i = 0; i < sampleKeys.length; i++) {
|
||||||
if (!getMap().containsKey(sampleKeys[i])) {
|
if (!getMap().containsKey(sampleKeys[i])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
V value = sampleValues[i];
|
V value = sampleValues[i];
|
||||||
V test = getMap().get(sampleKeys[i]);
|
V test = getMap().get(sampleKeys[i]);
|
||||||
if (value == test || value != null && value.equals(test)) {
|
if (value == test || value != null && value.equals(test)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
|
Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
|
||||||
HashSet<Map.Entry<K, V>> comparisonSet = new HashSet<Map.Entry<K, V>>(entrySet);
|
HashSet<Map.Entry<K, V>> comparisonSet = new HashSet<Map.Entry<K, V>>(entrySet);
|
||||||
try {
|
try {
|
||||||
assertFalse(entrySet.removeAll(Collections.<Map.Entry<K, V>> emptySet()));
|
assertFalse(entrySet.removeAll(Collections.<Map.Entry<K, V>> emptySet()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertEquals(sampleKeys.length, getMap().size());
|
assertEquals(sampleKeys.length, getMap().size());
|
||||||
try {
|
try {
|
||||||
assertTrue(entrySet.removeAll(comparisonSet));
|
assertTrue(entrySet.removeAll(comparisonSet));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(getMap().isEmpty());
|
assertTrue(getMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test entrySet.retainAll.
|
* Test entrySet.retainAll.
|
||||||
*/
|
*/
|
||||||
public void testEntrySetRetainAll() {
|
public void testEntrySetRetainAll() {
|
||||||
resetFull();
|
resetFull();
|
||||||
K[] sampleKeys = getSampleKeys();
|
K[] sampleKeys = getSampleKeys();
|
||||||
V[] sampleValues = getSampleValues();
|
V[] sampleValues = getSampleValues();
|
||||||
//verify map looks as expected:
|
//verify map looks as expected:
|
||||||
for (int i = 0; i < sampleKeys.length; i++) {
|
for (int i = 0; i < sampleKeys.length; i++) {
|
||||||
if (!getMap().containsKey(sampleKeys[i])) {
|
if (!getMap().containsKey(sampleKeys[i])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
V value = sampleValues[i];
|
V value = sampleValues[i];
|
||||||
V test = getMap().get(sampleKeys[i]);
|
V test = getMap().get(sampleKeys[i]);
|
||||||
if (value == test || value != null && value.equals(test)) {
|
if (value == test || value != null && value.equals(test)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
|
Set<Map.Entry<K, V>> entrySet = getMap().entrySet();
|
||||||
HashSet<Map.Entry<K, V>> comparisonSet = new HashSet<Map.Entry<K, V>>(entrySet);
|
HashSet<Map.Entry<K, V>> comparisonSet = new HashSet<Map.Entry<K, V>>(entrySet);
|
||||||
try {
|
try {
|
||||||
assertFalse(entrySet.retainAll(comparisonSet));
|
assertFalse(entrySet.retainAll(comparisonSet));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertEquals(sampleKeys.length, getMap().size());
|
assertEquals(sampleKeys.length, getMap().size());
|
||||||
try {
|
try {
|
||||||
assertTrue(entrySet.retainAll(Collections.<Map.Entry<K, V>> emptySet()));
|
assertTrue(entrySet.retainAll(Collections.<Map.Entry<K, V>> emptySet()));
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertTrue(getMap().isEmpty());
|
assertTrue(getMap().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1479,13 +1479,13 @@ public abstract class AbstractTestMap<K, V> extends AbstractTestObject {
|
||||||
public void testEntrySetIteratorRemoveChangesMap() {
|
public void testEntrySetIteratorRemoveChangesMap() {
|
||||||
resetFull();
|
resetFull();
|
||||||
for (Iterator<Map.Entry<K, V>> iter = getMap().entrySet().iterator(); iter.hasNext();) {
|
for (Iterator<Map.Entry<K, V>> iter = getMap().entrySet().iterator(); iter.hasNext();) {
|
||||||
K key = iter.next().getKey();
|
K key = iter.next().getKey();
|
||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assertFalse(getMap().containsKey(key));
|
assertFalse(getMap().containsKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue