Author: scolebourne Date: Wed Aug 2 13:24:02 2006 New Revision: 428130 URL: http://svn.apache.org/viewvc?rev=428130&view=rev Log: COLLECTIONS-219 - CollectionUtils - Fix removeAll() method which was completely broken
Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestListUtils.java Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?rev=428130&r1=428129&r2=428130&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original) +++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Wed Aug 2 13:24:02 2006 @@ -56,6 +56,7 @@ <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> Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java?rev=428130&r1=428129&r2=428130&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java (original) +++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java Wed Aug 2 13:24:02 2006 @@ -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 @@ * @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); } //----------------------------------------------------------------------- Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java?rev=428130&r1=428129&r2=428130&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java Wed Aug 2 13:24:02 2006 @@ -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 @@ 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); Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestListUtils.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestListUtils.java?rev=428130&r1=428129&r2=428130&view=diff ============================================================================== --- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestListUtils.java (original) +++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestListUtils.java Wed Aug 2 13:24:02 2006 @@ -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 @@ 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 @@ 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 } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]