You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2002/12/08 16:29:59 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections CollectionUtils.java
scolebourne 2002/12/08 07:29:59
Modified: collections/src/java/org/apache/commons/collections
CollectionUtils.java
Log:
Add new countMatches method
Revision Changes Path
1.22 +23 -4 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.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- CollectionUtils.java 24 Nov 2002 21:11:27 -0000 1.21
+++ CollectionUtils.java 8 Dec 2002 15:29:59 -0000 1.22
@@ -426,8 +426,24 @@
}
/**
+ * Counts the number of elements in the input collection that match the predicate.
+ * <p>
+ * A <code>null</code> predicate matches no elements.
+ *
+ * @param inputCollection the collection to get the input from, may not be null
+ * @param predicate the predicate to use, may be null
+ * @return the number of matches for the predicate in the collection
+ * @throws NullPointerException if the input collection is null
+ */
+ public static int countMatches(Collection inputCollection, Predicate predicate) {
+ return select(inputCollection, predicate).size();
+ }
+
+ /**
* Selects all elements from input collection which match the given predicate
* into an output collection.
+ * <p>
+ * A <code>null</code> predicate matches no elements.
*
* @param inputCollection the collection to get the input from, may not be null
* @param predicate the predicate to use, may be null
@@ -467,6 +483,8 @@
/**
* Selects all elements from inputCollection which don't match the given predicate
* into an output collection
+ * <p>
+ * A <code>null</code> predicate matches no elements.
*
* @param inputCollection the collection to get the input from, may not be null
* @param predicate the predicate to use, may be null
@@ -499,6 +517,7 @@
}
}
}
+
/**
* Transforms all elements from inputCollection with the given transformer
* and adds them to the outputCollection.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>