scolebourne 2003/01/19 17:29:30
Modified: collections/src/java/org/apache/commons/collections
CollectionUtils.java
Log:
Improve speed of countMatches()
from Peter KoBek
Revision Changes Path
1.26 +14 -5
jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java
Index: CollectionUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- CollectionUtils.java 11 Jan 2003 01:07:13 -0000 1.25
+++ CollectionUtils.java 20 Jan 2003 01:29:30 -0000 1.26
@@ -33,7 +33,7 @@
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
+ * permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -84,7 +84,7 @@
* @author Stephen Colebourne
* @author Steve Downey
* @author <a href="[EMAIL PROTECTED]">Herve Quiroz</a>
- * @author [EMAIL PROTECTED] (Peter)
+ * @author Peter KoBek
*/
public class CollectionUtils {
@@ -443,7 +443,16 @@
* @throws NullPointerException if the input collection is null
*/
public static int countMatches(Collection inputCollection, Predicate predicate)
{
- return select(inputCollection, predicate).size();
+ int count = 0;
+ if (inputCollection != null && predicate != null) {
+ for (Iterator it = inputCollection.iterator(); it.hasNext();) {
+ Object item = it.next();
+ if (predicate.evaluate(item)) {
+ count++;
+ }
+ }
+ }
+ return count;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>