commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1648910 - in /commons/proper/collections/trunk/src: main/java/org/apache/commons/collections4/CollectionUtils.java test/java/org/apache/commons/collections4/CollectionUtilsTest.java
Date Thu, 01 Jan 2015 17:26:55 GMT
Author: tn
Date: Thu Jan  1 17:26:55 2015
New Revision: 1648910

URL: http://svn.apache.org/r1648910
Log:
Avoid generic return parameter, specify the actual interface being used to avoid compilation
problems.

Modified:
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java?rev=1648910&r1=1648909&r2=1648910&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java
(original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java
Thu Jan  1 17:26:55 2015
@@ -995,9 +995,9 @@ public class CollectionUtils {
      * Partitions all elements from inputCollection into separate output collections,
      * based on the evaluation of the given predicate.
      * <p>
-     * For each predicate, the returned list will contain a collection holding
-     * all elements of the input collection matching the predicate. The last collection
-     * contained in the list will hold all elements which didn't match any predicate:
+     * For each predicate, the result will contain a list holding all elements of the
+     * input collection matching the predicate. The last list will hold all elements
+     * which didn't match any predicate:
      * <pre>
      *  [C1, R] = partition(I, P1) with
      *  I = input collection
@@ -1014,17 +1014,16 @@ public class CollectionUtils {
      * will result in the following output: [[1, 2], [3, 4, 5]].
      *
      * @param <O>  the type of object the {@link Iterable} contains
-     * @param <R>  the type of the output {@link Collection}
      * @param inputCollection  the collection to get the input from, may be null
      * @param predicate  the predicate to use, may be null
      * @return a list containing the output collections
      * @since 4.1
      */
-    public static <O, R extends Collection<O>> List<R> partition(final
Iterable<? extends O> inputCollection,
+    public static <O> List<List<O>> partition(final Iterable<? extends
O> inputCollection,
             final Predicate<? super O> predicate) {
 
-        @SuppressWarnings("unchecked") // safe
-        final Factory<R> factory = (Factory<R>) FactoryUtils.instantiateFactory(ArrayList.class);
+        @SuppressWarnings({ "unchecked", "rawtypes" }) // safe
+        final Factory<List<O>> factory = FactoryUtils.instantiateFactory((Class)
ArrayList.class);
         @SuppressWarnings("unchecked") // safe
         final Predicate<? super O>[] predicates = new Predicate[] { predicate };
         return partition(inputCollection, factory, predicates);
@@ -1074,9 +1073,9 @@ public class CollectionUtils {
      * Partitions all elements from inputCollection into separate output collections,
      * based on the evaluation of the given predicates.
      * <p>
-     * For each predicate, the returned list will contain a collection holding
-     * all elements of the input collection matching the predicate. The last collection
-     * contained in the list will hold all elements which didn't match any predicate:
+     * For each predicate, the result will contain a list holding all elements of the
+     * input collection matching the predicate. The last list will hold all elements
+     * which didn't match any predicate:
      * <pre>
      *  [C1, C2, R] = partition(I, P1, P2) with
      *  I = input collection
@@ -1098,17 +1097,16 @@ public class CollectionUtils {
      * and [x &lt; 5] will result in the following output: [[1, 2], [3, 4], [5]].
      *
      * @param <O>  the type of object the {@link Iterable} contains
-     * @param <R>  the type of the output {@link Collection}
      * @param inputCollection  the collection to get the input from, may be null
      * @param predicates  the predicates to use, may be null
      * @return a list containing the output collections
      * @since 4.1
      */
-    public static <O, R extends Collection<O>> List<R> partition(final
Iterable<? extends O> inputCollection,
+    public static <O> List<List<O>> partition(final Iterable<? extends
O> inputCollection,
             final Predicate<? super O>... predicates) {
 
-        @SuppressWarnings("unchecked") // safe
-        final Factory<R> factory = (Factory<R>) FactoryUtils.instantiateFactory(ArrayList.class);
+        @SuppressWarnings({ "unchecked", "rawtypes" }) // safe
+        final Factory<List<O>> factory = FactoryUtils.instantiateFactory((Class)
ArrayList.class);
         return partition(inputCollection, factory, predicates);
     }
 

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java?rev=1648910&r1=1648909&r2=1648910&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java
Thu Jan  1 17:26:55 2015
@@ -1185,6 +1185,7 @@ public class CollectionUtilsTest extends
         assertTrue(output1.contains(4L));
     }
 
+    @SuppressWarnings("unchecked")
     @Test
     public void partition() {
         List<Integer> input = new ArrayList<Integer>();
@@ -1192,7 +1193,7 @@ public class CollectionUtilsTest extends
         input.add(2);
         input.add(3);
         input.add(4);
-        List<Collection<Integer>> partitions = CollectionUtils.partition(input,
EQUALS_TWO);
+        List<List<Integer>> partitions = CollectionUtils.partition(input, EQUALS_TWO);
         assertEquals(2, partitions.size());
         
         // first partition contains 2
@@ -1248,7 +1249,8 @@ public class CollectionUtilsTest extends
         input.add(2);
         input.add(3);
         input.add(4);
-        List<Collection<Integer>> partitions = CollectionUtils.partition(input,
EQUALS_TWO, EVEN);
+        @SuppressWarnings("unchecked")
+        List<List<Integer>> partitions = CollectionUtils.partition(input, EQUALS_TWO,
EVEN);
 
         // first partition contains 2
         Collection<Integer> partition = partitions.get(0);



Mime
View raw message