@Override public UnmodifiableIterator<E> iterator() { return Iterators.filter(set1.iterator(), inSet2); }
@Override public UnmodifiableIterator<E> iterator() { return Iterators.filter(set1.iterator(), notInSet2); }
@Override public Iterator<T> iterator() { return Iterators.filter(unfiltered.iterator(), retainIfTrue); }
@Override public Iterator<T> iterator() { return Iterators.filter(unfiltered.iterator(), desiredType); }
@Override public Iterator<E> iterator() { return Iterators.filter(unfiltered.iterator(), predicate); }
@Override Iterator<Entry<K, V>> entryIterator() { return Iterators.filter(unfiltered.entrySet().iterator(), entryPredicate); }
@Override Iterator<Entry<K, V>> descendingEntryIterator() { return Iterators.filter(unfiltered.descendingMap().entrySet().iterator(), entryPredicate); }
/** * Returns the first element in {@code iterator} that satisfies the given * predicate. If no such element is found, {@code defaultValue} will be * returned from this method and the iterator will be left exhausted: its * {@code hasNext()} method will return {@code false}. Note that this can * usually be handled more naturally using {@code * tryFind(iterator, predicate).or(defaultValue)}. * * @since 7.0 */ @Nullable public static <T> T find( Iterator<? extends T> iterator, Predicate<? super T> predicate, @Nullable T defaultValue) { return getNext(filter(iterator, predicate), defaultValue); }
@Override public UnmodifiableIterator<E> iterator() { return Iterators.filter(unfiltered.iterator(), predicate); }
/** * Returns the first element in {@code iterator} that satisfies the given * predicate; use this method only when such an element is known to exist. If * no such element is found, the iterator will be left exhausted: its {@code * hasNext()} method will return {@code false}. If it is possible that * <i>no</i> element will match, use {@link #tryFind} or {@link * #find(Iterator, Predicate, Object)} instead. * * @throws NoSuchElementException if no element in {@code iterator} matches * the given predicate */ public static <T> T find(Iterator<T> iterator, Predicate<? super T> predicate) { return filter(iterator, predicate).next(); }
/** * Returns the number of elements in the specified iterator that equal the * specified object. The iterator will be left exhausted: its * {@code hasNext()} method will return {@code false}. * * @see Collections#frequency */ public static int frequency(Iterator<?> iterator, @Nullable Object element) { return size(filter(iterator, equalTo(element))); }
/** * Returns a view of {@code unfiltered} containing all elements that are of * the type {@code desiredType}. */ @SuppressWarnings("unchecked") // can cast to <T> because non-Ts are removed @GwtIncompatible // Class.isInstance public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) { return (UnmodifiableIterator<T>) filter(unfiltered, instanceOf(desiredType)); }
@Override public Iterator<E> descendingIterator() { return Iterators.filter(unfiltered().descendingIterator(), predicate); }
/** * Returns an {@link Optional} containing the first element in {@code * iterator} that satisfies the given predicate, if such an element exists. If * no such element is found, an empty {@link Optional} will be returned from * this method and the iterator will be left exhausted: its {@code * hasNext()} method will return {@code false}. * * <p><b>Warning:</b> avoid using a {@code predicate} that matches {@code * null}. If {@code null} is matched in {@code iterator}, a * NullPointerException will be thrown. * * @since 11.0 */ public static <T> Optional<T> tryFind(Iterator<T> iterator, Predicate<? super T> predicate) { UnmodifiableIterator<T> filteredIterator = filter(iterator, predicate); return filteredIterator.hasNext() ? Optional.of(filteredIterator.next()) : Optional.<T>absent(); }