@Test public void shouldOnlyYieldValuesThatPassAllPredicates() { UnaryFunction<? super String, String> mapper = Mappers.<String>identity(); Iterable<String> iterable = listWith("no", "nope", "no way", "nem", "you betcha"); Predicate<String> containsO = new Predicate<String>() { public boolean evaluate(String item) { return item.contains("o"); } }; Predicate<String> containsE = new Predicate<String>() { public boolean evaluate(String item) { return item.contains("e"); } }; Predicate<String> containsY = new Predicate<String>() { public boolean evaluate(String item) { return item.contains("y"); } }; ComprehensionIterator<String, String> iterator = new ComprehensionIterator<String, String>( mapper, iterable.iterator(), listWith(containsO, containsE, containsY)); assertThat(iterator.findNext(), is("you betcha")); }
@Override protected T findNext() { while (iterator.hasNext()) { final S next = iterator.next(); Boolean passesAllPredicates = Eagerly.all( predicates, new UnaryPredicate<UnaryPredicate<? super S>>() { @Override public boolean evaluate(UnaryPredicate<? super S> predicate) { return predicate.evaluate(next); } }); if (passesAllPredicates) { return mapper.call(next); } } throw new NoSuchElementException(); }
ComprehensionIterator extends CachingIterator<T> { @Override protected T findNext() { while (iterator.hasNext()) { final S next = iterator.next(); Boolean passesAllPredicates = Eagerly.all( predicates, new UnaryPredicate<UnaryPredicate<? super S>>() { @Override public boolean evaluate(UnaryPredicate<? super S> predicate) { return predicate.evaluate(next); } }); if (passesAllPredicates) { return mapper.call(next); } } throw new NoSuchElementException(); } }
ComprehensionIterator extends CachingIterator<T> { @Override protected T findNext() { while (iterator.hasNext()) { final S next = iterator.next(); Boolean passesAllPredicates = Eagerly.all( predicates, new UnaryPredicate<UnaryPredicate<? super S>>() { @Override public boolean evaluate(UnaryPredicate<? super S> predicate) { return predicate.evaluate(next); } }); if (passesAllPredicates) { return mapper.call(next); } } throw new NoSuchElementException(); } ComprehensionIterator(
            UnaryFunction<? super S, T> mapper,
            Iterator<S> iterator,
            Iterable<? extends UnaryPredicate<? super S>> predicates); }
ComprehensionIterator extends CachingIterator<T> { @Override protected T findNext() { while (iterator.hasNext()) { final S next = iterator.next(); Boolean passesAllPredicates = Eagerly.all( predicates, new UnaryPredicate<UnaryPredicate<? super S>>() { @Override public boolean evaluate(UnaryPredicate<? super S> predicate) { return predicate.evaluate(next); } }); if (passesAllPredicates) { return mapper.call(next); } } throw new NoSuchElementException(); } ComprehensionIterator(
            UnaryFunction<? super S, T> mapper,
            Iterator<S> iterator,
            Iterable<? extends UnaryPredicate<? super S>> predicates); @Override String toString(); }
ComprehensionIterator extends CachingIterator<T> { @Override protected T findNext() { while (iterator.hasNext()) { final S next = iterator.next(); Boolean passesAllPredicates = Eagerly.all( predicates, new UnaryPredicate<UnaryPredicate<? super S>>() { @Override public boolean evaluate(UnaryPredicate<? super S> predicate) { return predicate.evaluate(next); } }); if (passesAllPredicates) { return mapper.call(next); } } throw new NoSuchElementException(); } ComprehensionIterator(
            UnaryFunction<? super S, T> mapper,
            Iterator<S> iterator,
            Iterable<? extends UnaryPredicate<? super S>> predicates); @Override String toString();  }