fix #64
[memoization.java.git] / memoization-guava / src / main / java / de / xn__ho_hia / memoization / guava / GuavaCacheBasedBiPredicateMemoizer.java
blobddfeb06a77ddb7059d88cb6a1b801ef75907cb12
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.BiFunction;
10 import java.util.function.BiPredicate;
12 import com.google.common.cache.Cache;
14 final class GuavaCacheBasedBiPredicateMemoizer<FIRST, SECOND, KEY>
15 extends AbstractGuavaCacheBasedMemoizer<KEY, Boolean>
16 implements BiPredicate<FIRST, SECOND> {
18 private final BiFunction<FIRST, SECOND, KEY> keyFunction;
19 private final BiPredicate<FIRST, SECOND> biPredicate;
21 GuavaCacheBasedBiPredicateMemoizer(
22 final Cache<KEY, Boolean> cache,
23 final BiFunction<FIRST, SECOND, KEY> keyFunction,
24 final BiPredicate<FIRST, SECOND> biPredicate) {
25 super(cache);
26 this.keyFunction = keyFunction;
27 this.biPredicate = biPredicate;
30 @Override
31 public boolean test(final FIRST first, final SECOND second) {
32 final KEY key = keyFunction.apply(first, second);
33 return get(key, givenKey -> Boolean.valueOf(biPredicate.test(first, second))).booleanValue();