Returns a view of unfiltered containing all elements that satisfy the input predicate retainIfTrue.
(final Iterator<T> unfiltered, final Predicate<? super T> retainIfTrue)
| 641 | |
| 642 | |
| 643 | public static <T> UnmodifiableIterator<T> filter(final Iterator<T> unfiltered, final Predicate<? super T> retainIfTrue) { |
| 644 | checkNotNull(unfiltered); |
| 645 | checkNotNull(retainIfTrue); |
| 646 | return new AbstractIterator<T>() { |
| 647 | @Override |
| 648 | protected T computeNext() { |
| 649 | while (unfiltered.hasNext()) { |
| 650 | T element = unfiltered.next(); |
| 651 | if (retainIfTrue.apply(element)) { |
| 652 | return element; |
| 653 | } |
| 654 | } |
| 655 | return endOfData(); |
| 656 | } |
| 657 | }; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * Returns a view of {@code unfiltered} containing all elements that are of |
no test coverage detected