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:
parent
3f09772b74
commit
66c4b99ddc
|
@ -56,6 +56,7 @@ If this causes major headaches to anyone please contact commons-dev at jakarta.a
|
||||||
<ul>
|
<ul>
|
||||||
<li>Flat3Map - Fix setValue in MapIterator and EntrySetIterator to work correctly [COLLECTIONS-217]</li>
|
<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>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>
|
</ul>
|
||||||
|
|
||||||
<center><h3>JAVADOC</h3></center>
|
<center><h3>JAVADOC</h3></center>
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* @return a <code>Collection</code> containing all the elements of <code>collection</code> except
|
||||||
* any elements that also occur in <code>remove</code>.
|
* any elements that also occur in <code>remove</code>.
|
||||||
* @throws NullPointerException if either parameter is null
|
* @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) {
|
public static Collection removeAll(Collection collection, Collection remove) {
|
||||||
return ListUtils.retainAll(collection, remove);
|
return ListUtils.removeAll(collection, remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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(eltb,eltc);
|
||||||
assertEquals(eltc,eltb);
|
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();
|
Transformer transformer = TransformerUtils.nopTransformer();
|
||||||
Collection collection =
|
Collection collection =
|
||||||
CollectionUtils.transformedCollection(new ArrayList(), transformer);
|
CollectionUtils.transformedCollection(new ArrayList(), transformer);
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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));
|
assertTrue(retained.equals(fullList));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List list = ListUtils.retainAll(null, null);
|
ListUtils.retainAll(null, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch(NullPointerException npe){} // this is what we want
|
} catch(NullPointerException npe){} // this is what we want
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ public class TestListUtils extends BulkTest {
|
||||||
assertTrue(remainder.equals(fullList));
|
assertTrue(remainder.equals(fullList));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List list = ListUtils.removeAll(null, null);
|
ListUtils.removeAll(null, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch(NullPointerException npe) {} // this is what we want
|
} catch(NullPointerException npe) {} // this is what we want
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue