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
.concurrent
.ExecutionException
;
10 import java
.util
.function
.Function
;
12 import com
.google
.common
.cache
.Cache
;
14 import de
.xn__ho_hia
.memoization
.shared
.MemoizationException
;
16 abstract class AbstractGuavaCacheBasedMemoizer
<KEY
, VALUE
> {
18 private final Cache
<KEY
, VALUE
> cache
;
20 protected AbstractGuavaCacheBasedMemoizer(final Cache
<KEY
, VALUE
> cache
) {
24 protected final VALUE
get(final KEY key
, final Function
<KEY
, VALUE
> function
) {
26 return cache
.get(key
, () -> function
.apply(key
));
27 } catch (final ExecutionException exception
) {
28 throw new MemoizationException(exception
);