garydgregory commented on a change in pull request #91: Add drain method to
CollectionUtils
URL: https://github.com/apache/commons-collections/pull/91#discussion_r338850496
##########
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) {
Review comment:
This seems wrong, collections are addressed starting at index 0. I should be
able to call this method and have it remove all elements in one go by passing
in a start of 0 and a count equal to the collection size.
----------------------------------------------------------------
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