@Test public void shouldMemoizeFunction() { final ConcurrentMap<Integer, Long> cache = new ConcurrentHashMap<>(); final IntToLongFunction function = input -> 123; final IntFunction<Integer> keyFunction = Integer::valueOf; final ConcurrentMapBasedIntToLongFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToLongFunctionMemoizer<>( cache, keyFunction, function); memoizer.applyAsLong(123); }
@Override public long applyAsLong(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); }
ConcurrentMapBasedIntToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements IntToLongFunction { @Override public long applyAsLong(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } }
ConcurrentMapBasedIntToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements IntToLongFunction { @Override public long applyAsLong(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedIntToLongFunctionMemoizer(
            final ConcurrentMap<KEY, Long> cache,
            final IntFunction<KEY> keyFunction,
            final IntToLongFunction function); }
ConcurrentMapBasedIntToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements IntToLongFunction { @Override public long applyAsLong(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedIntToLongFunctionMemoizer(
            final ConcurrentMap<KEY, Long> cache,
            final IntFunction<KEY> keyFunction,
            final IntToLongFunction function); @Override long applyAsLong(final int value); }
ConcurrentMapBasedIntToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements IntToLongFunction { @Override public long applyAsLong(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedIntToLongFunctionMemoizer(
            final ConcurrentMap<KEY, Long> cache,
            final IntFunction<KEY> keyFunction,
            final IntToLongFunction function); @Override long applyAsLong(final int value);  }