Make FluentIterable method covariant.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1682776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2015-05-31 19:31:15 +00:00
parent b3fd256017
commit 8b04e57194
2 changed files with 20 additions and 18 deletions

View File

@ -148,7 +148,7 @@ public class FluentIterable<E> implements Iterable<E> {
* @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> implements Iterable<E> {
* @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> implements Iterable<E> {
* @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> implements Iterable<E> {
* @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> implements Iterable<E> {
/**
* 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;

View File

@ -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]);
}