Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 25632 invoked from network); 15 Sep 2009 05:56:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Sep 2009 05:56:25 -0000 Received: (qmail 20075 invoked by uid 500); 15 Sep 2009 05:56:24 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 19959 invoked by uid 500); 15 Sep 2009 05:56:24 -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 19918 invoked by uid 99); 15 Sep 2009 05:56:24 -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:56:24 +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:56:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 18C9B2388A19; Tue, 15 Sep 2009 05:55:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r815069 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/ListUtils.java Date: Tue, 15 Sep 2009 05:55:50 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090915055550.18C9B2388A19@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bayard Date: Tue Sep 15 05:55:49 2009 New Revision: 815069 URL: http://svn.apache.org/viewvc?rev=815069&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 ------------------------------------------------------------------------ r471166 | scolebourne | 2006-11-04 03:33:22 -0800 (Sat, 04 Nov 2006) | 1 line Removed Typed* containers such as TypedList and TypedMap as generics now provides type safety ------------------------------------------------------------------------ Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/ListUtils.java Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/ListUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/ListUtils.java?rev=815069&r1=815068&r2=815069&view=diff ============================================================================== --- commons/proper/collections/trunk/src/java/org/apache/commons/collections/ListUtils.java (original) +++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/ListUtils.java Tue Sep 15 05:55:49 2009 @@ -27,7 +27,6 @@ import org.apache.commons.collections.list.PredicatedList; import org.apache.commons.collections.list.SynchronizedList; import org.apache.commons.collections.list.TransformedList; -import org.apache.commons.collections.list.TypedList; import org.apache.commons.collections.list.UnmodifiableList; /** @@ -51,8 +50,8 @@ * This uses the {@link Collections Collections} implementation * and is provided for completeness. */ - public static final List EMPTY_LIST = Collections.EMPTY_LIST; - + public static final List EMPTY_LIST = Collections.emptyList(); + /** * ListUtils should not normally be instantiated. */ @@ -69,18 +68,14 @@ * @return the intersection of those two lists * @throws NullPointerException if either list is null */ - public static List intersection(final List list1, final List list2) { - final ArrayList result = new ArrayList(); - final Iterator iterator = list2.iterator(); - - while (iterator.hasNext()) { - final Object o = iterator.next(); + public static List intersection(final List list1, final List list2) { + final List result = new ArrayList(); - if (list1.contains(o)) { - result.add(o); + for (E e : list2) { + if (list1.contains(e)) { + result.add(e); } } - return result; } @@ -99,14 +94,11 @@ * @return a new list containing the results * @throws NullPointerException if either list is null */ - public static List subtract(final List list1, final List list2) { - final ArrayList result = new ArrayList(list1); - final Iterator iterator = list2.iterator(); - - while (iterator.hasNext()) { - result.remove(iterator.next()); + public static List subtract(final List list1, final List list2) { + final ArrayList result = new ArrayList(list1); + for (E e : list2) { + result.remove(e); } - return result; } @@ -119,7 +111,7 @@ * @return a new list containing the sum of those lists * @throws NullPointerException if either list is null */ - public static List sum(final List list1, final List list2) { + public static List sum(final List list1, final List list2) { return subtract(union(list1, list2), intersection(list1, list2)); } @@ -133,8 +125,8 @@ * @return a new list containing the union of those lists * @throws NullPointerException if either list is null */ - public static List union(final List list1, final List list2) { - final ArrayList result = new ArrayList(list1); + public static List union(final List list1, final List list2) { + final ArrayList result = new ArrayList(list1); result.addAll(list2); return result; } @@ -168,7 +160,7 @@ * @param list2 the second list, may be null * @return whether the lists are equal by value comparison */ - public static boolean isEqualList(final Collection list1, final Collection list2) { + public static boolean isEqualList(final Collection list1, final Collection list2) { if (list1 == list2) { return true; } @@ -176,8 +168,8 @@ return false; } - Iterator it1 = list1.iterator(); - Iterator it2 = list2.iterator(); + Iterator it1 = list1.iterator(); + Iterator it2 = list2.iterator(); Object obj1 = null; Object obj2 = null; @@ -205,16 +197,15 @@ * @param list the list to generate the hashCode for, may be null * @return the hash code */ - public static int hashCodeForList(final Collection list) { + public static int hashCodeForList(final Collection list) { if (list == null) { return 0; } int hashCode = 1; - Iterator it = list.iterator(); - Object obj = null; + Iterator it = list.iterator(); while (it.hasNext()) { - obj = it.next(); + E obj = it.next(); hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode()); } return hashCode; @@ -236,11 +227,10 @@ * @throws NullPointerException if either parameter is null * @since Commons Collections 3.2 */ - public static List retainAll(Collection collection, Collection retain) { - List list = new ArrayList(Math.min(collection.size(), retain.size())); + public static List retainAll(Collection collection, Collection retain) { + List list = new ArrayList(Math.min(collection.size(), retain.size())); - for (Iterator iter = collection.iterator(); iter.hasNext();) { - Object obj = iter.next(); + for (E obj : collection) { if (retain.contains(obj)) { list.add(obj); } @@ -264,11 +254,10 @@ * @throws NullPointerException if either parameter is null * @since Commons Collections 3.2 */ - public static List removeAll(Collection collection, Collection remove) { - List list = new ArrayList(); - for (Iterator iter = collection.iterator(); iter.hasNext();) { - Object obj = iter.next(); - if (remove.contains(obj) == false) { + public static List removeAll(Collection collection, Collection remove) { + List list = new ArrayList(); + for (E obj : collection) { + if (!remove.contains(obj)) { list.add(obj); } } @@ -298,7 +287,7 @@ * @return a synchronized list backed by the given list * @throws IllegalArgumentException if the list is null */ - public static List synchronizedList(List list) { + public static List synchronizedList(List list) { return SynchronizedList.decorate(list); } @@ -311,7 +300,7 @@ * @return an unmodifiable list backed by the given list * @throws IllegalArgumentException if the list is null */ - public static List unmodifiableList(List list) { + public static List unmodifiableList(List list) { return UnmodifiableList.decorate(list); } @@ -328,24 +317,11 @@ * @return a predicated list backed by the given list * @throws IllegalArgumentException if the List or Predicate is null */ - public static List predicatedList(List list, Predicate predicate) { + public static List predicatedList(List list, Predicate predicate) { return PredicatedList.decorate(list, predicate); } /** - * Returns a typed list backed by the given list. - *

- * Only objects of the specified type can be added to the list. - * - * @param list the list to limit to a specific type, must not be null - * @param type the type of objects which may be added to the list - * @return a typed list backed by the specified list - */ - public static List typedList(List list, Class type) { - return TypedList.decorate(list, type); - } - - /** * Returns a transformed list backed by the given list. *

* This method returns a new list (decorating the specified list) that @@ -364,7 +340,7 @@ * @return a transformed list backed by the given list * @throws IllegalArgumentException if the List or Transformer is null */ - public static List transformedList(List list, Transformer transformer) { + public static List transformedList(List list, Transformer transformer) { return TransformedList.decorate(list, transformer); } @@ -397,7 +373,7 @@ * @return a lazy list backed by the given list * @throws IllegalArgumentException if the List or Factory is null */ - public static List lazyList(List list, Factory factory) { + public static List lazyList(List list, Factory factory) { return LazyList.decorate(list, factory); } @@ -411,7 +387,7 @@ * @return a fixed-size list backed by that list * @throws IllegalArgumentException if the List is null */ - public static List fixedSizeList(List list) { + public static List fixedSizeList(List list) { return FixedSizeList.decorate(list); }