GuavaCacheBasedToDoubleBiFunctionMemoizer extends AbstractGuavaCacheBasedMemoizer<KEY, Double> implements ToDoubleBiFunction<FIRST, SECOND> { @Override public double applyAsDouble(final FIRST first, final SECOND second) { final KEY key = keyFunction.apply(first, second); return get(key, givenKey -> Double.valueOf(biFunction.applyAsDouble(first, second))).doubleValue(); } GuavaCacheBasedToDoubleBiFunctionMemoizer(
            final Cache<KEY, Double> cache,
            final BiFunction<FIRST, SECOND, KEY> keyFunction,
            final ToDoubleBiFunction<FIRST, SECOND> biFunction); @Override double applyAsDouble(final FIRST first, final SECOND second);  }
@Test public void shouldTransformInput() { final ToDoubleBiFunction<String, String> biFunction = (first, second) -> 123; final BiFunction<String, String, String> keyFunction = (first, second) -> second + first; final Cache<String, Double> cache = CacheBuilder.newBuilder().build(); final GuavaCacheBasedToDoubleBiFunctionMemoizer<String, String, String> memoizer = new GuavaCacheBasedToDoubleBiFunctionMemoizer<>( cache, keyFunction, biFunction); Assert.assertEquals("firstsecond", 123D, memoizer.applyAsDouble("first", "second"), 0.0D); }