FluentIterator implements ImmutableIterator<T> { public boolean weakEquals(Iterator<T> s, int n) { return Iterators.weakEquals(this, s, n); } FluentIterator(Iterator<T> t); static FluentIterator<T> fluent(Iterator<T> t); @Override boolean hasNext(); @Override T next(); boolean weakEquals(Iterator<T> s, int n); @SuppressWarnings("unchecked") FluentIterator<T> filter(Predicate<? super T> p); boolean any(Predicate<? super T> p); boolean all(Predicate<? super T> p); @SuppressWarnings("unchecked") FluentIterator<T> concat(Iterator... ts); FluentIterator<T> peek(Consumer<? super T> cs); List<T> take(int n); List<T> takeAll(); FluentIterator<T> limit(int n); List<FluentIterator<T>> tee(int n); FluentIterator<Pair<T, S>> zip(Iterator<S> s, boolean weak); FluentIterator<List<T>> groupBy(Function<T, K> key); FluentIterator<List<T>> groupBy(); FluentIterator<T> skipDuplicates(Function<T, K> key); FluentIterator<T> skipDuplicates(); FluentIterator<T> keepFirst(Function<? super T, ? extends K> key); FluentIterator<T> keepLast(Function<? super T, ? extends K> key); FluentIterator<V> map(Function<T, V> f); FluentIterator<T> map(Iterator<T> t, BinaryOperator<T> f); T reduce(BinaryOperator<T> f); V reduce(BiFunction<V, T, V> f, V start);  }
@Test public void testWeakEquals() { FluentIterator<Integer> ta = fluent(of(10, 20, 30)); FluentIterator<Integer> tb = fluent(of(10, 20, 30)); assertTrue(ta.weakEquals(tb, 2)); ta = fluent(of(10, 20, 30)); tb = fluent(of(10, 20, 30)); assertTrue(ta.weakEquals(tb, 3)); ta = fluent(of(10, 20, 30)); tb = fluent(of(10, 20, 30)); assertTrue(ta.weakEquals(tb, 4)); tb = fluent(of(10, 20, 30)); Iterator<Integer> tc = of(10, 20, 30, 40); assertTrue(tb.weakEquals(tc, 3)); assertFalse(tb.weakEquals(tc, 4)); Iterator<Integer> tg = of(10, null, null); FluentIterator<Integer> te = fluent(empty()); Iterator<Integer> tf = empty(); assertTrue(te.weakEquals(tf, 3)); te = fluent(empty()); assertTrue(te.weakEquals(te, 4)); FluentIterator<Integer> td = fluent(of(10, null, null)); assertTrue(weakEquals(td, tg, 3)); td = fluent(of(10, 20, 30, 40)); tf = of(10, null, null); assertFalse(td.weakEquals(tf, 4)); }