Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 20019 invoked from network); 15 Sep 2009 05:55:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Sep 2009 05:55:41 -0000 Received: (qmail 4371 invoked by uid 500); 15 Sep 2009 05:55:40 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 4259 invoked by uid 500); 15 Sep 2009 05:55:39 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 4214 invoked by uid 99); 15 Sep 2009 05:55:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Sep 2009 05:55:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Sep 2009 05:55:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0A9BA2388A21; Tue, 15 Sep 2009 05:54:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r815039 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/collection/TransformedCollection.java Date: Tue, 15 Sep 2009 05:54:49 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090915055450.0A9BA2388A21@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bayard Date: Tue Sep 15 05:54:49 2009 New Revision: 815039 URL: http://svn.apache.org/viewvc?rev=815039&view=rev Log: Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956. Also see the following revisions: ------------------------------------------------------------------------ r555925 | skestle | 2007-07-13 03:39:24 -0700 (Fri, 13 Jul 2007) | 2 lines Added Edwin Tellman's patch for COLLECTIONS-243. It all seems pretty reasonable, and it should all be checked again as the project is worked through ------------------------------------------------------------------------ r471575 | scolebourne | 2006-11-05 15:58:08 -0800 (Sun, 05 Nov 2006) | 1 line Generify and remove AbstractSerializableCollectionDecorator ------------------------------------------------------------------------ r471202 | scolebourne | 2006-11-04 06:21:44 -0800 (Sat, 04 Nov 2006) | 1 line Remove getCollection() - use covariant decorated() ------------------------------------------------------------------------ Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/collection/TransformedCollection.java Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/collection/TransformedCollection.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/collection/TransformedCollection.java?rev=815039&r1=815038&r2=815039&view=diff ============================================================================== --- commons/proper/collections/trunk/src/java/org/apache/commons/collections/collection/TransformedCollection.java (original) +++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/collection/TransformedCollection.java Tue Sep 15 05:54:49 2009 @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import org.apache.commons.collections.Transformer; @@ -33,18 +32,19 @@ *

* This class is Serializable from Commons Collections 3.1. * + * @param the type of the elements in the collection * @since Commons Collections 3.0 * @version $Revision$ $Date$ * * @author Stephen Colebourne */ -public class TransformedCollection extends AbstractSerializableCollectionDecorator { +public class TransformedCollection extends AbstractCollectionDecorator { /** Serialization version */ private static final long serialVersionUID = 8692300188161871514L; /** The transformer to use */ - protected final Transformer transformer; + protected final Transformer transformer; /** * Factory method to create a transforming collection. @@ -58,10 +58,10 @@ * @return a new transformed collection * @throws IllegalArgumentException if collection or transformer is null */ - public static Collection decorate(Collection coll, Transformer transformer) { - return new TransformedCollection(coll, transformer); + public static Collection decorate(Collection coll, Transformer transformer) { + return new TransformedCollection(coll, transformer); } - + /** * Factory method to create a transforming collection that will transform * existing contents of the specified collection. @@ -76,13 +76,14 @@ * @throws IllegalArgumentException if collection or transformer is null * @since Commons Collections 3.3 */ + // TODO: Generics public static Collection decorateTransform(Collection collection, Transformer transformer) { TransformedCollection decorated = new TransformedCollection(collection, transformer); if (transformer != null && collection != null && collection.size() > 0) { Object[] values = collection.toArray(); collection.clear(); for(int i=0; i coll, Transformer transformer) { super(coll); if (transformer == null) { throw new IllegalArgumentException("Transformer must not be null"); @@ -115,7 +116,7 @@ * @param object the object to transform * @return a transformed object */ - protected Object transform(Object object) { + protected E transform(E object) { return transformer.transform(object); } @@ -127,23 +128,21 @@ * @param coll the collection to transform * @return a transformed object */ - protected Collection transform(Collection coll) { - List list = new ArrayList(coll.size()); - for (Iterator it = coll.iterator(); it.hasNext(); ) { - list.add(transform(it.next())); + protected Collection transform(Collection coll) { + List list = new ArrayList(coll.size()); + for (E item : coll) { + list.add(transform(item)); } return list; } //----------------------------------------------------------------------- - public boolean add(Object object) { - object = transform(object); - return getCollection().add(object); + public boolean add(E object) { + return decorated().add(transform(object)); } - public boolean addAll(Collection coll) { - coll = transform(coll); - return getCollection().addAll(coll); + public boolean addAll(Collection coll) { + return decorated().addAll(transform(coll)); } }