ConcurrentMapBasedLongPredicateMemoizer extends ConcurrentMapBasedMemoizer<KEY, Boolean> implements LongPredicate { @Override public boolean test(final long value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Boolean.valueOf(predicate.test(value))).booleanValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedLongPredicateMemoizer(
            final ConcurrentMap<KEY, Boolean> cache,
            final LongFunction<KEY> keyFunction,
            final LongPredicate predicate); @Override boolean test(final long value);  }
@Test public void shouldMemoizePredicateCall() { final ConcurrentMap<Long, Boolean> cache = new ConcurrentHashMap<>(); final LongPredicate predicate = input -> true; final LongFunction<Long> keyFunction = Long::valueOf; final ConcurrentMapBasedLongPredicateMemoizer<Long> memoizer = new ConcurrentMapBasedLongPredicateMemoizer<>( cache, keyFunction, predicate); Assert.assertTrue("Memoized value does not match expectations", memoizer.test(123L)); }