@Test public void shouldMemoizeFunction() { final ConcurrentMap<Integer, Double> cache = new ConcurrentHashMap<>(); final IntToDoubleFunction function = input -> 123; final IntFunction<Integer> keyFunction = Integer::valueOf; final ConcurrentMapBasedIntToDoubleFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToDoubleFunctionMemoizer<>( cache, keyFunction, function); memoizer.applyAsDouble(123); }
@Override public double applyAsDouble(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Double.valueOf(function.applyAsDouble(value))) .doubleValue(); }
ConcurrentMapBasedIntToDoubleFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Double> implements IntToDoubleFunction { @Override public double applyAsDouble(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Double.valueOf(function.applyAsDouble(value))) .doubleValue(); } }
ConcurrentMapBasedIntToDoubleFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Double> implements IntToDoubleFunction { @Override public double applyAsDouble(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Double.valueOf(function.applyAsDouble(value))) .doubleValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedIntToDoubleFunctionMemoizer(
            final ConcurrentMap<KEY, Double> cache,
            final IntFunction<KEY> keyFunction,
            final IntToDoubleFunction function); }
ConcurrentMapBasedIntToDoubleFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Double> implements IntToDoubleFunction { @Override public double applyAsDouble(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Double.valueOf(function.applyAsDouble(value))) .doubleValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedIntToDoubleFunctionMemoizer(
            final ConcurrentMap<KEY, Double> cache,
            final IntFunction<KEY> keyFunction,
            final IntToDoubleFunction function); @Override double applyAsDouble(final int value); }
ConcurrentMapBasedIntToDoubleFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Double> implements IntToDoubleFunction { @Override public double applyAsDouble(final int value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Double.valueOf(function.applyAsDouble(value))) .doubleValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedIntToDoubleFunctionMemoizer(
            final ConcurrentMap<KEY, Double> cache,
            final IntFunction<KEY> keyFunction,
            final IntToDoubleFunction function); @Override double applyAsDouble(final int value);  }