garydgregory commented on a change in pull request #91: Add drain method to
CollectionUtils
URL: https://github.com/apache/commons-collections/pull/91#discussion_r338850120
##########
File path: src/main/java/org/apache/commons/collections4/CollectionUtils.java
##########
@@ -909,6 +909,46 @@ public int hashCode() {
return predicate != null && IterableUtils.matchesAll(input, predicate);
}
+ /**
+ * Removes the specified number of elements from the specified location in
the collection and returns them.
+ * This method would have the side-effect of modifying the input
collections.
+ *
+ * @param <E> the type of object the {@link Collection} contains
+ * @param input the collection will be operated,can't be null
+ * @param start the specified position to remove element,can't be less
than 1
+ * @param count the specified number to remove,can't be less than 1
+ * @return collection of elements that removed from the input collection
+ */
+ public static <E> Collection<E> drain(Collection<E> input, int start, int
count) {
+ if (null == input) {
+ throw new IllegalArgumentException("The collection
can't be null.");
+ }
+ if (start < 1) {
+ throw new IllegalArgumentException("The Start can't
less than 1.");
+ }
+ if (count < 1) {
Review comment:
A count of 0 seems like it should be legal input, ending up removing nothing.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services