public static <T> Predicate<T> countingPredicate(final LongAdder counter,
                                                     final boolean countIfTrue,
                                                     final Predicate<T> predicate) {
        Objects.requireNonNull(predicate);
        Objects.requireNonNull(counter);
        return val -> {
            final boolean result = predicate.test(val);
            if (countIfTrue) {
                if (result) {
                    counter.increment();
                }
            } else {
                if (!result) {
                    counter.increment();
                }
            }
            return result;
        };
    }
Creates a predicate that increments counter for each match encountered.

@param counter     The counter to increment. It is the caller's responsibility to zero it as needed.
@param countIfTrue If true counter is incremented for a match. If false, counter is incremented for
                   a non-match.
@param predicate   The predicate to wrap
@return The wrapped predicate
stroom-util/src/main/java/stroom/util/PredicateUtil.java