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
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
) {
26 this.keyFunction
= keyFunction
;
27 this.consumer
= consumer
;
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
);