code: public static <T, A, R> Collector<T, ?, R> filtering(final Predicate<? super T> predicate, final Collector<? super T, A, R> downstream) {
          final BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator();
  
          final BiConsumer<A, T> accumulator = new BiConsumer<A, T>() {
              @Override
              public void accept(A a, T t) {
                  if (predicate.test(t)) {
                      downstreamAccumulator.accept(a, t);
                  }
              }
          };
  
          return new CollectorImpl<>(downstream.supplier(), accumulator, downstream.combiner(), downstream.finisher(), downstream.characteristics());
      }
docs: It's copied from StreamEx: https://github.com/amaembo/streamex under Apache License v2 and may be modified.
  <br />
  
  Returns a {@code Collector} which passes only those elements to the
  specified downstream collector which match given predicate.
  
  <p>
  This method returns a
  <a href="package-summary.html#ShortCircuitReduction">short-circuiting
  collector</a> if downstream collector is short-circuiting.
  
  <p>
  The operation performed by the returned collector is equivalent to
  {@code stream.filter(predicate).collect(downstream)}. This collector is
  mostly useful as a downstream collector in cascaded operation involving
  {@link #pairing(Collector, Collector, BiFunction)} collector.
  
  <p>
  This method is similar to {@code Collectors.filtering} method which
  appears in JDK 9. However when downstream collector is
  <a href="package-summary.html#ShortCircuitReduction">short-circuiting</a>
  , this method will also return a short-circuiting collector.
  
  @param <T> the type of the input elements
  @param <A> intermediate accumulation type of the downstream collector
  @param <R> result type of collector
  @param predicate a filter function to be applied to the input elements
  @param downstream a collector which will accept filtered values
  @return a collector which applies the predicate to the input elements and
  provides the elements for which predicate returned true to the
  downstream collector
  @see #pairing(Collector, Collector, BiFunction)
  @since 0.4.0