diff --git a/src/main/java/org/apache/commons/collections4/FluentIterable.java b/src/main/java/org/apache/commons/collections4/FluentIterable.java index 503a4e0a7..2b4a545f2 100644 --- a/src/main/java/org/apache/commons/collections4/FluentIterable.java +++ b/src/main/java/org/apache/commons/collections4/FluentIterable.java @@ -148,7 +148,7 @@ public class FluentIterable implements Iterable { * @param other the other iterable to combine, may be null * @return a new iterable, combining this iterable with other */ - public FluentIterable append(final Iterable other) { + public FluentIterable append(final Iterable other) { return of(IterableUtils.chainedIterable(iterable, other)); } @@ -171,7 +171,7 @@ public class FluentIterable implements Iterable { * @return a new iterable, collating this iterable with the other in natural order * @see {@link org.apache.commons.collections4.iterators.CollatingIterator CollatingIterator} */ - public FluentIterable collate(final Iterable other) { + public FluentIterable collate(final Iterable other) { return of(IterableUtils.collatedIterable(iterable, other, null)); } @@ -197,7 +197,8 @@ public class FluentIterable implements Iterable { * @return a new iterable, collating this iterable with the other in natural order * @see {@link org.apache.commons.collections4.iterators.CollatingIterator CollatingIterator} */ - public FluentIterable collate(final Iterable other, Comparator comparator) { + public FluentIterable collate(final Iterable other, + final Comparator comparator) { return of(IterableUtils.collatedIterable(iterable, other, comparator)); } @@ -226,7 +227,7 @@ public class FluentIterable implements Iterable { * @return a new iterable, providing a filtered view of this iterable * @throws NullPointerException if predicate is null */ - public FluentIterable filter(final Predicate predicate) { + public FluentIterable filter(final Predicate predicate) { return of(IterableUtils.filteredIterable(iterable, predicate)); } @@ -300,26 +301,25 @@ public class FluentIterable implements Iterable { /** * 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 zip(final E... elements) { - return zip(Arrays.asList(elements)); + public FluentIterable zip(final Iterable 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 zip(final Iterable... others) { + public FluentIterable zip(final Iterable... others) { @SuppressWarnings("unchecked") Iterable[] iterables = new Iterable[1 + others.length]; iterables[0] = iterable; diff --git a/src/main/java/org/apache/commons/collections4/IterableUtils.java b/src/main/java/org/apache/commons/collections4/IterableUtils.java index 66ac47c2f..fd4edfba8 100644 --- a/src/main/java/org/apache/commons/collections4/IterableUtils.java +++ b/src/main/java/org/apache/commons/collections4/IterableUtils.java @@ -53,7 +53,8 @@ public class IterableUtils { * @return a new iterable, combining the provided iterables */ @SuppressWarnings("unchecked") - public static Iterable chainedIterable(final Iterable a, final Iterable b) { + public static Iterable chainedIterable(final Iterable a, + final Iterable 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 Iterable collatedIterable(final Iterable a, - final Iterable b, + public static Iterable collatedIterable(final Iterable a, + final Iterable b, final Comparator comparator) { return new FluentIterable() { @Override @@ -395,7 +396,8 @@ public class IterableUtils { * @return a new iterable, interleaving the provided iterables */ @SuppressWarnings("unchecked") - public static Iterable zippingIterable(final Iterable a, final Iterable b) { + public static Iterable zippingIterable(final Iterable a, + final Iterable 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 Iterable zippingIterable(final Iterable... iterables) { + public static Iterable zippingIterable(final Iterable... iterables) { return new FluentIterable() { @Override public Iterator iterator() { @SuppressWarnings("unchecked") - Iterator[] iterators = new Iterator[iterables.length]; + Iterator[] iterators = new Iterator[iterables.length]; for (int i = 0; i < iterables.length; i++) { iterators[i] = emptyIteratorIfNull(iterables[i]); }