/** * Combines two iterables into a single iterable. * <p> * The returned iterable has an iterator that traverses the elements in {@code a}, * followed by the elements in {@code b}. The source iterators are not polled until * necessary. * <p> * The returned iterable's iterator supports {@code remove()} when the corresponding * input iterator supports it. * * @param <E> the element type * @param a the first iterable, may not be null * @param b the second iterable, may not be null * @return a new iterable, combining the provided iterables * @throws NullPointerException if either a or b is null */ @SuppressWarnings("unchecked") public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a, final Iterable<? extends E> b) { return chainedIterable(new Iterable[] {a, b}); }
/** * Combines three iterables into a single iterable. * <p> * The returned iterable has an iterator that traverses the elements in {@code a}, * followed by the elements in {@code b} and {@code c}. The source iterators are * not polled until necessary. * <p> * The returned iterable's iterator supports {@code remove()} when the corresponding * input iterator supports it. * * @param <E> the element type * @param a the first iterable, may not be null * @param b the second iterable, may not be null * @param c the third iterable, may not be null * @return a new iterable, combining the provided iterables * @throws NullPointerException if either of the provided iterables is null */ @SuppressWarnings("unchecked") public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a, final Iterable<? extends E> b, final Iterable<? extends E> c) { return chainedIterable(new Iterable[] {a, b, c}); }
/** * Combines four iterables into a single iterable. * <p> * The returned iterable has an iterator that traverses the elements in {@code a}, * followed by the elements in {@code b}, {@code c} and {@code d}. The source * iterators are not polled until necessary. * <p> * The returned iterable's iterator supports {@code remove()} when the corresponding * input iterator supports it. * * @param <E> the element type * @param a the first iterable, may not be null * @param b the second iterable, may not be null * @param c the third iterable, may not be null * @param d the fourth iterable, may not be null * @return a new iterable, combining the provided iterables * @throws NullPointerException if either of the provided iterables is null */ @SuppressWarnings("unchecked") public static <E> Iterable<E> chainedIterable(final Iterable<? extends E> a, final Iterable<? extends E> b, final Iterable<? extends E> c, final Iterable<? extends E> d) { return chainedIterable(new Iterable[] {a, b, c, d}); }
/** * Returns a new FluentIterable whose iterator will first traverse * the elements of the current iterable, followed by the elements * of the provided iterable. * * @param other the other iterable to combine, may not be null * @return a new iterable, combining this iterable with other * @throws NullPointerException if other is null */ public FluentIterable<E> append(final Iterable<? extends E> other) { return of(IterableUtils.chainedIterable(iterable, other)); }