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:
parent
b3fd256017
commit
8b04e57194
|
@ -148,7 +148,7 @@ public class FluentIterable<E> implements Iterable<E> {
|
||||||
* @param other the other iterable to combine, may be null
|
* @param other the other iterable to combine, may be null
|
||||||
* @return a new iterable, combining this iterable with other
|
* @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));
|
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
|
* @return a new iterable, collating this iterable with the other in natural order
|
||||||
* @see {@link org.apache.commons.collections4.iterators.CollatingIterator CollatingIterator}
|
* @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));
|
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
|
* @return a new iterable, collating this iterable with the other in natural order
|
||||||
* @see {@link org.apache.commons.collections4.iterators.CollatingIterator CollatingIterator}
|
* @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));
|
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
|
* @return a new iterable, providing a filtered view of this iterable
|
||||||
* @throws NullPointerException if predicate is null
|
* @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));
|
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
|
* 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.
|
* alternating order.
|
||||||
*
|
*
|
||||||
* @param elements the elements to interleave
|
* @param other the other iterable to interleave
|
||||||
* @return a new iterable, interleaving this iterable with the elements
|
* @return a new iterable, interleaving this iterable with others
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public FluentIterable<E> zip(final Iterable<? extends E> other) {
|
||||||
public FluentIterable<E> zip(final E... elements) {
|
return of(IterableUtils.zippingIterable(iterable, other));
|
||||||
return zip(Arrays.asList(elements));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new FluentIterable whose iterator will traverse
|
* 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.
|
* alternating order.
|
||||||
*
|
*
|
||||||
* @param others the iterables to interleave
|
* @param others the iterables to interleave
|
||||||
* @return a new iterable, interleaving this iterable with others
|
* @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")
|
@SuppressWarnings("unchecked")
|
||||||
Iterable<E>[] iterables = new Iterable[1 + others.length];
|
Iterable<E>[] iterables = new Iterable[1 + others.length];
|
||||||
iterables[0] = iterable;
|
iterables[0] = iterable;
|
||||||
|
|
|
@ -53,7 +53,8 @@ public class IterableUtils {
|
||||||
* @return a new iterable, combining the provided iterables
|
* @return a new iterable, combining the provided iterables
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@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});
|
return chainedIterable(new Iterable[] {a, b});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,8 +156,8 @@ public class IterableUtils {
|
||||||
* may be null, in which case natural ordering will be used
|
* may be null, in which case natural ordering will be used
|
||||||
* @return a filtered view on the specified iterable
|
* @return a filtered view on the specified iterable
|
||||||
*/
|
*/
|
||||||
public static <E> Iterable<E> collatedIterable(final Iterable<E> a,
|
public static <E> Iterable<E> collatedIterable(final Iterable<? extends E> a,
|
||||||
final Iterable<E> b,
|
final Iterable<? extends E> b,
|
||||||
final Comparator<? super E> comparator) {
|
final Comparator<? super E> comparator) {
|
||||||
return new FluentIterable<E>() {
|
return new FluentIterable<E>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -395,7 +396,8 @@ public class IterableUtils {
|
||||||
* @return a new iterable, interleaving the provided iterables
|
* @return a new iterable, interleaving the provided iterables
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@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});
|
return zippingIterable(new Iterable[] {a, b});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,12 +415,12 @@ public class IterableUtils {
|
||||||
* @param iterables the array of iterables to interleave
|
* @param iterables the array of iterables to interleave
|
||||||
* @return a new iterable, interleaving the provided iterables
|
* @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>() {
|
return new FluentIterable<E>() {
|
||||||
@Override
|
@Override
|
||||||
public Iterator<E> iterator() {
|
public Iterator<E> iterator() {
|
||||||
@SuppressWarnings("unchecked")
|
@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++) {
|
for (int i = 0; i < iterables.length; i++) {
|
||||||
iterators[i] = emptyIteratorIfNull(iterables[i]);
|
iterators[i] = emptyIteratorIfNull(iterables[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue