fix #64
[memoization.java.git] / memoization-guava / src / main / java / de / xn__ho_hia / memoization / guava / GuavaCacheBasedLongSupplierMemoizer.java
blobd19486c095dc536e5fcdb7c15e2e04bf95946fce
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.LongSupplier;
10 import java.util.function.Supplier;
12 import com.google.common.cache.Cache;
14 final class GuavaCacheBasedLongSupplierMemoizer<KEY>
15 extends AbstractGuavaCacheBasedMemoizer<KEY, Long>
16 implements LongSupplier {
18 private final Supplier<KEY> keySupplier;
19 private final LongSupplier supplier;
21 GuavaCacheBasedLongSupplierMemoizer(
22 final Cache<KEY, Long> cache,
23 final Supplier<KEY> keySupplier,
24 final LongSupplier supplier) {
25 super(cache);
26 this.keySupplier = keySupplier;
27 this.supplier = supplier;
30 @Override
31 public long getAsLong() {
32 return get(keySupplier.get(), givenKey -> Long.valueOf(supplier.getAsLong())).longValue();