You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2015/05/29 12:59:40 UTC

svn commit: r1682416 - in /commons/proper/collections/trunk/src: changes/changes.xml main/java/org/apache/commons/collections4/SetUtils.java test/java/org/apache/commons/collections4/SetUtilsTest.java

Author: tn
Date: Fri May 29 10:59:39 2015
New Revision: 1682416

URL: http://svn.apache.org/r1682416
Log:
Rename SetUtils.identityHashSet to SetUtils.newIdentityHashSet to better reflect that it returns a new instance.

Modified:
    commons/proper/collections/trunk/src/changes/changes.xml
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/SetUtils.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/SetUtilsTest.java

Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1682416&r1=1682415&r2=1682416&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Fri May 29 10:59:39 2015
@@ -34,7 +34,7 @@
       Added new decorator "SkippingIterator" and factory methods "IteratorUtils#skippingIterator(...)".
     </action>
     <action issue="COLLECTIONS-556" dev="tn" type="add">
-      Added method "SetUtils#identityHashSet()" which returns a new identity HashSet
+      Added method "SetUtils#newIdentityHashSet()" which returns a new identity HashSet
       using reference-equality instead of object-equality.
     </action>
     <action issue="COLLECTIONS-562" dev="tn" type="update">

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/SetUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/SetUtils.java?rev=1682416&r1=1682415&r2=1682416&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/SetUtils.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/SetUtils.java Fri May 29 10:59:39 2015
@@ -19,15 +19,19 @@ package org.apache.commons.collections4;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.IdentityHashMap;
+import java.util.NavigableSet;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.commons.collections4.set.ListOrderedSet;
+import org.apache.commons.collections4.set.PredicatedNavigableSet;
 import org.apache.commons.collections4.set.PredicatedSet;
 import org.apache.commons.collections4.set.PredicatedSortedSet;
+import org.apache.commons.collections4.set.TransformedNavigableSet;
 import org.apache.commons.collections4.set.TransformedSet;
 import org.apache.commons.collections4.set.TransformedSortedSet;
+import org.apache.commons.collections4.set.UnmodifiableNavigableSet;
 import org.apache.commons.collections4.set.UnmodifiableSet;
 import org.apache.commons.collections4.set.UnmodifiableSortedSet;
 
@@ -171,10 +175,11 @@ public class SetUtils {
      * @return a new identity hash set
      * @since 4.1
      */
-    public static <E> Set<E> identityHashSet() {
+    public static <E> Set<E> newIdentityHashSet() {
         return Collections.newSetFromMap(new IdentityHashMap<E, Boolean>());
     }
 
+    // Set
     //-----------------------------------------------------------------------
     /**
      * Returns a synchronized set backed by the given set.
@@ -271,6 +276,7 @@ public class SetUtils {
         return ListOrderedSet.listOrderedSet(set);
     }
 
+    // SortedSet
     //-----------------------------------------------------------------------
     /**
      * Returns a synchronized sorted set backed by the given sorted set.
@@ -352,4 +358,62 @@ public class SetUtils {
         return TransformedSortedSet.transformingSortedSet(set, transformer);
     }
 
+    // NavigableSet
+    //-----------------------------------------------------------------------
+    /**
+     * Returns an unmodifiable navigable set backed by the given navigable set.
+     * <p>
+     * This method uses the implementation in the decorators subpackage.
+     *
+     * @param <E> the element type
+     * @param set  the navigable set to make unmodifiable, must not be null
+     * @return an unmodifiable set backed by the given set
+     * @throws IllegalArgumentException  if the set is null
+     * @since 4.1
+     */
+    public static <E> SortedSet<E> unmodifiableNavigableSet(final NavigableSet<E> set) {
+        return UnmodifiableNavigableSet.unmodifiableNavigableSet(set);
+    }
+
+    /**
+     * Returns a predicated (validating) navigable set backed by the given navigable set.
+     * <p>
+     * Only objects that pass the test in the given predicate can be added to the set.
+     * Trying to add an invalid object results in an IllegalArgumentException.
+     * It is important not to use the original set after invoking this method,
+     * as it is a backdoor for adding invalid objects.
+     *
+     * @param <E> the element type
+     * @param set  the navigable set to predicate, must not be null
+     * @param predicate  the predicate for the navigable set, must not be null
+     * @return a predicated navigable set backed by the given navigable set
+     * @throws IllegalArgumentException  if the Set or Predicate is null
+     * @since 4.1
+     */
+    public static <E> SortedSet<E> predicatedNavigableSet(final NavigableSet<E> set, final Predicate<? super E> predicate) {
+        return PredicatedNavigableSet.predicatedNavigableSet(set, predicate);
+    }
+
+    /**
+     * Returns a transformed navigable set backed by the given navigable set.
+     * <p>
+     * Each object is passed through the transformer as it is added to the
+     * Set. It is important not to use the original set after invoking this
+     * method, as it is a backdoor for adding untransformed objects.
+     * <p>
+     * Existing entries in the specified set will not be transformed.
+     * If you want that behaviour, see {@link TransformedNavigableSet#transformedNavigableSet}.
+     *
+     * @param <E> the element type
+     * @param set  the navigable set to transform, must not be null
+     * @param transformer  the transformer for the set, must not be null
+     * @return a transformed set backed by the given set
+     * @throws IllegalArgumentException  if the Set or Transformer is null
+     * @since 4.1
+     */
+    public static <E> SortedSet<E> transformedNavigableSet(final NavigableSet<E> set,
+                                                           final Transformer<? super E, ? extends E> transformer) {
+        return TransformedNavigableSet.transformingNavigableSet(set, transformer);
+    }
+
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/SetUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/SetUtilsTest.java?rev=1682416&r1=1682415&r2=1682416&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/SetUtilsTest.java (original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/SetUtilsTest.java Fri May 29 10:59:39 2015
@@ -102,8 +102,8 @@ public class SetUtilsTest extends BulkTe
         assertEquals(0, SetUtils.hashCodeForSet(null));
     }
 
-    public void testIdentityHashSet() {
-        Set<String> set = SetUtils.identityHashSet();
+    public void testNewIdentityHashSet() {
+        Set<String> set = SetUtils.newIdentityHashSet();
         String a = new String("a");
         set.add(a);
         set.add(new String("b"));