diff --git a/RELEASE-NOTES.html b/RELEASE-NOTES.html index 2f9c74f7f..645b52368 100644 --- a/RELEASE-NOTES.html +++ b/RELEASE-NOTES.html @@ -56,6 +56,7 @@ If this causes major headaches to anyone please contact commons-dev at jakarta.a
Collection
containing all the elements of collection
except
* any elements that also occur in remove
.
* @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);
}
//-----------------------------------------------------------------------
diff --git a/src/test/org/apache/commons/collections/TestCollectionUtils.java b/src/test/org/apache/commons/collections/TestCollectionUtils.java
index e3a2d6f7c..d74bce6f8 100644
--- a/src/test/org/apache/commons/collections/TestCollectionUtils.java
+++ b/src/test/org/apache/commons/collections/TestCollectionUtils.java
@@ -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);
diff --git a/src/test/org/apache/commons/collections/TestListUtils.java b/src/test/org/apache/commons/collections/TestListUtils.java
index 2d0d16b5a..69abaea8d 100644
--- a/src/test/org/apache/commons/collections/TestListUtils.java
+++ b/src/test/org/apache/commons/collections/TestListUtils.java
@@ -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
}