Author: tn Date: Tue Dec 30 18:24:14 2014 New Revision: 1648561 URL: http://svn.apache.org/r1648561 Log: [COLLECTIONS-537] Harmonized signature of functor-related factory methods: collection and array based methods did not have the same generic bounds. Thanks to Frank Jakop.
Modified: commons/proper/collections/trunk/src/changes/changes.xml commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/ClosureUtils.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/PredicateUtils.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/TransformerUtils.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AnyPredicate.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/OnePredicate.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=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/changes/changes.xml (original) +++ commons/proper/collections/trunk/src/changes/changes.xml Tue Dec 30 18:24:14 2014 @@ -22,6 +22,10 @@ <body> <release version="4.1" date="TBD" description=""> + <action issue="COLLECTIONS-537" dev="tn" type="fix" due-to="Frank Jakop"> + Harmonized signature of factory methods for functor-related classes which take + a collection as input with their array counterparts. + </action> <action issue="COLLECTIONS-540" dev="tn" type="fix" due-to="Daniel Stewart, Issam El Atif"> Added overloaded method "CollectionUtils#get(Enumeration, int)" and simplified code for "CollectionUtils#get(Object, int)". Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/ClosureUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/ClosureUtils.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/ClosureUtils.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/ClosureUtils.java Tue Dec 30 18:24:14 2014 @@ -216,7 +216,7 @@ public class ClosureUtils { * @throws IllegalArgumentException if the closures collection is empty * @throws IllegalArgumentException if any closure in the collection is null */ - public static <E> Closure<E> chainedClosure(final Collection<Closure<E>> closures) { + public static <E> Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures) { return ChainedClosure.chainedClosure(closures); } Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/PredicateUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/PredicateUtils.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/PredicateUtils.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/PredicateUtils.java Tue Dec 30 18:24:14 2014 @@ -286,7 +286,7 @@ public class PredicateUtils { * @throws IllegalArgumentException if any predicate in the collection is null * @see org.apache.commons.collections4.functors.AllPredicate */ - public static <T> Predicate<T> allPredicate(final Collection<? extends Predicate<T>> predicates) { + public static <T> Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates) { return AllPredicate.allPredicate(predicates); } @@ -334,7 +334,7 @@ public class PredicateUtils { * @throws IllegalArgumentException if any predicate in the collection is null * @see org.apache.commons.collections4.functors.AnyPredicate */ - public static <T> Predicate<T> anyPredicate(final Collection<? extends Predicate<T>> predicates) { + public static <T> Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates) { return AnyPredicate.anyPredicate(predicates); } @@ -384,7 +384,7 @@ public class PredicateUtils { * @throws IllegalArgumentException if any predicate in the collection is null * @see org.apache.commons.collections4.functors.OnePredicate */ - public static <T> Predicate<T> onePredicate(final Collection<Predicate<T>> predicates) { + public static <T> Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates) { return OnePredicate.onePredicate(predicates); } @@ -434,7 +434,7 @@ public class PredicateUtils { * @throws IllegalArgumentException if any predicate in the collection is null * @see org.apache.commons.collections4.functors.NonePredicate */ - public static <T> Predicate<T> nonePredicate(final Collection<? extends Predicate<T>> predicates) { + public static <T> Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates) { return NonePredicate.nonePredicate(predicates); } Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/TransformerUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/TransformerUtils.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/TransformerUtils.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/TransformerUtils.java Tue Dec 30 18:24:14 2014 @@ -208,7 +208,7 @@ public class TransformerUtils { * @see org.apache.commons.collections4.functors.ChainedTransformer */ public static <T> Transformer<T, T> chainedTransformer( - final Collection<? extends Transformer<T, T>> transformers) { + final Collection<? extends Transformer<? super T, ? extends T>> transformers) { return ChainedTransformer.chainedTransformer(transformers); } Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AllPredicate.java Tue Dec 30 18:24:14 2014 @@ -76,13 +76,13 @@ public final class AllPredicate<T> exten * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static <T> Predicate<T> allPredicate(final Collection<? extends Predicate<T>> predicates) { - final Predicate<T>[] preds = validate(predicates); + public static <T> Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates) { + final Predicate<? super T>[] preds = validate(predicates); if (preds.length == 0) { return truePredicate(); } if (preds.length == 1) { - return preds[0]; + return coerce(preds[0]); } return new AllPredicate<T>(preds); } Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AnyPredicate.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AnyPredicate.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AnyPredicate.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/AnyPredicate.java Tue Dec 30 18:24:14 2014 @@ -73,7 +73,7 @@ public final class AnyPredicate<T> exten * @throws IllegalArgumentException if any predicate in the array is null */ @SuppressWarnings("unchecked") - public static <T> Predicate<T> anyPredicate(final Collection<? extends Predicate<T>> predicates) { + public static <T> Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates) { final Predicate<? super T>[] preds = FunctorUtils.validate(predicates); if (preds.length == 0) { return FalsePredicate.<T>falsePredicate(); Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java Tue Dec 30 18:24:14 2014 @@ -64,7 +64,7 @@ public class ChainedClosure<E> implement * @throws IllegalArgumentException if any closure in the collection is null */ @SuppressWarnings("unchecked") - public static <E> Closure<E> chainedClosure(final Collection<Closure<E>> closures) { + public static <E> Closure<E> chainedClosure(final Collection<? extends Closure<? super E>> closures) { if (closures == null) { throw new IllegalArgumentException("Closure collection must not be null"); } Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java Tue Dec 30 18:24:14 2014 @@ -67,7 +67,8 @@ public class ChainedTransformer<T> imple * @throws IllegalArgumentException if any transformer in the collection is null */ @SuppressWarnings("unchecked") - public static <T> Transformer<T, T> chainedTransformer(final Collection<? extends Transformer<T, T>> transformers) { + public static <T> Transformer<T, T> chainedTransformer( + final Collection<? extends Transformer<? super T, ? extends T>> transformers) { if (transformers == null) { throw new IllegalArgumentException("Transformer collection must not be null"); } Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/FunctorUtils.java Tue Dec 30 18:24:14 2014 @@ -66,7 +66,7 @@ class FunctorUtils { * @return the coerced predicate. */ @SuppressWarnings("unchecked") - static <T> Predicate<T> coerce(final Predicate<? super T> predicate){ + static <T> Predicate<T> coerce(final Predicate<? super T> predicate) { return (Predicate<T>) predicate; } @@ -93,15 +93,15 @@ class FunctorUtils { * @param predicates the predicates to validate * @return predicate array */ - static <T> Predicate<T>[] validate(final Collection<? extends Predicate<T>> predicates) { + static <T> Predicate<? super T>[] validate(final Collection<? extends Predicate<? super T>> predicates) { if (predicates == null) { throw new IllegalArgumentException("The predicate collection must not be null"); } // convert to array like this to guarantee iterator() ordering @SuppressWarnings("unchecked") // OK - final Predicate<T>[] preds = new Predicate[predicates.size()]; + final Predicate<? super T>[] preds = new Predicate[predicates.size()]; int i = 0; - for (final Predicate<T> predicate : predicates) { + for (final Predicate<? super T> predicate : predicates) { preds[i] = predicate; if (preds[i] == null) { throw new IllegalArgumentException( @@ -154,7 +154,7 @@ class FunctorUtils { * @return the coerced closure. */ @SuppressWarnings("unchecked") - static <T> Closure<T> coerce(final Closure<? super T> closure){ + static <T> Closure<T> coerce(final Closure<? super T> closure) { return (Closure<T>) closure; } Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/NonePredicate.java Tue Dec 30 18:24:14 2014 @@ -66,7 +66,7 @@ public final class NonePredicate<T> exte * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static <T> Predicate<T> nonePredicate(final Collection<? extends Predicate<T>> predicates) { + public static <T> Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates) { final Predicate<? super T>[] preds = FunctorUtils.validate(predicates); if (preds.length == 0) { return TruePredicate.<T>truePredicate(); Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java?rev=1648561&r1=1648560&r2=1648561&view=diff ============================================================================== --- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java (original) +++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/functors/OnePredicate.java Tue Dec 30 18:24:14 2014 @@ -69,7 +69,7 @@ public final class OnePredicate<T> exten * @throws IllegalArgumentException if the predicates array is null * @throws IllegalArgumentException if any predicate in the array is null */ - public static <T> Predicate<T> onePredicate(final Collection<? extends Predicate<T>> predicates) { + public static <T> Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates) { final Predicate<? super T>[] preds = FunctorUtils.validate(predicates); return new OnePredicate<T>(preds); }