fix #64
[memoization.java.git] / memoization-guava / src / main / java / de / xn__ho_hia / memoization / guava / GuavaCacheBasedDoubleConsumerMemoizer.java
blobcd9935e4a1a5ba4b3e7f108aad52c57fddc45bb6
1 /*
2 * This file is part of memoization.java. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of memoization.java,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
7 package de.xn__ho_hia.memoization.guava;
9 import java.util.function.DoubleConsumer;
10 import java.util.function.DoubleFunction;
12 import com.google.common.cache.Cache;
14 final class GuavaCacheBasedDoubleConsumerMemoizer<KEY>
15 extends AbstractGuavaCacheBasedMemoizer<KEY, Double>
16 implements DoubleConsumer {
18 private final DoubleFunction<KEY> keyFunction;
19 private final DoubleConsumer consumer;
21 GuavaCacheBasedDoubleConsumerMemoizer(
22 final Cache<KEY, Double> cache,
23 final DoubleFunction<KEY> keyFunction,
24 final DoubleConsumer consumer) {
25 super(cache);
26 this.keyFunction = keyFunction;
27 this.consumer = consumer;
30 @Override
31 public void accept(final double value) {
32 final KEY key = keyFunction.apply(value);
33 get(key, givenKey -> {
34 consumer.accept(value);
35 return Double.valueOf(value);
36 });