MCPcopy Create free account
hub / github.com/antlr/codebuff / tryFind

Method tryFind

corpus/java/training/guava/collect/Iterators.java:707–710  ·  view source on GitHub ↗

Returns an Optional containing the first element in iterator that satisfies the given predicate, if such an element exists. If no such element is found, an empty Optional will be returned from this method and the iterator will be left exhausted: its hasNext() method w

(Iterator<T> iterator, Predicate<? super T> predicate)

Source from the content-addressed store, hash-verified

705 * @since 11.0
706 */
707 public static <T> Optional<T> tryFind(Iterator<T> iterator, Predicate<? super T> predicate) {
708 UnmodifiableIterator<T> filteredIterator = filter(iterator, predicate);
709 return filteredIterator.hasNext() ? Optional.of(filteredIterator.next()) : Optional.<T>absent();
710 }
711
712 /**
713 * Returns the index in {@code iterator} of the first element that satisfies

Callers 1

tryFindMethod · 0.95

Calls 5

filterMethod · 0.95
ofMethod · 0.95
absentMethod · 0.95
nextMethod · 0.65
hasNextMethod · 0.45

Tested by

no test coverage detected