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/31 21:31:16 UTC
svn commit: r1682776 - in
/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4:
FluentIterable.java IterableUtils.java
Author: tn
Date: Sun May 31 19:31:15 2015
New Revision: 1682776
URL: http://svn.apache.org/r1682776
Log:
Make FluentIterable method covariant.
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java?rev=1682776&r1=1682775&r2=1682776&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/FluentIterable.java Sun May 31 19:31:15 2015
@@ -148,7 +148,7 @@ public class FluentIterable<E> implement
* @param other the other iterable to combine, may be null
* @return a new iterable, combining this iterable with other
*/
- public FluentIterable<E> append(final Iterable<E> other) {
+ public FluentIterable<E> append(final Iterable<? extends E> other) {
return of(IterableUtils.chainedIterable(iterable, other));
}
@@ -171,7 +171,7 @@ public class FluentIterable<E> implement
* @return a new iterable, collating this iterable with the other in natural order
* @see {@link org.apache.commons.collections4.iterators.CollatingIterator CollatingIterator}
*/
- public FluentIterable<E> collate(final Iterable<E> other) {
+ public FluentIterable<E> collate(final Iterable<? extends E> other) {
return of(IterableUtils.collatedIterable(iterable, other, null));
}
@@ -197,7 +197,8 @@ public class FluentIterable<E> implement
* @return a new iterable, collating this iterable with the other in natural order
* @see {@link org.apache.commons.collections4.iterators.CollatingIterator CollatingIterator}
*/
- public FluentIterable<E> collate(final Iterable<E> other, Comparator<? super E> comparator) {
+ public FluentIterable<E> collate(final Iterable<? extends E> other,
+ final Comparator<? super E> comparator) {
return of(IterableUtils.collatedIterable(iterable, other, comparator));
}
@@ -226,7 +227,7 @@ public class FluentIterable<E> implement
* @return a new iterable, providing a filtered view of this iterable
* @throws NullPointerException if predicate is null
*/
- public FluentIterable<E> filter(final Predicate<E> predicate) {
+ public FluentIterable<E> filter(final Predicate<? super E> predicate) {
return of(IterableUtils.filteredIterable(iterable, predicate));
}
@@ -300,26 +301,25 @@ public class FluentIterable<E> implement
/**
* Returns a new FluentIterable whose iterator will traverse
- * the elements of this iterable and the provided elements in
+ * the elements of this iterable and the other iterable in
* alternating order.
*
- * @param elements the elements to interleave
- * @return a new iterable, interleaving this iterable with the elements
+ * @param other the other iterable to interleave
+ * @return a new iterable, interleaving this iterable with others
*/
- @SuppressWarnings("unchecked")
- public FluentIterable<E> zip(final E... elements) {
- return zip(Arrays.asList(elements));
+ public FluentIterable<E> zip(final Iterable<? extends E> other) {
+ return of(IterableUtils.zippingIterable(iterable, other));
}
/**
* Returns a new FluentIterable whose iterator will traverse
- * the elements of this iterable and the other iterable in
+ * the elements of this iterable and the other iterables in
* alternating order.
*
* @param others the iterables to interleave
* @return a new iterable, interleaving this iterable with others
*/
- public FluentIterable<E> zip(final Iterable<E>... others) {
+ public FluentIterable<E> zip(final Iterable<? extends E>... others) {
@SuppressWarnings("unchecked")
Iterable<E>[] iterables = new Iterable[1 + others.length];
iterables[0] = iterable;
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java?rev=1682776&r1=1682775&r2=1682776&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/IterableUtils.java Sun May 31 19:31:15 2015
@@ -53,7 +53,8 @@ public class IterableUtils {
* @return a new iterable, combining the provided iterables
*/
@SuppressWarnings("unchecked")
- public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a, final Iterable<? extends E> b) {
+ public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a,
+ final Iterable<? extends E> b) {
return chainedIterable(new Iterable[] {a, b});
}
@@ -155,8 +156,8 @@ public class IterableUtils {
* may be null, in which case natural ordering will be used
* @return a filtered view on the specified iterable
*/
- public static <E> Iterable<E> collatedIterable(final Iterable<E> a,
- final Iterable<E> b,
+ public static <E> Iterable<E> collatedIterable(final Iterable<? extends E> a,
+ final Iterable<? extends E> b,
final Comparator<? super E> comparator) {
return new FluentIterable<E>() {
@Override
@@ -395,7 +396,8 @@ public class IterableUtils {
* @return a new iterable, interleaving the provided iterables
*/
@SuppressWarnings("unchecked")
- public static <E> Iterable<E> zippingIterable(final Iterable<E> a, final Iterable<E> b) {
+ public static <E> Iterable<E> zippingIterable(final Iterable<? extends E> a,
+ final Iterable<? extends E> b) {
return zippingIterable(new Iterable[] {a, b});
}
@@ -413,12 +415,12 @@ public class IterableUtils {
* @param iterables the array of iterables to interleave
* @return a new iterable, interleaving the provided iterables
*/
- public static <E> Iterable<E> zippingIterable(final Iterable<E>... iterables) {
+ public static <E> Iterable<E> zippingIterable(final Iterable<? extends E>... iterables) {
return new FluentIterable<E>() {
@Override
public Iterator<E> iterator() {
@SuppressWarnings("unchecked")
- Iterator<E>[] iterators = new Iterator[iterables.length];
+ Iterator<? extends E>[] iterators = new Iterator[iterables.length];
for (int i = 0; i < iterables.length; i++) {
iterators[i] = emptyIteratorIfNull(iterables[i]);
}