@Test public void shouldMemoizeBiFunction() { final ToIntFunction<String> function = first -> 123; final Function<String, String> keyfunction = a -> "key"; try (final Cache<String, Integer> cache = JCacheMemoize.createCache(ToDoubleBiFunction.class)) { final JCacheBasedToIntFunctionMemoizer<String, String> loader = new JCacheBasedToIntFunctionMemoizer<>( cache, keyfunction, function); Assert.assertEquals("Memoized value does not match expectation", 123, loader.applyAsInt("first")); } }
@Override public int applyAsInt(final FIRST first) { final KEY key = keyFunction.apply(first); return invoke(key, givenKey -> Integer.valueOf(biFunction.applyAsInt(first))).intValue(); }
JCacheBasedToIntFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, Integer> implements ToIntFunction<FIRST> { @Override public int applyAsInt(final FIRST first) { final KEY key = keyFunction.apply(first); return invoke(key, givenKey -> Integer.valueOf(biFunction.applyAsInt(first))).intValue(); } }
JCacheBasedToIntFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, Integer> implements ToIntFunction<FIRST> { @Override public int applyAsInt(final FIRST first) { final KEY key = keyFunction.apply(first); return invoke(key, givenKey -> Integer.valueOf(biFunction.applyAsInt(first))).intValue(); } JCacheBasedToIntFunctionMemoizer(
            final Cache<KEY, Integer> cache,
            final Function<FIRST, KEY> keyFunction,
            final ToIntFunction<FIRST> biFunction); }
JCacheBasedToIntFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, Integer> implements ToIntFunction<FIRST> { @Override public int applyAsInt(final FIRST first) { final KEY key = keyFunction.apply(first); return invoke(key, givenKey -> Integer.valueOf(biFunction.applyAsInt(first))).intValue(); } JCacheBasedToIntFunctionMemoizer(
            final Cache<KEY, Integer> cache,
            final Function<FIRST, KEY> keyFunction,
            final ToIntFunction<FIRST> biFunction); @Override int applyAsInt(final FIRST first); }
JCacheBasedToIntFunctionMemoizer extends AbstractJCacheBasedMemoizer<KEY, Integer> implements ToIntFunction<FIRST> { @Override public int applyAsInt(final FIRST first) { final KEY key = keyFunction.apply(first); return invoke(key, givenKey -> Integer.valueOf(biFunction.applyAsInt(first))).intValue(); } JCacheBasedToIntFunctionMemoizer(
            final Cache<KEY, Integer> cache,
            final Function<FIRST, KEY> keyFunction,
            final ToIntFunction<FIRST> biFunction); @Override int applyAsInt(final FIRST first);  }