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
.IntFunction
;
11 import com
.google
.common
.cache
.Cache
;
13 final class GuavaCacheBasedIntFunctionMemoizer
<KEY
, OUTPUT
>
14 extends AbstractGuavaCacheBasedMemoizer
<KEY
, OUTPUT
>
15 implements IntFunction
<OUTPUT
> {
17 private final IntFunction
<KEY
> keyFunction
;
18 private final IntFunction
<OUTPUT
> function
;
20 GuavaCacheBasedIntFunctionMemoizer(
21 final Cache
<KEY
, OUTPUT
> cache
,
22 final IntFunction
<KEY
> keyFunction
,
23 final IntFunction
<OUTPUT
> function
) {
25 this.keyFunction
= keyFunction
;
26 this.function
= function
;
30 public OUTPUT
apply(final int value
) {
31 final KEY key
= keyFunction
.apply(value
);
32 return get(key
, givenKey
-> function
.apply(value
));