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
;
10 import java
.util
.function
.IntPredicate
;
12 import com
.google
.common
.cache
.Cache
;
14 final class GuavaCacheBasedIntPredicateMemoizer
<KEY
>
15 extends AbstractGuavaCacheBasedMemoizer
<KEY
, Boolean
>
16 implements IntPredicate
{
18 private final IntFunction
<KEY
> keyFunction
;
19 private final IntPredicate predicate
;
21 GuavaCacheBasedIntPredicateMemoizer(
22 final Cache
<KEY
, Boolean
> cache
,
23 final IntFunction
<KEY
> keyFunction
,
24 final IntPredicate predicate
) {
26 this.keyFunction
= keyFunction
;
27 this.predicate
= predicate
;
31 public boolean test(final int input
) {
32 final KEY key
= keyFunction
.apply(input
);
33 return get(key
, givenKey
-> Boolean
.valueOf(predicate
.test(input
))).booleanValue();