MCPcopy
hub / github.com/google/guava / filter

Method filter

guava/src/com/google/common/collect/Iterables.java:573–600  ·  view source on GitHub ↗

Returns a view of {@code unfiltered} containing all elements that satisfy the input predicate {@code retainIfTrue}. The returned iterable's iterator does not support {@code remove()}. <p><b>{@code Stream} equivalent:</b> {@link Stream#filter}.

(
      Iterable<T> unfiltered, Predicate<? super T> retainIfTrue)

Source from the content-addressed store, hash-verified

571 * <p><b>{@code Stream} equivalent:</b> {@link Stream#filter}.
572 */
573 public static <T extends @Nullable Object> Iterable<T> filter(
574 Iterable<T> unfiltered, Predicate<? super T> retainIfTrue) {
575 checkNotNull(unfiltered);
576 checkNotNull(retainIfTrue);
577 return new FluentIterable<T>() {
578 @Override
579 public Iterator<T> iterator() {
580 return Iterators.filter(unfiltered.iterator(), retainIfTrue);
581 }
582
583 @Override
584 public void forEach(Consumer<? super T> action) {
585 checkNotNull(action);
586 unfiltered.forEach(
587 (@ParametricNullness T a) -> {
588 if (retainIfTrue.test(a)) {
589 action.accept(a);
590 }
591 });
592 }
593
594 @Override
595 @GwtIncompatible // Spliterator
596 public Spliterator<T> spliterator() {
597 return CollectSpliterators.filter(unfiltered.spliterator(), retainIfTrue);
598 }
599 };
600 }
601
602 /**
603 * Returns a view of {@code unfiltered} containing all elements that are of the type {@code

Callers 5

filterMethod · 0.95
filterUpperBoundsMethod · 0.95
filterMethod · 0.95
MathTestingClass · 0.95
findClassesToTestMethod · 0.95

Calls 2

instanceOfMethod · 0.95
checkNotNullMethod · 0.45

Tested by 2

filterMethod · 0.76
findClassesToTestMethod · 0.76