commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Blum <mblu...@gmail.com>
Subject [collections] New utility methods for CollectionUtils & ListUtils
Date Sun, 29 Jan 2006 18:23:50 GMT
I'm new to the commons-dev list, but I've participated a bit in the MyFaces
list and, a while ago, in the Struts list.

I have several methods that I think would make good additions to the Commons
Collections CollectionUtils and ListUtils classes, and I wanted to find out:

1. Whether there was interest in them;
2. If so, how I go about submitting a patch.

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.

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.

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

If there's interest, please let me know, and if someone who knows more than
I do about the process could also please let me know what the best way is to
submit a patch.

Thanks!

-Matt

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message