Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 17344 invoked from network); 2 Dec 2004 00:31:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Dec 2004 00:31:40 -0000 Received: (qmail 93785 invoked by uid 500); 2 Dec 2004 00:31:33 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 93765 invoked by uid 500); 2 Dec 2004 00:31:33 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 93751 invoked by uid 99); 2 Dec 2004 00:31:33 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of r.u.c.afonso@uol.com.br designates 200.221.4.110 as permitted sender) Received: from relay3.uol.com.br (HELO relay3.uol.com.br) (200.221.4.110) by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 01 Dec 2004 16:31:31 -0800 Received: from uol.com.br (unknown [172.26.5.166]) by shark3.mail.sys.intranet (Postfix) with ESMTP id 69E2EB679 for ; Wed, 1 Dec 2004 22:31:27 -0200 (BRST) Date: Wed, 1 Dec 2004 22:34:05 -0200 Message-Id: Subject: Re: [Collections] deep cloning MIME-Version: 1.0 X-Sensitivity: 3 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable From: "Rafael U. C. Afonso" To: "commons-user" X-XaM3-API-Version: 4.1 (B79) X-type: 0 X-SenderIP: 200.162.210.223 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hello: It could be done simply using InvokerTransformer (http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/or= g/apache/commons/collections/functors/InvokerTransformer.html) and CollectionUtils.collect() (http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/or= g/apache/commons/collections/CollectionUtils.html#collect(java.util.Colle= ction,%20org.apache.commons.collections.Transformer)): Collection clonedCollection =3D CollectionUtils.collect(originalCollection, new InvokerTransformer.getInstance("clone")); Thanks, ---------- In=EDcio da mensagem original ----------- De: "Edgar Poce" epoce@fibertel.com.ar Para: "Jakarta Commons Users List" commons-user@jakarta.apache.org 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 =3D new ArrayList(); > Iterator iter =3D collection.iterator() ; > while (iter.hasNext()) { > Object o =3D (Object) iter.next() ; > try { > Method method =3D o.getClass().getDeclaredMethod("clone", > new Class[]{}); > Object clone =3D method.invoke(o, new Object[]{} ); > retu.add(clone); > } catch (Exception e) { > throw new CloneNotSupportedException("Unable to clone > element " + o + ". Exception=3D" + e.getClass().getName() + ". Message=3D " > + 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: commons-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-user-help@jakarta.apache.org > > Rafael Ubiratam Clemente Afonso r.u.c.afonso@uol.com.br --------------------------------- Where is Debug? Debug is on the Table!=0A =0A____________________________________________= ______________________________=0AAcabe com aquelas janelinhas que pulam n= a sua tela.=0AAntiPop-up UOL - =C9 gr=E1tis!=0Ahttp://antipopup.uol.com.b= r/=0A --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org