@Test public void shouldMemoizeFunction() { final DoubleFunction<String> function = a -> "test"; final DoubleFunction<String> keyFunction = a -> "key"; try (final Cache<String, String> cache = JCacheMemoize.createCache(DoubleFunction.class)) { final JCacheBasedDoubleFunctionMemoizer<String, String> loader = new JCacheBasedDoubleFunctionMemoizer<>( cache, keyFunction, function); Assert.assertEquals("Memoized value does not match expectation", "test", loader.apply(123)); } }
@Override public OUTPUT apply(final double value) { final KEY key = keyFunction.apply(value); return invoke(key, givenKey -> function.apply(value)); }
JCacheBasedDoubleFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, OUTPUT> implements DoubleFunction<OUTPUT> { @Override public OUTPUT apply(final double value) { final KEY key = keyFunction.apply(value); return invoke(key, givenKey -> function.apply(value)); } }
JCacheBasedDoubleFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, OUTPUT> implements DoubleFunction<OUTPUT> { @Override public OUTPUT apply(final double value) { final KEY key = keyFunction.apply(value); return invoke(key, givenKey -> function.apply(value)); } JCacheBasedDoubleFunctionMemoizer(
            final Cache<KEY, OUTPUT> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleFunction<OUTPUT> function); }
JCacheBasedDoubleFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, OUTPUT> implements DoubleFunction<OUTPUT> { @Override public OUTPUT apply(final double value) { final KEY key = keyFunction.apply(value); return invoke(key, givenKey -> function.apply(value)); } JCacheBasedDoubleFunctionMemoizer(
            final Cache<KEY, OUTPUT> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleFunction<OUTPUT> function); @Override OUTPUT apply(final double value); }
JCacheBasedDoubleFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, OUTPUT> implements DoubleFunction<OUTPUT> { @Override public OUTPUT apply(final double value) { final KEY key = keyFunction.apply(value); return invoke(key, givenKey -> function.apply(value)); } JCacheBasedDoubleFunctionMemoizer(
            final Cache<KEY, OUTPUT> cache,
            final DoubleFunction<KEY> keyFunction,
            final DoubleFunction<OUTPUT> function); @Override OUTPUT apply(final double value);  }