Hello:
It could be done simply using
InvokerTransformer
(http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache/commons/collections/functors/InvokerTransformer.html)
and CollectionUtils.collect()
(http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache/commons/collections/CollectionUtils.html#collect(java.util.Collection,%20org.apache.commons.collections.Transformer)):
Collection clonedCollection =
CollectionUtils.collect(originalCollection,
new
InvokerTransformer.getInstance("clone"));
Thanks,
---------- In�cio da mensagem original
-----------
De: "Edgar Poce"
[EMAIL PROTECTED]
Para: "Jakarta Commons Users List"
[EMAIL PROTECTED]
Cc:
Data: Wed, 01 Dec 2004 20:35:36 -0300
Assunto: Re: [Collections] deep cloning
> But the goal of the Collections
component is to extend the JDK
> framework, right?.
> I think it would be useful to have a
deepClone utility under
> CollectionUtils.
>
> something like
>
> /**
> * Deep clone.
> * It creates a new Collection wich
contains a clone of
> * each element found in the
original Collection.
> * All the elements in the original
Collection must support
> * clone() method invocation. If
not CloneNotSupportedException
> * is thrown
> *
> * @param collection
> * @return
> * @throws CloneNotSupportedException
> */
> private static Collection
deepClone(Collection collection) throws
> CloneNotSupportedException {
> ArrayList retu = new
ArrayList();
> Iterator iter =
collection.iterator() ;
> while (iter.hasNext()) {
> Object o = (Object)
iter.next() ;
> try {
> Method method =
o.getClass().getDeclaredMethod("clone",
> new Class[]{});
> Object clone =
method.invoke(o, new Object[]{} );
> retu.add(clone);
> } catch (Exception e) {
> throw new
CloneNotSupportedException("Unable to
clone
> element " + o + ". Exception=" +
e.getClass().getName() + ". Message= "
> + e.getMessage() );
> }
> }
> return retu ;
> }
>
> ----- Original Message -----
> From: Stephen Colebourne
> > No, because the JDK collections
API doesn't feature cloning as part
> of > its
> > standard functions.
> >
> > You could try commons-lang
SerializationUtils clone. That will do
> what > you
> > want, just a little slowly.
> >
> > Stephen
> >
> > ----- Original Message -----
> > From: "Edgar Poce"
> > > hi
> > > is there any method in the
package that clones a Collection and
> > > returns a new Collection wich
contains a clone of each element?.
> > >
> > > Thanks in advance
> > > Edgar
> > >
> > >
>---------------------------------------------------------------------
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
[EMAIL PROTECTED]
> For additional commands, e-mail:
[EMAIL PROTECTED]
>
>
Rafael Ubiratam Clemente Afonso
[EMAIL PROTECTED]
---------------------------------
Where is Debug?
Debug is on the Table!
__________________________________________________________________________
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - � gr�tis!
http://antipopup.uol.com.br/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]