Author: brentworden Date: Fri May 20 16:56:34 2011 New Revision: 1125466 URL: http://svn.apache.org/viewvc?rev=1125466&view=rev Log: [COLLECTIONS-362] changed filter return value to boolean.
Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java?rev=1125466&r1=1125465&r2=1125466&view=diff ============================================================================== --- commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java (original) +++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java Fri May 20 16:56:34 2011 @@ -454,20 +454,24 @@ public class CollectionUtils { * predicate returns false, remove the element. * <p> * If the input collection or predicate is null, there is no change made. - * + * * @param collection * the collection to get the input from, may be null * @param predicate * the predicate to use as a filter, may be null + * @return true if the collection is modified by this call, false otherwise. */ - public static <T> void filter(Iterable<T> collection, Predicate<? super T> predicate) { + public static <T> boolean filter(Iterable<T> collection, Predicate<? super T> predicate) { + boolean result = false; if (collection != null && predicate != null) { for (Iterator<T> it = collection.iterator(); it.hasNext();) { if (!predicate.evaluate(it.next())) { it.remove(); + result = true; } } } + return result; } /** Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java?rev=1125466&r1=1125465&r2=1125466&view=diff ============================================================================== --- commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java (original) +++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java Fri May 20 16:56:34 2011 @@ -20,8 +20,8 @@ import static junit.framework.Assert.ass import static org.apache.commons.collections.functors.EqualPredicate.equalPredicate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.*; @@ -873,7 +873,7 @@ public class TestCollectionUtils extends ints.add(3); ints.add(3); Iterable<Integer> iterable = ints; - CollectionUtils.filter(iterable, EQUALS_TWO); + assertTrue(CollectionUtils.filter(iterable, EQUALS_TWO)); assertEquals(1, (int) ints.size()); assertEquals(2, (int) ints.get(0)); } @@ -881,11 +881,11 @@ public class TestCollectionUtils extends @Test public void filterNullParameters() throws Exception { List<Long> longs = Collections.nCopies(4, 10L); - CollectionUtils.filter(longs, null); + assertFalse(CollectionUtils.filter(longs, null)); assertEquals(4, longs.size()); - CollectionUtils.filter(null, EQUALS_TWO); + assertFalse(CollectionUtils.filter(null, EQUALS_TWO)); assertEquals(4, longs.size()); - CollectionUtils.filter(null, null); + assertFalse(CollectionUtils.filter(null, null)); assertEquals(4, longs.size()); }