Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 30712 invoked from network); 15 Sep 2009 05:57:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Sep 2009 05:57:13 -0000 Received: (qmail 35156 invoked by uid 500); 15 Sep 2009 05:57:13 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 35080 invoked by uid 500); 15 Sep 2009 05:57:13 -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 35071 invoked by uid 99); 15 Sep 2009 05:57:13 -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:57:13 +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:57:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EBDB923889EC; Tue, 15 Sep 2009 05:56:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r815104 - /commons/proper/collections/trunk/src/java/org/apache/commons/collections/SetUtils.java Date: Tue, 15 Sep 2009 05:56:47 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090915055647.EBDB923889EC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bayard Date: Tue Sep 15 05:56:47 2009 New Revision: 815104 URL: http://svn.apache.org/viewvc?rev=815104&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/SetUtils.java Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/SetUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/SetUtils.java?rev=815104&r1=815103&r2=815104&view=diff ============================================================================== --- commons/proper/collections/trunk/src/java/org/apache/commons/collections/SetUtils.java (original) +++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/SetUtils.java Tue Sep 15 05:56:47 2009 @@ -18,7 +18,6 @@ import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -30,8 +29,6 @@ import org.apache.commons.collections.set.SynchronizedSortedSet; import org.apache.commons.collections.set.TransformedSet; import org.apache.commons.collections.set.TransformedSortedSet; -import org.apache.commons.collections.set.TypedSet; -import org.apache.commons.collections.set.TypedSortedSet; import org.apache.commons.collections.set.UnmodifiableSet; import org.apache.commons.collections.set.UnmodifiableSortedSet; @@ -54,12 +51,32 @@ * This uses the {@link Collections} implementation * and is provided for completeness. */ - public static final Set EMPTY_SET = Collections.EMPTY_SET; + public static final Set EMPTY_SET = Collections.EMPTY_SET; + + /** + * Get a typed empty unmodifiable Set. + * @param + * @return Set + */ + public static Set emptySet() { + return Collections.emptySet(); + } + /** * An empty unmodifiable sorted set. * This is not provided in the JDK. */ - public static final SortedSet EMPTY_SORTED_SET = UnmodifiableSortedSet.decorate(new TreeSet()); + public static final SortedSet EMPTY_SORTED_SET = UnmodifiableSortedSet.decorate(new TreeSet()); + + /** + * Get a typed empty unmodifiable sorted set. + * @param + * @return SortedSet + */ + @SuppressWarnings("unchecked") + public static SortedSet emptySortedSet() { + return (SortedSet) EMPTY_SORTED_SET; + } /** * SetUtils should not normally be instantiated. @@ -96,7 +113,7 @@ * @param set2 the second set, may be null * @return whether the sets are equal by value comparison */ - public static boolean isEqualSet(final Collection set1, final Collection set2) { + public static boolean isEqualSet(final Collection set1, final Collection set2) { if (set1 == set2) { return true; } @@ -119,16 +136,13 @@ * @param set the set to calculate the hash code for, may be null * @return the hash code */ - public static int hashCodeForSet(final Collection set) { + public static int hashCodeForSet(final Collection set) { if (set == null) { return 0; } - int hashCode = 0; - Iterator it = set.iterator(); - Object obj = null; - while (it.hasNext()) { - obj = it.next(); + int hashCode = 0; + for (T obj : set) { if (obj != null) { hashCode += obj.hashCode(); } @@ -159,7 +173,7 @@ * @return a synchronized set backed by the given set * @throws IllegalArgumentException if the set is null */ - public static Set synchronizedSet(Set set) { + public static Set synchronizedSet(Set set) { return SynchronizedSet.decorate(set); } @@ -172,7 +186,7 @@ * @return an unmodifiable set backed by the given set * @throws IllegalArgumentException if the set is null */ - public static Set unmodifiableSet(Set set) { + public static Set unmodifiableSet(Set set) { return UnmodifiableSet.decorate(set); } @@ -189,24 +203,11 @@ * @return a predicated set backed by the given set * @throws IllegalArgumentException if the Set or Predicate is null */ - public static Set predicatedSet(Set set, Predicate predicate) { + public static Set predicatedSet(Set set, Predicate predicate) { return PredicatedSet.decorate(set, predicate); } /** - * Returns a typed set backed by the given set. - *

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

* Each object is passed through the transformer as it is added to the @@ -221,7 +222,7 @@ * @return a transformed set backed by the given set * @throws IllegalArgumentException if the Set or Transformer is null */ - public static Set transformedSet(Set set, Transformer transformer) { + public static Set transformedSet(Set set, Transformer transformer) { return TransformedSet.decorate(set, transformer); } @@ -236,7 +237,7 @@ * @return an ordered set backed by the given set * @throws IllegalArgumentException if the Set is null */ - public static Set orderedSet(Set set) { + public static Set orderedSet(Set set) { return ListOrderedSet.decorate(set); } @@ -263,7 +264,7 @@ * @return a synchronized set backed by the given set * @throws IllegalArgumentException if the set is null */ - public static SortedSet synchronizedSortedSet(SortedSet set) { + public static SortedSet synchronizedSortedSet(SortedSet set) { return SynchronizedSortedSet.decorate(set); } @@ -276,7 +277,7 @@ * @return an unmodifiable set backed by the given set * @throws IllegalArgumentException if the set is null */ - public static SortedSet unmodifiableSortedSet(SortedSet set) { + public static SortedSet unmodifiableSortedSet(SortedSet set) { return UnmodifiableSortedSet.decorate(set); } @@ -293,24 +294,11 @@ * @return a predicated sorted set backed by the given sorted set * @throws IllegalArgumentException if the Set or Predicate is null */ - public static SortedSet predicatedSortedSet(SortedSet set, Predicate predicate) { + public static SortedSet predicatedSortedSet(SortedSet set, Predicate predicate) { return PredicatedSortedSet.decorate(set, predicate); } /** - * Returns a typed sorted set backed by the given set. - *

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

* Each object is passed through the transformer as it is added to the @@ -325,7 +313,7 @@ * @return a transformed set backed by the given set * @throws IllegalArgumentException if the Set or Transformer is null */ - public static SortedSet transformedSortedSet(SortedSet set, Transformer transformer) { + public static SortedSet transformedSortedSet(SortedSet set, Transformer transformer) { return TransformedSortedSet.decorate(set, transformer); }