[jira] [Comment Edited] (COLLECTIONS-674) Add Collections Drain Method

2019-10-23 Thread Chen (Jira)


[ 
https://issues.apache.org/jira/browse/COLLECTIONS-674?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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  Collection drain(Collection 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 result = new ArrayList(count);
Iterator 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 from, Collection to, int count);
> Collection Collections.drain(Collection from, int count);{code}



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


[jira] [Comment Edited] (COLLECTIONS-674) Add Collections Drain Method

2019-09-26 Thread Chen (Jira)


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

Chen edited comment on COLLECTIONS-674 at 9/26/19 7:06 AM:
---

{code:java}
public static  Collection drain(Collection 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 result = new ArrayList(count);
Iterator iterator = input.iterator();
while (count > 0) {
result.add(iterator.next());
iterator.remove();
count = count - 1;
}
return result;
}
{code}



was (Author: guoping1):

{code:java}
public static  Collection drain(Collection input, int start, int 
count) {
if (null == input) {
throw new IllegalArgumentException("The Collection of 
Input 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 result = new ArrayList(count);
Iterator 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 from, Collection to, int count);
> Collection Collections.drain(Collection from, int count);{code}



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