ConcurrentMapBasedPredicateMemoizer extends ConcurrentMapBasedMemoizer<KEY, Boolean> implements Predicate<INPUT> { @Override public boolean test(final INPUT input) { final KEY key = keyFunction.apply(input); return computeIfAbsent(key, givenKey -> Boolean.valueOf(predicate.test(input))).booleanValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedPredicateMemoizer(
            final ConcurrentMap<KEY, Boolean> cache,
            final Function<INPUT, KEY> keyFunction,
            final Predicate<INPUT> predicate); @Override boolean test(final INPUT input);  }
@Test public void shouldMemoizePredicateCall() { final ConcurrentMap<String, Boolean> cache = new ConcurrentHashMap<>(); final Predicate<String> predicate = input -> true; final Function<String, String> keyFunction = Function.identity(); final ConcurrentMapBasedPredicateMemoizer<String, String> memoizer = new ConcurrentMapBasedPredicateMemoizer<>( cache, keyFunction, predicate); Assert.assertTrue("Memoized value does not match expectations", memoizer.test("test")); }