You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Carman <ja...@carmanconsulting.com> on 2006/02/01 03:59:33 UTC

RE: [collections] New utility methods for CollectionUtils & ListUtils

1.  +1 on not using Commons Lang as a dependency.

2.  I would agree that this is a bit specialized.  I'm -0 on including it.

3.  The removeNulls() method could be interesting, but I would not limit it
to lists.  You could use CollectionUtils.filter() and an "isNotNull"
predicate.

-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Tuesday, January 31, 2006 4:35 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] New utility methods for CollectionUtils &
ListUtils

Matt Blum wrote:
> The proposed CollectionUtils method is currently called cloneCollection,
but
> could be called deepClone.  It takes any Collection as a parameter, and
> attempts to create a clone of it and every object contained within it.  It
> tries a couple of different processes to do this, starting with using
> reflection to find the objects' clone method; if they don't have such a
> method but are Serializable, it uses Commons Lang SerializationUtils'
clone
> method to clone them.  If it can't do that, either, it will just copy by
> reference.  It will recursively iterate through any sub-Collections as
well,
> meaning that circular references will cause it to generate a stack
> overflow.  I've found it to be very useful.

This could be useful, but would need to be done without a dependency on 
commons-lang. Practically, it could just be the application of a 
Transformer to each element in the collection resulting in a new collection.


> The main proposed ListUtils method is simply called move, and takes a
List,
> an index, and a distance as parameters.  It will move the element in the
> List at the specified index the specified distance, which can either be
> positive or negative.  It will wrap around, so that, in a List of length
> three (say), moving an element a distance of -2 would have the same effect
> as moving it 1.  It will throw IndexOutOfBoundsException, as you'd expect,
> if the specified index is out of range.

This seems a little specialised, although I'm open to other views.

> I have another proposed ListUtils method, called removeNulls, which as
you'd
> expect simply removes nulls from a list.

I have coded this before and it is useful.


If you would like to write a patch, perhaps for the null remove first, 
then follow http://jakarta.apache.org/commons/patches.html
creating a bugzilla request prefixed by [collections]

Stephen

---------------------------------------------------------------------
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