You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Colebourne <sc...@btopenworld.com> on 2006/07/03 15:18:22 UTC

[collections] New methods

Some possible new methods for [collections]

ListUtils.trimSize(List list, int size)
- trims list size to size if too large
 
ListUtils.forceSize(List list, int size)
- trims list size to size if too large
- adds extra nulls to the list if its too small

ListUtils.copy(List,Object[])
- copy a collection into an array

ListUtils.merge(List list, List defaultValues)
- replace any null values in list with the matching index in defaultValues

Opinions? Volunteers to code them?!!!

Stephen





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [collections] New methods

Posted by James Carman <ja...@carmanconsulting.com>.
Oh, and if nobody else wants to spend some cycles on this, I could do it.
It shouldn't take too long.

-----Original Message-----
From: James Carman [mailto:james@carmanconsulting.com] 
Sent: Tuesday, July 04, 2006 1:02 PM
To: 'Jakarta Commons Developers List'; 'Stephen Colebourne'
Subject: RE: [collections] New methods

+1 on having three methods trim, grow, and setSize (names TBD, but the
functionality sounds cool to me).  The only issue I might have is that for
the grow method, we might want to create a flavor of it that allows you to
specify what objects to add to the list if it actually does need to grow.
Maybe like this:

grow(List list, int minSize, Object defaultValue);
grow(List list, int minSize, Factory factory);
grow(List list, int minSize) // add nulls



-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Monday, July 03, 2006 12:57 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] New methods

> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

My original proposal was to have one method that trims if too large and
grows if too small.

So, perhaps there are three methods in total - trim, grow, forceSize

Stephen


----- Original Message ----
From: James Carman <ja...@carmanconsulting.com>
You can't do a resize method because the code won't know which way you want
to go with it.  For instance, if you ask it to resize(list, 10) and the list
has 20 elements in it, does that mean that you want it to trim it back so
that it only contains 10 elements?  Or, does that mean that it's okay,
because it already has at least 10 elements in it?  So, I'm cool with having
two methods here.  One for shrinking and one for growing (if necessary).

+1 on not needing the ListUtils.copy() method, since the core API provides
it.

+1 on the obscurity of the merge() method.  That doesn't sound like a common
enough requirement to be on commons collections.

-----Original Message-----
From: Henri Yandell [mailto:flamefew@gmail.com] 
Sent: Monday, July 03, 2006 12:13 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] New methods

On 7/3/06, Stephen Colebourne <sc...@btopenworld.com> wrote:
> Some possible new methods for [collections]
>
> ListUtils.trimSize(List list, int size)
> - trims list size to size if too large
>
> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

Would it be bad to just have the one method that both enlarged and
shrunk?  resize(LIst, int) or something?

> ListUtils.copy(List,Object[])
> - copy a collection into an array

java.util.Collection.toArray() ?

> ListUtils.merge(List list, List defaultValues)
> - replace any null values in list with the matching index in defaultValues

Do you think this is something people will need often? Seems likely to
be quite rare.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [collections] New methods

Posted by James Carman <ja...@carmanconsulting.com>.
+1 on having three methods trim, grow, and setSize (names TBD, but the
functionality sounds cool to me).  The only issue I might have is that for
the grow method, we might want to create a flavor of it that allows you to
specify what objects to add to the list if it actually does need to grow.
Maybe like this:

grow(List list, int minSize, Object defaultValue);
grow(List list, int minSize, Factory factory);
grow(List list, int minSize) // add nulls



-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Monday, July 03, 2006 12:57 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] New methods

> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

My original proposal was to have one method that trims if too large and
grows if too small.

So, perhaps there are three methods in total - trim, grow, forceSize

Stephen


----- Original Message ----
From: James Carman <ja...@carmanconsulting.com>
You can't do a resize method because the code won't know which way you want
to go with it.  For instance, if you ask it to resize(list, 10) and the list
has 20 elements in it, does that mean that you want it to trim it back so
that it only contains 10 elements?  Or, does that mean that it's okay,
because it already has at least 10 elements in it?  So, I'm cool with having
two methods here.  One for shrinking and one for growing (if necessary).

+1 on not needing the ListUtils.copy() method, since the core API provides
it.

+1 on the obscurity of the merge() method.  That doesn't sound like a common
enough requirement to be on commons collections.

-----Original Message-----
From: Henri Yandell [mailto:flamefew@gmail.com] 
Sent: Monday, July 03, 2006 12:13 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] New methods

