@Test public void shouldMemoizeFunction() { final ConcurrentMap<Double, Long> cache = new ConcurrentHashMap<>(); final DoubleToLongFunction function = input -> 123; final DoubleFunction<Double> keyFunction = Double::valueOf; final ConcurrentMapBasedDoubleToLongFunctionMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleToLongFunctionMemoizer<>( cache, keyFunction, function); memoizer.applyAsLong(123.456D); }
@Override public long applyAsLong(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); }
ConcurrentMapBasedDoubleToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements DoubleToLongFunction { @Override public long applyAsLong(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } }
ConcurrentMapBasedDoubleToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements DoubleToLongFunction { @Override public long applyAsLong(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedDoubleToLongFunctionMemoizer(
            final ConcurrentMap<KEY, Long> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleToLongFunction function); }
ConcurrentMapBasedDoubleToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements DoubleToLongFunction { @Override public long applyAsLong(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedDoubleToLongFunctionMemoizer(
            final ConcurrentMap<KEY, Long> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleToLongFunction function); @Override long applyAsLong(final double value); }
ConcurrentMapBasedDoubleToLongFunctionMemoizer extends ConcurrentMapBasedMemoizer<KEY, Long> implements DoubleToLongFunction { @Override public long applyAsLong(final double value) { final KEY key = keyFunction.apply(value); return computeIfAbsent(key, givenKey -> Long.valueOf(function.applyAsLong(value))) .longValue(); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedDoubleToLongFunctionMemoizer(
            final ConcurrentMap<KEY, Long> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleToLongFunction function); @Override long applyAsLong(final double value);  }