COLLECTIONS-219 - CollectionUtils - Fix removeAll() method which was completely broken

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@428130 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2006-08-02 20:24:02 +00:00
parent 3f09772b74
commit 66c4b99ddc
4 changed files with 72 additions and 9 deletions

View File

@ -56,6 +56,7 @@ If this causes major headaches to anyone please contact commons-dev at jakarta.a
<ul>
<li>Flat3Map - Fix setValue in MapIterator and EntrySetIterator to work correctly [COLLECTIONS-217]</li>
<li>ExtendedProperties - Include property name had confused static/instance semantics [COLLECTIONS-214]</li>
<li>CollectionUtils - Fix removeAll() method which was completely broken [COLLECTIONS-219]</li>
</ul>
<center><h3>JAVADOC</h3></center>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2005 The Apache Software Foundation
* Copyright 2001-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -1115,10 +1115,10 @@ public class CollectionUtils {
* @return a <code>Collection</code> containing all the elements of <code>collection</code> except
* any elements that also occur in <code>remove</code>.
* @throws NullPointerException if either parameter is null
* @since Commons Collections 3.2
* @since Commons Collections 3.3 (method existed in 3.2 but was completely broken)
*/
public static Collection removeAll(Collection collection, Collection remove) {
return ListUtils.retainAll(collection, remove);
return ListUtils.removeAll(collection, remove);
}
//-----------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2005 The Apache Software Foundation
* Copyright 2001-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -1237,8 +1237,70 @@ public class TestCollectionUtils extends TestCase {
assertEquals(eltb,eltc);
assertEquals(eltc,eltb);
}
public void testTransformedCollection() {
//-----------------------------------------------------------------------
public void testRetainAll() {
List base = new ArrayList();
base.add("A");
base.add("B");
base.add("C");
List sub = new ArrayList();
sub.add("A");
sub.add("C");
sub.add("X");
Collection result = CollectionUtils.retainAll(base, sub);
assertEquals(2, result.size());
assertEquals(true, result.contains("A"));
assertEquals(false, result.contains("B"));
assertEquals(true, result.contains("C"));
assertEquals(3, base.size());
assertEquals(true, base.contains("A"));
assertEquals(true, base.contains("B"));
assertEquals(true, base.contains("C"));
assertEquals(3, sub.size());
assertEquals(true, sub.contains("A"));
assertEquals(true, sub.contains("C"));
assertEquals(true, sub.contains("X"));
try {
CollectionUtils.retainAll(null, null);
fail("expecting NullPointerException");
} catch(NullPointerException npe){} // this is what we want
}
public void testRemoveAll() {
List base = new ArrayList();
base.add("A");
base.add("B");
base.add("C");
List sub = new ArrayList();
sub.add("A");
sub.add("C");
sub.add("X");
Collection result = CollectionUtils.removeAll(base, sub);
assertEquals(1, result.size());
assertEquals(false, result.contains("A"));
assertEquals(true, result.contains("B"));
assertEquals(false, result.contains("C"));
assertEquals(3, base.size());
assertEquals(true, base.contains("A"));
assertEquals(true, base.contains("B"));
assertEquals(true, base.contains("C"));
assertEquals(3, sub.size());
assertEquals(true, sub.contains("A"));
assertEquals(true, sub.contains("C"));
assertEquals(true, sub.contains("X"));
try {
CollectionUtils.removeAll(null, null);
fail("expecting NullPointerException");
} catch(NullPointerException npe){} // this is what we want
}
//-----------------------------------------------------------------------
public void testTransformedCollection() {
Transformer transformer = TransformerUtils.nopTransformer();
Collection collection =
CollectionUtils.transformedCollection(new ArrayList(), transformer);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2004 The Apache Software Foundation
* Copyright 2001-2004,2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -150,7 +150,7 @@ public class TestListUtils extends BulkTest {
assertTrue(retained.equals(fullList));
try {
List list = ListUtils.retainAll(null, null);
ListUtils.retainAll(null, null);
fail("expecting NullPointerException");
} catch(NullPointerException npe){} // this is what we want
}
@ -167,7 +167,7 @@ public class TestListUtils extends BulkTest {
assertTrue(remainder.equals(fullList));
try {
List list = ListUtils.removeAll(null, null);
ListUtils.removeAll(null, null);
fail("expecting NullPointerException");
} catch(NullPointerException npe) {} // this is what we want
}