On 7/3/06, Stephen Colebourne <sc...@btopenworld.com> wrote:
> Some possible new methods for [collections]
>
> ListUtils.trimSize(List list, int size)
> - trims list size to size if too large
>
> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

Would it be bad to just have the one method that both enlarged and
shrunk?  resize(LIst, int) or something?

> ListUtils.copy(List,Object[])
> - copy a collection into an array

java.util.Collection.toArray() ?

> ListUtils.merge(List list, List defaultValues)
> - replace any null values in list with the matching index in defaultValues

Do you think this is something people will need often? Seems likely to
be quite rare.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] New methods

Posted by Stephen Colebourne <sc...@btopenworld.com>.
> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

My original proposal was to have one method that trims if too large and grows if too small.

So, perhaps there are three methods in total - trim, grow, forceSize

Stephen


----- Original Message ----
From: James Carman <ja...@carmanconsulting.com>
You can't do a resize method because the code won't know which way you want
to go with it.  For instance, if you ask it to resize(list, 10) and the list
has 20 elements in it, does that mean that you want it to trim it back so
that it only contains 10 elements?  Or, does that mean that it's okay,
because it already has at least 10 elements in it?  So, I'm cool with having
two methods here.  One for shrinking and one for growing (if necessary).

+1 on not needing the ListUtils.copy() method, since the core API provides
it.

+1 on the obscurity of the merge() method.  That doesn't sound like a common
enough requirement to be on commons collections.

-----Original Message-----
From: Henri Yandell [mailto:flamefew@gmail.com] 
Sent: Monday, July 03, 2006 12:13 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] New methods

On 7/3/06, Stephen Colebourne <sc...@btopenworld.com> wrote:
> Some possible new methods for [collections]
>
> ListUtils.trimSize(List list, int size)
> - trims list size to size if too large
>
> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

Would it be bad to just have the one method that both enlarged and
shrunk?  resize(LIst, int) or something?

> ListUtils.copy(List,Object[])
> - copy a collection into an array

java.util.Collection.toArray() ?

> ListUtils.merge(List list, List defaultValues)
> - replace any null values in list with the matching index in defaultValues

Do you think this is something people will need often? Seems likely to
be quite rare.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [collections] New methods

Posted by James Carman <ja...@carmanconsulting.com>.
You can't do a resize method because the code won't know which way you want
to go with it.  For instance, if you ask it to resize(list, 10) and the list
has 20 elements in it, does that mean that you want it to trim it back so
that it only contains 10 elements?  Or, does that mean that it's okay,
because it already has at least 10 elements in it?  So, I'm cool with having
two methods here.  One for shrinking and one for growing (if necessary).

+1 on not needing the ListUtils.copy() method, since the core API provides
it.

+1 on the obscurity of the merge() method.  That doesn't sound like a common
enough requirement to be on commons collections.

-----Original Message-----
From: Henri Yandell [mailto:flamefew@gmail.com] 
Sent: Monday, July 03, 2006 12:13 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] New methods

On 7/3/06, Stephen Colebourne <sc...@btopenworld.com> wrote:
> Some possible new methods for [collections]
>
> ListUtils.trimSize(List list, int size)
> - trims list size to size if too large
>
> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

Would it be bad to just have the one method that both enlarged and
shrunk?  resize(LIst, int) or something?

> ListUtils.copy(List,Object[])
> - copy a collection into an array

java.util.Collection.toArray() ?

> ListUtils.merge(List list, List defaultValues)
> - replace any null values in list with the matching index in defaultValues

Do you think this is something people will need often? Seems likely to
be quite rare.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] New methods

Posted by Henri Yandell <fl...@gmail.com>.
On 7/3/06, Stephen Colebourne <sc...@btopenworld.com> wrote:
> Some possible new methods for [collections]
>
> ListUtils.trimSize(List list, int size)
> - trims list size to size if too large
>
> ListUtils.forceSize(List list, int size)
> - trims list size to size if too large
> - adds extra nulls to the list if its too small

Would it be bad to just have the one method that both enlarged and
shrunk?  resize(LIst, int) or something?

> ListUtils.copy(List,Object[])
> - copy a collection into an array

java.util.Collection.toArray() ?

> ListUtils.merge(List list, List defaultValues)
> - replace any null values in list with the matching index in defaultValues

Do you think this is something people will need often? Seems likely to
be quite rare.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org