commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chen (Jira)" <j...@apache.org>
Subject [jira] [Comment Edited] (COLLECTIONS-674) Add Collections Drain Method
Date Wed, 23 Oct 2019 07:30:00 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-674?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16938352#comment-16938352
] 

Chen edited comment on COLLECTIONS-674 at 10/23/19 7:29 AM:
------------------------------------------------------------

I will push a PR for it.


was (Author: guoping1):
{code:java}
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 < 0) {
			throw new IllegalArgumentException("The Start can't less than 0.");
		}
		if (count < 1) {
			throw new IllegalArgumentException("The Count can't less than 1.");
		}
		if (input.size() < start + count) {
			throw new IllegalArgumentException(
					"The sum of start and count cann't be greater than the size of collection.");
		}

		Collection<E> result = new ArrayList<E>(count);
		Iterator<E> iterator = input.iterator();
		while (count > 0) {
			result.add(iterator.next());
			iterator.remove();
			count = count - 1;
		}
		return result;
	}
{code}


> Add Collections Drain Method
> ----------------------------
>
>                 Key: COLLECTIONS-674
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-674
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Collection
>    Affects Versions: 4.1
>            Reporter: David Mollitor
>            Priority: Major
>
> Add a {{Collections.drain()}} method which removes the first N elements from the collection
and returns them.  This method would have the side-effect of modifying the input collections
(due to removal).
>  
> {code:java}
> // Some suggestions
> void Collections.drain(Collection<T> from, Collection<T> to, int count);
> Collection<t> Collections.drain(Collection<t> from, int count);{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message