@Override public Iterator<E> iterator() { return iterable.iterator(); }
@Override public Spliterator<E> spliterator() { return iterable.spliterator(); }
@Override public void forEach(Consumer<? super E> action) { iterable.forEach(action); }
@Override public Iterator<E> iterator() { return iterable.iterator(); } };
@Override public void forEach(Consumer<? super T> action) { checkNotNull(action); fromIterable.forEach((F f) -> action.accept(function.apply(f))); }
@SuppressWarnings("unchecked") // safe upcast, assuming no one has a crazy Spliterator subclass @Override public Spliterator<T> spliterator() { return (Spliterator<T>) iterable.spliterator(); }
@Override public Iterator<? extends T> apply(Iterable<? extends T> iterable) { return iterable.iterator(); } };
@Override public void forEach(Consumer<? super T> action) { checkNotNull(action); unfiltered.forEach( (T a) -> { if (retainIfTrue.test(a)) { action.accept(a); } }); }
/** * Returns a sequential {@link Stream} of the contents of {@code iterable}, delegating to {@link * Collection#stream} if possible. */ public static <T> Stream<T> stream(Iterable<T> iterable) { return (iterable instanceof Collection) ? ((Collection<T>) iterable).stream() : StreamSupport.stream(iterable.spliterator(), false); }
/** * Converts an iterable into a collection. If the iterable is already a collection, it is * returned. Otherwise, an {@link java.util.ArrayList} is created with the contents of the * iterable in the same iteration order. */ private static <E> Collection<E> castOrCopyToCollection(Iterable<E> iterable) { return (iterable instanceof Collection) ? (Collection<E>) iterable : Lists.newArrayList(iterable.iterator()); }
static String iterationOrder(Iterable<? extends Node> iterable) { StringBuilder builder = new StringBuilder(); for (Node t : iterable) { builder.append(t.value); } StringBuilder forEachBuilder = new StringBuilder(); iterable.forEach(t -> forEachBuilder.append(t.value)); assertTrue( "Iterator content was " + builder + " but forEach content was " + forEachBuilder, builder.toString().contentEquals(forEachBuilder)); return builder.toString(); }
@Override public Spliterator<T> spliterator() { return CollectSpliterators.map(fromIterable.spliterator(), function); } };
private static boolean isEmpty(Iterable<?> iterable) { return iterable instanceof Collection ? ((Collection<?>) iterable).isEmpty() : !iterable.iterator().hasNext(); }
public void testUnmodifiableIterable_forEach() { List<String> list = newArrayList("a", "b", "c", "d"); Iterable<String> iterable = Iterables.unmodifiableIterable(list); Iterator<String> expectedIterator = list.iterator(); iterable.forEach(s -> assertEquals(expectedIterator.next(), s)); assertFalse(expectedIterator.hasNext()); }
@Override public Spliterator<T> spliterator() { return CollectSpliterators.filter(unfiltered.spliterator(), retainIfTrue); } };
@Override public T next() { if (!iterator.hasNext()) { iterator = iterable.iterator(); if (!iterator.hasNext()) { throw new NoSuchElementException(); } } return iterator.next(); }
@GwtIncompatible // Iterables.filter(Iterable, Class) public void testFilterByType_forEach() throws Exception { HasBoth hasBoth1 = new HasBoth(); HasBoth hasBoth2 = new HasBoth(); Iterable<TypeA> alist = Lists.newArrayList(hasBoth1, new TypeA(), hasBoth2, new TypeA()); Iterable<TypeB> blist = Iterables.filter(alist, TypeB.class); Iterator<TypeB> expectedIterator = Arrays.<TypeB>asList(hasBoth1, hasBoth2).iterator(); blist.forEach(b -> assertThat(b).isEqualTo(expectedIterator.next())); assertThat(expectedIterator.hasNext()).isFalse(); }
@Override protected boolean doEquivalent(Iterable<T> iterableA, Iterable<T> iterableB) { Iterator<T> iteratorA = iterableA.iterator(); Iterator<T> iteratorB = iterableB.iterator(); while (iteratorA.hasNext() && iteratorB.hasNext()) { if (!elementEquivalence.equivalent(iteratorA.next(), iteratorB.next())) { return false; } } return !iteratorA.hasNext() && !iteratorB.hasNext(); }
/** * Collects all remaining objects of this Iterable into a list. * * @return a list with all remaining objects of this Iterable */ @Override public List<E> asList() { return toList(iterable.iterator()); }
@Override public Iterator<Flowable<T>> iterator() { return new ToFlowableIterator<T>(sources.iterator()); } }