code: public static <T, A, R> Collector<T, ?, R> filtering(Predicate<? super T> predicate,
              Collector<T, A, R> downstream) {
          BiConsumer<A, T> downstreamAccumulator = downstream.accumulator();
          BiConsumer<A, T> accumulator = (acc, t) -> {
              if (predicate.test(t))
                  downstreamAccumulator.accept(acc, t);
          };
          Predicate<A> finished = finished(downstream);
          if (finished != null) {
              return new CancellableCollectorImpl<>(downstream.supplier(), accumulator, downstream.combiner(), downstream
                      .finisher(), finished, downstream.characteristics());
          }
          return Collector.of(downstream.supplier(), accumulator, downstream.combiner(), downstream.finisher(), downstream
                  .characteristics().toArray(new Characteristics[0]));
      }
docs: 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