@Test public void shouldMemoizeFunction() { final ConcurrentMap<Double, Integer> cache = new ConcurrentHashMap<>(); final DoubleToIntFunction function = input -> 123; final DoubleFunction<Double> keyFunction = Double::valueOf; final ConcurrentMapBasedDoubleToIntFunctionMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleToIntFunctionMemoizer<>( cache, keyFunction, function); memoizer.applyAsInt(123.456D); }
@Override public int applyAsInt(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Integer.valueOf(function.applyAsInt(value))) .intValue(); }
ConcurrentMapBasedDoubleToIntFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Integer> implements DoubleToIntFunction { @Override public int applyAsInt(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Integer.valueOf(function.applyAsInt(value))) .intValue(); } }
ConcurrentMapBasedDoubleToIntFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Integer> implements DoubleToIntFunction { @Override public int applyAsInt(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Integer.valueOf(function.applyAsInt(value))) .intValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedDoubleToIntFunctionMemoizer(
            final ConcurrentMap<KEY, Integer> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleToIntFunction function); }
ConcurrentMapBasedDoubleToIntFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Integer> implements DoubleToIntFunction { @Override public int applyAsInt(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Integer.valueOf(function.applyAsInt(value))) .intValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedDoubleToIntFunctionMemoizer(
            final ConcurrentMap<KEY, Integer> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleToIntFunction function); @Override int applyAsInt(final double value); }
ConcurrentMapBasedDoubleToIntFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Integer> implements DoubleToIntFunction { @Override public int applyAsInt(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Integer.valueOf(function.applyAsInt(value))) .intValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedDoubleToIntFunctionMemoizer(
            final ConcurrentMap<KEY, Integer> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleToIntFunction function); @Override int applyAsInt(final double value);  }