Class CountingPredicate<T>

java.lang.Object
org.kiwiproject.beta.util.function.CountingPredicate<T>
All Implemented Interfaces:
Predicate<T>

@Beta public class CountingPredicate<T> extends Object implements Predicate<T>
A Predicate that wraps a Predicate and tracks the number of true and false results.

This should be used only on one stream, unless you want to continue to accumulate the number of true and false results over multiple streams.

Exceptions thrown by the wrapped Predicate are passed through.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new instance that wraps predicate in order to count the number of true and false results.
  • Method Summary

    Modifier and Type
    Method
    Description
    @org.checkerframework.checker.index.qual.NonNegative long
    Return the number of times this predicate has gotten a false result.
    boolean
    test(T t)
    @org.checkerframework.checker.index.qual.NonNegative long
    Return the number of times this predicate has gotten a true result.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Predicate

    and, negate, or
  • Constructor Details

    • CountingPredicate

      public CountingPredicate(Predicate<T> predicate)
      Create a new instance that wraps predicate in order to count the number of true and false results.
      Parameters:
      predicate - the original Predicate to wrap
  • Method Details

    • test

      public boolean test(T t)
      Specified by:
      test in interface Predicate<T>
    • trueCount

      public @org.checkerframework.checker.index.qual.NonNegative long trueCount()
      Return the number of times this predicate has gotten a true result.
      Returns:
      the total number of true results
    • falseCount

      public @org.checkerframework.checker.index.qual.NonNegative long falseCount()
      Return the number of times this predicate has gotten a false result.
      Returns:
      the total number of false results