ConcurrentMapBasedFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, OUTPUT> implements Function<INPUT, OUTPUT> { @Override public OUTPUT apply(final INPUT input) { final KEY key = keyFunction.apply(input); return computeIfAbsent(key, givenKey -> function.apply(input)); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedFunctionMemoizer(
            final ConcurrentMap<KEY, OUTPUT> cache,
            final Function<INPUT, KEY> keyFunction,
            final Function<INPUT, OUTPUT> function); @Override OUTPUT apply(final INPUT input);  }
@Test public void shouldMemoizeFunctionCall() { final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>(); final Function<String, String> function = input -> "output"; final Function<String, String> keyFunction = Function.identity(); final ConcurrentMapBasedFunctionMemoizer<String, String, String> memoizer = new ConcurrentMapBasedFunctionMemoizer<>( cache, keyFunction, function); Assert.assertEquals("Memoized value does not match expectations", "output", memoizer.apply("test")); }