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 static de
.xn__ho_hia
.memoization
.shared
.MemoizationDefaults
.defaultKeySupplier
;
10 import static de
.xn__ho_hia
.memoization
.shared
.MemoizationDefaults
.doubleBinaryOperatorHashCodeKeyFunction
;
11 import static de
.xn__ho_hia
.memoization
.shared
.MemoizationDefaults
.hashCodeKeyFunction
;
12 import static de
.xn__ho_hia
.memoization
.shared
.MemoizationDefaults
.intBinaryOperatorHashCodeKeyFunction
;
13 import static java
.util
.function
.Function
.identity
;
15 import java
.util
.function
.BiConsumer
;
16 import java
.util
.function
.BiFunction
;
17 import java
.util
.function
.BiPredicate
;
18 import java
.util
.function
.BooleanSupplier
;
19 import java
.util
.function
.Consumer
;
20 import java
.util
.function
.DoubleBinaryOperator
;
21 import java
.util
.function
.DoubleConsumer
;
22 import java
.util
.function
.DoubleFunction
;
23 import java
.util
.function
.DoublePredicate
;
24 import java
.util
.function
.DoubleSupplier
;
25 import java
.util
.function
.Function
;
26 import java
.util
.function
.IntBinaryOperator
;
27 import java
.util
.function
.IntConsumer
;
28 import java
.util
.function
.IntFunction
;
29 import java
.util
.function
.IntPredicate
;
30 import java
.util
.function
.IntSupplier
;
31 import java
.util
.function
.LongConsumer
;
32 import java
.util
.function
.LongFunction
;
33 import java
.util
.function
.LongPredicate
;
34 import java
.util
.function
.LongSupplier
;
35 import java
.util
.function
.Predicate
;
36 import java
.util
.function
.Supplier
;
38 import com
.google
.common
.cache
.Cache
;
39 import com
.google
.common
.cache
.CacheBuilder
;
41 import de
.xn__ho_hia
.memoization
.shared
.DoubleBinaryFunction
;
42 import de
.xn__ho_hia
.memoization
.shared
.IntBinaryFunction
;
43 import de
.xn__ho_hia
.memoization
.shared
.MemoizationDefaults
;
47 * Factory for lightweight wrappers that store the result of a potentially expensive function call. Each method of this
48 * class exposes two of the following features:
50 * <strong>Default cache</strong>
52 * The memoizer uses the default cache of this factory. Current implementation creates a new {@link Cache} per memoizer.
54 * <strong>Default cache key</strong>
56 * The memoizer uses the default {@link BiFunction} or {@link Supplier} to calculate the cache key for each call. Either
57 * uses the natural key (e.g. the input itself) or one of the methods in {@link MemoizationDefaults}.
59 * <strong>Custom cache</strong>
61 * The memoizer uses a user-provided {@link Cache} as its cache. It is possible to add values to the cache both before
62 * and after the memoizer was created.
64 * <strong>Custom cache key</strong>
66 * The memoizer uses a user-defined {@link BiFunction} or {@link Supplier} to calculate the cache key for each call.
67 * Take a look at {@link MemoizationDefaults} for a possible key functions and suppliers.
73 * @see BooleanSupplier
75 * @see DoubleBinaryOperator
78 * @see DoublePredicate
81 * @see IntBinaryOperator
92 * @see <a href="https://en.wikipedia.org/wiki/Memoization">Wikipedia: Memoization</a>
94 public final class GuavaMemoize
{
96 private GuavaMemoize() {
102 * Memoizes a {@link BiConsumer} in a Guava {@link Cache}.
106 * <li>Default cache</li>
107 * <li>Default cache key</li>
111 * The {@link BiConsumer} to memoize.
112 * @return The wrapped {@link BiConsumer}.
114 public static final <FIRST
, SECOND
> BiConsumer
<FIRST
, SECOND
> biConsumer(
115 final BiConsumer
<FIRST
, SECOND
> biConsumer
) {
116 return biConsumer(biConsumer
, CacheBuilder
.newBuilder().build());
121 * Memoizes a {@link BiConsumer} in a Guava {@link Cache}.
125 * <li>Default cache</li>
126 * <li>Custom cache key</li>
130 * The {@link BiConsumer} to memoize.
132 * The {@link BiFunction} to compute the cache key.
133 * @return The wrapped {@link BiConsumer}.
135 public static final <FIRST
, SECOND
, KEY
> BiConsumer
<FIRST
, SECOND
> biConsumer(
136 final BiConsumer
<FIRST
, SECOND
> biConsumer
,
137 final BiFunction
<FIRST
, SECOND
, KEY
> keyFunction
) {
138 return biConsumer(biConsumer
, keyFunction
, CacheBuilder
.newBuilder().build());
143 * Memoizes a {@link BiConsumer} in a Guava {@link Cache}.
147 * <li>Custom cache</li>
148 * <li>Custom cache key</li>
152 * The {@link BiConsumer} to memoize.
154 * The {@link BiFunction} to compute the cache key.
156 * The {@link Cache} to use.
157 * @return The wrapped {@link BiConsumer}.
159 public static final <FIRST
, SECOND
, KEY
> BiConsumer
<FIRST
, SECOND
> biConsumer(
160 final BiConsumer
<FIRST
, SECOND
> biConsumer
,
161 final BiFunction
<FIRST
, SECOND
, KEY
> keyFunction
,
162 final Cache
<KEY
, KEY
> cache
) {
163 return new GuavaCacheBasedBiConsumerMemoizer
<>(cache
, keyFunction
, biConsumer
);
168 * Memoizes a {@link BiConsumer} in a Guava {@link Cache}.
172 * <li>Custom cache</li>
173 * <li>Default cache key</li>
177 * The {@link BiConsumer} to memoize.
179 * The {@link Cache} to use.
180 * @return The wrapped {@link BiConsumer}.
182 public static final <FIRST
, SECOND
> BiConsumer
<FIRST
, SECOND
> biConsumer(
183 final BiConsumer
<FIRST
, SECOND
> biConsumer
,
184 final Cache
<String
, String
> cache
) {
185 return biConsumer(biConsumer
, hashCodeKeyFunction(), cache
);
190 * Memoizes a {@link BiFunction} in a Guava {@link Cache}.
194 * <li>Default cache</li>
195 * <li>Default cache key</li>
199 * The {@link BiFunction} to memoize.
200 * @return The wrapped {@link BiFunction}.
202 public static final <FIRST
, SECOND
, OUTPUT
> BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction(
203 final BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction
) {
204 return biFunction(biFunction
, CacheBuilder
.newBuilder().build());
209 * Memoizes a {@link BiFunction} in a Guava {@link Cache}.
213 * <li>Default cache</li>
214 * <li>Custom cache key</li>
218 * The {@link BiFunction} to memoize.
220 * The {@link BiFunction} to compute the cache key.
221 * @return The wrapped {@link BiFunction}.
223 public static final <FIRST
, SECOND
, KEY
, OUTPUT
> BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction(
224 final BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction
,
225 final BiFunction
<FIRST
, SECOND
, KEY
> keyFunction
) {
226 return biFunction(biFunction
, keyFunction
, CacheBuilder
.newBuilder().build());
231 * Memoizes a {@link BiFunction} in a Guava {@link Cache}.
235 * <li>Custom cache</li>
236 * <li>Custom cache key</li>
240 * The {@link BiFunction} to memoize.
242 * The {@link BiFunction} to compute the cache key.
244 * The {@link Cache} to use.
245 * @return The wrapped {@link BiFunction}.
247 public static final <FIRST
, SECOND
, KEY
, OUTPUT
> BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction(
248 final BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction
,
249 final BiFunction
<FIRST
, SECOND
, KEY
> keyFunction
,
250 final Cache
<KEY
, OUTPUT
> cache
) {
251 return new GuavaCacheBasedBiFunctionMemoizer
<>(cache
, keyFunction
, biFunction
);
256 * Memoizes a {@link BiFunction} in a Guava {@link Cache}.
260 * <li>Custom cache</li>
261 * <li>Default cache key</li>
265 * The {@link BiFunction} to memoize.
267 * The {@link Cache} to use.
268 * @return The wrapped {@link BiFunction}.
270 public static final <FIRST
, SECOND
, OUTPUT
> BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction(
271 final BiFunction
<FIRST
, SECOND
, OUTPUT
> biFunction
,
272 final Cache
<String
, OUTPUT
> cache
) {
273 return biFunction(biFunction
, hashCodeKeyFunction(), cache
);
278 * Memoizes a {@link BiPredicate} in a Guava {@link Cache}.
282 * <li>Default cache</li>
283 * <li>Default cache key</li>
287 * The {@link BiPredicate} to memoize.
288 * @return The wrapped {@link BiPredicate}.
290 public static final <FIRST
, SECOND
> BiPredicate
<FIRST
, SECOND
> biPredicate(
291 final BiPredicate
<FIRST
, SECOND
> biPredicate
) {
292 return biPredicate(biPredicate
, CacheBuilder
.newBuilder().build());
297 * Memoizes a {@link BiPredicate} in a Guava {@link Cache}.
301 * <li>Default cache</li>
302 * <li>Custom cache key</li>
306 * The {@link BiPredicate} to memoize.
308 * The {@link BiFunction} to compute the cache key.
309 * @return The wrapped {@link BiPredicate}.
311 public static final <FIRST
, SECOND
, KEY
> BiPredicate
<FIRST
, SECOND
> biPredicate(
312 final BiPredicate
<FIRST
, SECOND
> biPredicate
,
313 final BiFunction
<FIRST
, SECOND
, KEY
> keyFunction
) {
314 return biPredicate(biPredicate
, keyFunction
, CacheBuilder
.newBuilder().build());
319 * Memoizes a {@link BiPredicate} in a Guava {@link Cache}.
323 * <li>Custom cache</li>
324 * <li>Custom cache key</li>
328 * The {@link BiPredicate} to memoize.
330 * The {@link BiFunction} to compute the cache key.
332 * The {@link Cache} to use.
333 * @return The wrapped {@link BiPredicate}.
335 public static final <FIRST
, SECOND
, KEY
> BiPredicate
<FIRST
, SECOND
> biPredicate(
336 final BiPredicate
<FIRST
, SECOND
> biPredicate
,
337 final BiFunction
<FIRST
, SECOND
, KEY
> keyFunction
,
338 final Cache
<KEY
, Boolean
> cache
) {
339 return new GuavaCacheBasedBiPredicateMemoizer
<>(cache
, keyFunction
, biPredicate
);
344 * Memoizes a {@link BiPredicate} in a Guava {@link Cache}.
348 * <li>Custom cache</li>
349 * <li>Default cache key</li>
353 * The {@link BiPredicate} to memoize.
355 * The {@link Cache} to use.
356 * @return The wrapped {@link BiPredicate}.
358 public static final <FIRST
, SECOND
> BiPredicate
<FIRST
, SECOND
> biPredicate(
359 final BiPredicate
<FIRST
, SECOND
> biPredicate
,
360 final Cache
<String
, Boolean
> cache
) {
361 return biPredicate(biPredicate
, hashCodeKeyFunction(), cache
);
366 * Memoizes a {@link BooleanSupplier} in a Guava {@link Cache}.
370 * <li>Default cache</li>
371 * <li>Default cache key</li>
374 * @param booleanSupplier
375 * The {@link BooleanSupplier} to memoize.
376 * @return The wrapped {@link BooleanSupplier}.
378 public static final BooleanSupplier
booleanSupplier(final BooleanSupplier booleanSupplier
) {
379 return booleanSupplier(booleanSupplier
, CacheBuilder
.newBuilder().build());
384 * Memoizes a {@link BooleanSupplier} in a Guava {@link Cache}.
388 * <li>Custom cache</li>
389 * <li>Default cache key</li>
392 * @param booleanSupplier
393 * The {@link BooleanSupplier} to memoize.
395 * The {@link Cache} to use.
396 * @return The wrapped {@link BooleanSupplier}.
398 public static final BooleanSupplier
booleanSupplier(
399 final BooleanSupplier booleanSupplier
,
400 final Cache
<String
, Boolean
> cache
) {
401 return booleanSupplier(booleanSupplier
, defaultKeySupplier(), cache
);
406 * Memoizes a {@link BooleanSupplier} in a Guava {@link Cache}.
410 * <li>Default cache</li>
411 * <li>Custom cache key</li>
414 * @param booleanSupplier
415 * The {@link BooleanSupplier} to memoize.
417 * The {@link Supplier} for the cache key.
418 * @return The wrapped {@link BooleanSupplier}.
420 public static final <KEY
> BooleanSupplier
booleanSupplier(
421 final BooleanSupplier booleanSupplier
,
422 final Supplier
<KEY
> keySupplier
) {
423 return booleanSupplier(booleanSupplier
, keySupplier
, CacheBuilder
.newBuilder().build());
428 * Memoizes a {@link BooleanSupplier} in a Guava {@link Cache}.
432 * <li>Custom cache</li>
433 * <li>Custom cache key</li>
436 * @param booleanSupplier
437 * The {@link BooleanSupplier} to memoize.
439 * The {@link Supplier} for the cache key.
441 * The {@link Cache} to use.
442 * @return The wrapped {@link BooleanSupplier}.
444 public static final <KEY
> BooleanSupplier
booleanSupplier(
445 final BooleanSupplier booleanSupplier
,
446 final Supplier
<KEY
> keySupplier
,
447 final Cache
<KEY
, Boolean
> cache
) {
448 return new GuavaCacheBasedBooleanSupplierMemoizer
<>(cache
, keySupplier
, booleanSupplier
);
453 * Memoizes a {@link Consumer} in a Guava {@link Cache}.
457 * <li>Default cache</li>
458 * <li>Default cache key</li>
462 * The {@link Consumer} to memoize.
463 * @return The wrapped {@link Consumer}.
465 public static final <INPUT
> Consumer
<INPUT
> consumer(
466 final Consumer
<INPUT
> consumer
) {
467 return consumer(consumer
, CacheBuilder
.newBuilder().build());
472 * Memoizes a {@link Consumer} in a Guava {@link Cache}.
476 * <li>Custom cache</li>
477 * <li>Default cache key</li>
481 * The {@link Consumer} to memoize.
483 * The {@link Cache} to use.
484 * @return The wrapped {@link Consumer}.
486 public static final <INPUT
> Consumer
<INPUT
> consumer(
487 final Consumer
<INPUT
> consumer
,
488 final Cache
<INPUT
, INPUT
> cache
) {
489 return consumer(consumer
, identity(), cache
);
494 * Memoizes a {@link Consumer} in a Guava {@link Cache}.
498 * <li>Default cache</li>
499 * <li>Custom cache key</li>
503 * The {@link Consumer} to memoize.
505 * The {@link Function} to compute the cache key.
506 * @return The wrapped {@link Consumer}.
508 public static final <INPUT
, KEY
> Consumer
<INPUT
> consumer(
509 final Consumer
<INPUT
> consumer
,
510 final Function
<INPUT
, KEY
> keyFunction
) {
511 return consumer(consumer
, keyFunction
, CacheBuilder
.newBuilder().build());
516 * Memoizes a {@link Consumer} in a Guava {@link Cache}.
520 * <li>Custom cache</li>
521 * <li>Custom cache key</li>
525 * The {@link Consumer} to memoize.
527 * The {@link Function} to compute the cache key.
529 * The {@link Cache} to use.
530 * @return The wrapped {@link Consumer}.
532 public static final <INPUT
, KEY
> Consumer
<INPUT
> consumer(
533 final Consumer
<INPUT
> consumer
,
534 final Function
<INPUT
, KEY
> keyFunction
,
535 final Cache
<KEY
, INPUT
> cache
) {
536 return new GuavaCacheBasedConsumerMemoizer
<>(cache
, keyFunction
, consumer
);
541 * Memoizes a {@link DoubleBinaryOperator} in a Guava {@link Cache}.
545 * <li>Default cache</li>
546 * <li>Default cache key</li>
549 * @param doubleBinaryOperator
550 * The {@link DoubleBinaryOperator} to memoize.
551 * @return The wrapped {@link DoubleBinaryOperator}.
553 public static final DoubleBinaryOperator
doubleBinaryOperator(
554 final DoubleBinaryOperator doubleBinaryOperator
) {
555 return doubleBinaryOperator(doubleBinaryOperator
, CacheBuilder
.newBuilder().build());
560 * Memoizes a {@link DoubleBinaryOperator} in a Guava {@link Cache}.
564 * <li>Default cache</li>
565 * <li>Custom cache key</li>
568 * @param doubleBinaryOperator
569 * The {@link DoubleBinaryOperator} to memoize.
571 * The {@link DoubleBinaryFunction} to compute the cache key.
572 * @return The wrapped {@link DoubleBinaryOperator}.
574 public static final <KEY
> DoubleBinaryOperator
doubleBinaryOperator(
575 final DoubleBinaryOperator doubleBinaryOperator
,
576 final DoubleBinaryFunction
<KEY
> keyFunction
) {
577 return doubleBinaryOperator(doubleBinaryOperator
, keyFunction
, CacheBuilder
.newBuilder().build());
582 * Memoizes a {@link DoubleBinaryOperator} in a Guava {@link Cache}.
586 * <li>Custom cache</li>
587 * <li>Default cache key</li>
590 * @param doubleBinaryOperator
591 * The {@link DoubleBinaryOperator} to memoize.
593 * The {@link Cache} to use.
594 * @return The wrapped {@link DoubleBinaryOperator}.
596 public static final DoubleBinaryOperator
doubleBinaryOperator(
597 final DoubleBinaryOperator doubleBinaryOperator
,
598 final Cache
<String
, Double
> cache
) {
599 return doubleBinaryOperator(doubleBinaryOperator
, doubleBinaryOperatorHashCodeKeyFunction(), cache
);
604 * Memoizes a {@link DoubleBinaryOperator} in a Guava {@link Cache}.
608 * <li>Custom cache</li>
609 * <li>Custom cache key</li>
612 * @param doubleBinaryOperator
613 * The {@link DoubleBinaryOperator} to memoize.
615 * The {@link DoubleBinaryFunction} to compute the cache key.
617 * The {@link Cache} to use.
618 * @return The wrapped {@link DoubleBinaryOperator}.
620 public static final <KEY
> DoubleBinaryOperator
doubleBinaryOperator(
621 final DoubleBinaryOperator doubleBinaryOperator
,
622 final DoubleBinaryFunction
<KEY
> keyFunction
,
623 final Cache
<KEY
, Double
> cache
) {
624 return new GuavaCacheBasedDoubleBinaryOperatorMemoizer
<>(cache
, keyFunction
, doubleBinaryOperator
);
629 * Memoizes a {@link DoubleConsumer} in a Guava {@link Cache}.
633 * <li>Default cache</li>
634 * <li>Default cache key</li>
637 * @param doubleConsumer
638 * The {@link DoubleConsumer} to memoize.
639 * @return The wrapped {@link DoubleConsumer}.
641 public static final DoubleConsumer
doubleConsumer(
642 final DoubleConsumer doubleConsumer
) {
643 return doubleConsumer(doubleConsumer
, CacheBuilder
.newBuilder().build());
648 * Memoizes a {@link DoubleConsumer} in a Guava {@link Cache}.
652 * <li>Custom cache</li>
653 * <li>Default cache key</li>
656 * @param doubleConsumer
657 * The {@link DoubleConsumer} to memoize.
659 * The {@link Cache} to use.
660 * @return The wrapped {@link DoubleConsumer}.
662 public static final DoubleConsumer
doubleConsumer(
663 final DoubleConsumer doubleConsumer
,
664 final Cache
<Double
, Double
> cache
) {
665 return doubleConsumer(doubleConsumer
, Double
::valueOf
, cache
);
670 * Memoizes a {@link DoubleConsumer} in a Guava {@link Cache}.
674 * <li>Default cache</li>
675 * <li>Custom cache key</li>
678 * @param doubleConsumer
679 * The {@link DoubleConsumer} to memoize.
681 * The {@link DoubleFunction} to compute the cache key.
682 * @return The wrapped {@link DoubleConsumer}.
684 public static final <KEY
> DoubleConsumer
doubleConsumer(
685 final DoubleConsumer doubleConsumer
,
686 final DoubleFunction
<KEY
> keyFunction
) {
687 return doubleConsumer(doubleConsumer
, keyFunction
, CacheBuilder
.newBuilder().build());
692 * Memoizes a {@link DoubleConsumer} in a Guava {@link Cache}.
696 * <li>Custom cache</li>
697 * <li>Custom cache key</li>
700 * @param doubleConsumer
701 * The {@link DoubleConsumer} to memoize.
703 * The {@link Function} to compute the cache key.
705 * The {@link Cache} to use.
706 * @return The wrapped {@link DoubleConsumer}.
708 public static final <KEY
> DoubleConsumer
doubleConsumer(
709 final DoubleConsumer doubleConsumer
,
710 final DoubleFunction
<KEY
> keyFunction
,
711 final Cache
<KEY
, Double
> cache
) {
712 return new GuavaCacheBasedDoubleConsumerMemoizer
<>(cache
, keyFunction
, doubleConsumer
);
717 * Memoizes a {@link DoubleFunction} in a Guava {@link Cache}.
721 * <li>Default cache</li>
722 * <li>Default cache key</li>
726 * The {@link DoubleFunction} to memoize.
727 * @return The wrapped {@link DoubleFunction}.
729 public static final <OUTPUT
> DoubleFunction
<OUTPUT
> doubleFunction(
730 final DoubleFunction
<OUTPUT
> function
) {
731 return doubleFunction(function
, CacheBuilder
.newBuilder().build());
736 * Memoizes a {@link DoubleFunction} in a Guava {@link Cache}.
740 * <li>Custom cache</li>
741 * <li>Default cache key</li>
745 * The {@link DoubleFunction} to memoize.
747 * The {@link Cache} to use.
748 * @return The wrapped {@link DoubleFunction}.
750 public static final <OUTPUT
> DoubleFunction
<OUTPUT
> doubleFunction(
751 final DoubleFunction
<OUTPUT
> function
,
752 final Cache
<Double
, OUTPUT
> cache
) {
753 return doubleFunction(function
, Double
::valueOf
, cache
);
758 * Memoizes a {@link DoubleFunction} in a Guava {@link Cache}.
762 * <li>Default cache</li>
763 * <li>Custom cache key</li>
767 * The {@link DoubleFunction} to memoize.
769 * The {@link DoubleFunction} to compute the cache key.
770 * @return The wrapped {@link DoubleFunction}.
772 public static final <KEY
, OUTPUT
> DoubleFunction
<OUTPUT
> doubleFunction(
773 final DoubleFunction
<OUTPUT
> function
,
774 final DoubleFunction
<KEY
> keyFunction
) {
775 return doubleFunction(function
, keyFunction
, CacheBuilder
.newBuilder().build());
780 * Memoizes a {@link DoubleFunction} in a Guava {@link Cache}.
784 * <li>Custom cache</li>
785 * <li>Custom cache key</li>
789 * The {@link DoubleFunction} to memoize.
791 * The {@link DoubleFunction} to compute the cache key.
793 * The {@link Cache} to use.
794 * @return The wrapped {@link DoubleFunction}.
796 public static final <KEY
, OUTPUT
> DoubleFunction
<OUTPUT
> doubleFunction(
797 final DoubleFunction
<OUTPUT
> function
,
798 final DoubleFunction
<KEY
> keyFunction
,
799 final Cache
<KEY
, OUTPUT
> cache
) {
800 return new GuavaCacheBasedDoubleFunctionMemoizer
<>(cache
, keyFunction
, function
);
805 * Memoizes a {@link DoublePredicate} in a Guava {@link Cache}.
809 * <li>Default cache</li>
810 * <li>Default cache key</li>
813 * @param doublePredicate
814 * The {@link DoublePredicate} to memoize.
815 * @return The wrapped {@link DoublePredicate}.
817 public static final DoublePredicate
doublePredicate(
818 final DoublePredicate doublePredicate
) {
819 return doublePredicate(doublePredicate
, CacheBuilder
.newBuilder().build());
824 * Memoizes a {@link DoublePredicate} in a Guava {@link Cache}.
828 * <li>Custom cache</li>
829 * <li>Default cache key</li>
832 * @param doublePredicate
833 * The {@link DoublePredicate} to memoize.
835 * The {@link Cache} to use.
836 * @return The wrapped {@link DoublePredicate}.
838 public static final DoublePredicate
doublePredicate(
839 final DoublePredicate doublePredicate
,
840 final Cache
<Double
, Boolean
> cache
) {
841 return doublePredicate(doublePredicate
, Double
::valueOf
, cache
);
846 * Memoizes a {@link DoublePredicate} in a Guava {@link Cache}.
850 * <li>Default cache</li>
851 * <li>Custom cache key</li>
854 * @param doublePredicate
855 * The {@link DoublePredicate} to memoize.
857 * The {@link DoubleFunction} to compute the cache key.
858 * @return The wrapped {@link DoublePredicate}.
860 public static final <KEY
> DoublePredicate
doublePredicate(
861 final DoublePredicate doublePredicate
,
862 final DoubleFunction
<KEY
> keyFunction
) {
863 return doublePredicate(doublePredicate
, keyFunction
, CacheBuilder
.newBuilder().build());
868 * Memoizes a {@link DoublePredicate} in a Guava {@link Cache}.
872 * <li>Custom cache</li>
873 * <li>Custom cache key</li>
876 * @param doublePredicate
877 * The {@link DoublePredicate} to memoize.
879 * The {@link DoubleFunction} to compute the cache key.
881 * The {@link Cache} to use.
882 * @return The wrapped {@link DoublePredicate}.
884 public static final <KEY
> DoublePredicate
doublePredicate(
885 final DoublePredicate doublePredicate
,
886 final DoubleFunction
<KEY
> keyFunction
,
887 final Cache
<KEY
, Boolean
> cache
) {
888 return new GuavaCacheBasedDoublePredicateMemoizer
<>(cache
, keyFunction
, doublePredicate
);
893 * Memoizes a {@link DoubleSupplier} in a Guava {@link Cache}.
897 * <li>Default cache</li>
898 * <li>Default cache key</li>
901 * @param doubleSupplier
902 * The {@link DoubleSupplier} to memoize.
903 * @return The wrapped {@link DoubleSupplier}.
905 public static final DoubleSupplier
doubleSupplier(final DoubleSupplier doubleSupplier
) {
906 return doubleSupplier(doubleSupplier
, CacheBuilder
.newBuilder().build());
911 * Memoizes a {@link DoubleSupplier} in a Guava {@link Cache}.
915 * <li>Custom cache</li>
916 * <li>Default cache key</li>
919 * @param doubleSupplier
920 * The {@link DoubleSupplier} to memoize.
922 * The {@link Cache} to use.
923 * @return The wrapped {@link DoubleSupplier}.
925 public static final DoubleSupplier
doubleSupplier(
926 final DoubleSupplier doubleSupplier
,
927 final Cache
<String
, Double
> cache
) {
928 return doubleSupplier(doubleSupplier
, defaultKeySupplier(), cache
);
933 * Memoizes a {@link DoubleSupplier} in a Guava {@link Cache}.
937 * <li>Default cache</li>
938 * <li>Custom cache key</li>
941 * @param doubleSupplier
942 * The {@link DoubleSupplier} to memoize.
944 * The {@link Supplier} for the cache key.
945 * @return The wrapped {@link DoubleSupplier}.
947 public static final <KEY
> DoubleSupplier
doubleSupplier(
948 final DoubleSupplier doubleSupplier
,
949 final Supplier
<KEY
> keySupplier
) {
950 return doubleSupplier(doubleSupplier
, keySupplier
, CacheBuilder
.newBuilder().build());
955 * Memoizes a {@link DoubleSupplier} in a Guava {@link Cache}.
959 * <li>Custom cache</li>
960 * <li>Custom cache key</li>
963 * @param doubleSupplier
964 * The {@link DoubleSupplier} to memoize.
966 * The {@link Supplier} for the cache key.
968 * The {@link Cache} to use.
969 * @return The wrapped {@link DoubleSupplier}.
971 public static final <KEY
> DoubleSupplier
doubleSupplier(
972 final DoubleSupplier doubleSupplier
,
973 final Supplier
<KEY
> keySupplier
,
974 final Cache
<KEY
, Double
> cache
) {
975 return new GuavaCacheBasedDoubleSupplierMemoizer
<>(cache
, keySupplier
, doubleSupplier
);
980 * Memoizes a {@link Function} in a Guava {@link Cache}.
984 * <li>Default cache</li>
985 * <li>Default cache key</li>
989 * The {@link Function} to memoize.
990 * @return The wrapped {@link Function}.
992 public static final <INPUT
, OUTPUT
> Function
<INPUT
, OUTPUT
> function(
993 final Function
<INPUT
, OUTPUT
> function
) {
994 return function(function
, CacheBuilder
.newBuilder().build());
999 * Memoizes a {@link Function} in a Guava {@link Cache}.
1003 * <li>Custom cache</li>
1004 * <li>Default cache key</li>
1008 * The {@link Function} to memoize.
1010 * The {@link Cache} to use.
1011 * @return The wrapped {@link Function}.
1013 public static final <INPUT
, OUTPUT
> Function
<INPUT
, OUTPUT
> function(
1014 final Function
<INPUT
, OUTPUT
> function
,
1015 final Cache
<INPUT
, OUTPUT
> cache
) {
1016 return function(function
, Function
.identity(), cache
);
1021 * Memoizes a {@link Function} in a Guava {@link Cache}.
1025 * <li>Default cache</li>
1026 * <li>Custom cache key</li>
1030 * The {@link Function} to memoize.
1031 * @param keyFunction
1032 * The {@link Function} to compute the cache key.
1033 * @return The wrapped {@link Function}.
1035 public static final <INPUT
, KEY
, OUTPUT
> Function
<INPUT
, OUTPUT
> function(
1036 final Function
<INPUT
, OUTPUT
> function
,
1037 final Function
<INPUT
, KEY
> keyFunction
) {
1038 return function(function
, keyFunction
, CacheBuilder
.newBuilder().build());
1043 * Memoizes a {@link Function} in a Guava {@link Cache}.
1047 * <li>Custom cache</li>
1048 * <li>Custom cache key</li>
1052 * The {@link Function} to memoize.
1053 * @param keyFunction
1054 * The {@link Function} to compute the cache key.
1056 * The {@link Cache} to use.
1057 * @return The wrapped {@link Function}.
1059 public static final <INPUT
, KEY
, OUTPUT
> Function
<INPUT
, OUTPUT
> function(
1060 final Function
<INPUT
, OUTPUT
> function
,
1061 final Function
<INPUT
, KEY
> keyFunction
,
1062 final Cache
<KEY
, OUTPUT
> cache
) {
1063 return new GuavaCacheBasedFunctionMemoizer
<>(cache
, keyFunction
, function
);
1068 * Memoizes a {@link IntBinaryOperator} in a Guava {@link Cache}.
1072 * <li>Default cache</li>
1073 * <li>Default cache key</li>
1076 * @param intBinaryOperator
1077 * The {@link IntBinaryOperator} to memoize.
1078 * @return The wrapped {@link IntBinaryOperator}.
1080 public static final IntBinaryOperator
intBinaryOperator(
1081 final IntBinaryOperator intBinaryOperator
) {
1082 return intBinaryOperator(intBinaryOperator
, CacheBuilder
.newBuilder().build());
1087 * Memoizes a {@link IntBinaryOperator} in a Guava {@link Cache}.
1091 * <li>Default cache</li>
1092 * <li>Custom cache key</li>
1095 * @param intBinaryOperator
1096 * The {@link IntBinaryOperator} to memoize.
1097 * @param keyFunction
1098 * The {@link IntBinaryFunction} to compute the cache key.
1099 * @return The wrapped {@link IntBinaryOperator}.
1101 public static final <KEY
> IntBinaryOperator
intBinaryOperator(
1102 final IntBinaryOperator intBinaryOperator
,
1103 final IntBinaryFunction
<KEY
> keyFunction
) {
1104 return intBinaryOperator(intBinaryOperator
, keyFunction
, CacheBuilder
.newBuilder().build());
1109 * Memoizes a {@link IntBinaryOperator} in a Guava {@link Cache}.
1113 * <li>Custom cache</li>
1114 * <li>Default cache key</li>
1117 * @param intBinaryOperator
1118 * The {@link IntBinaryOperator} to memoize.
1120 * The {@link Cache} to use.
1121 * @return The wrapped {@link IntBinaryOperator}.
1123 public static final IntBinaryOperator
intBinaryOperator(
1124 final IntBinaryOperator intBinaryOperator
,
1125 final Cache
<String
, Integer
> cache
) {
1126 return intBinaryOperator(intBinaryOperator
, intBinaryOperatorHashCodeKeyFunction(), cache
);
1131 * Memoizes a {@link IntBinaryOperator} in a Guava {@link Cache}.
1135 * <li>Custom cache</li>
1136 * <li>Custom cache key</li>
1139 * @param intBinaryOperator
1140 * The {@link IntBinaryOperator} to memoize.
1141 * @param keyFunction
1142 * The {@link IntBinaryFunction} to compute the cache key.
1144 * The {@link Cache} to use.
1145 * @return The wrapped {@link IntBinaryOperator}.
1147 public static final <KEY
> IntBinaryOperator
intBinaryOperator(
1148 final IntBinaryOperator intBinaryOperator
,
1149 final IntBinaryFunction
<KEY
> keyFunction
,
1150 final Cache
<KEY
, Integer
> cache
) {
1151 return new GuavaCacheBasedIntBinaryOperatorMemoizer
<>(cache
, keyFunction
, intBinaryOperator
);
1156 * Memoizes a {@link IntConsumer} in a Guava {@link Cache}.
1160 * <li>Default cache</li>
1161 * <li>Default cache key</li>
1164 * @param intConsumer
1165 * The {@link IntConsumer} to memoize.
1166 * @return The wrapped {@link IntConsumer}.
1168 public static final IntConsumer
intConsumer(
1169 final IntConsumer intConsumer
) {
1170 return intConsumer(intConsumer
, CacheBuilder
.newBuilder().build());
1175 * Memoizes a {@link IntConsumer} in a Guava {@link Cache}.
1179 * <li>Custom cache</li>
1180 * <li>Default cache key</li>
1183 * @param intConsumer
1184 * The {@link IntConsumer} to memoize.
1186 * The {@link Cache} to use.
1187 * @return The wrapped {@link IntConsumer}.
1189 public static final IntConsumer
intConsumer(
1190 final IntConsumer intConsumer
,
1191 final Cache
<Integer
, Integer
> cache
) {
1192 return intConsumer(intConsumer
, Integer
::valueOf
, cache
);
1197 * Memoizes a {@link IntConsumer} in a Guava {@link Cache}.
1201 * <li>Default cache</li>
1202 * <li>Custom cache key</li>
1205 * @param intConsumer
1206 * The {@link IntConsumer} to memoize.
1207 * @param keyFunction
1208 * The {@link DoubleFunction} to compute the cache key.
1209 * @return The wrapped {@link IntConsumer}.
1211 public static final <KEY
> IntConsumer
intConsumer(
1212 final IntConsumer intConsumer
,
1213 final IntFunction
<KEY
> keyFunction
) {
1214 return intConsumer(intConsumer
, keyFunction
, CacheBuilder
.newBuilder().build());
1219 * Memoizes a {@link IntConsumer} in a Guava {@link Cache}.
1223 * <li>Custom cache</li>
1224 * <li>Custom cache key</li>
1227 * @param intConsumer
1228 * The {@link IntConsumer} to memoize.
1229 * @param keyFunction
1230 * The {@link Function} to compute the cache key.
1232 * The {@link Cache} to use.
1233 * @return The wrapped {@link IntConsumer}.
1235 public static final <KEY
> IntConsumer
intConsumer(
1236 final IntConsumer intConsumer
,
1237 final IntFunction
<KEY
> keyFunction
,
1238 final Cache
<KEY
, Integer
> cache
) {
1239 return new GuavaCacheBasedIntConsumerMemoizer
<>(cache
, keyFunction
, intConsumer
);
1244 * Memoizes a {@link IntFunction} in a Guava {@link Cache}.
1248 * <li>Default cache</li>
1249 * <li>Default cache key</li>
1253 * The {@link IntFunction} to memoize.
1254 * @return The wrapped {@link IntFunction}.
1256 public static final <OUTPUT
> IntFunction
<OUTPUT
> intFunction(
1257 final IntFunction
<OUTPUT
> function
) {
1258 return intFunction(function
, CacheBuilder
.newBuilder().build());
1263 * Memoizes a {@link IntFunction} in a Guava {@link Cache}.
1267 * <li>Custom cache</li>
1268 * <li>Default cache key</li>
1272 * The {@link IntFunction} to memoize.
1274 * The {@link Cache} to use.
1275 * @return The wrapped {@link IntFunction}.
1277 public static final <OUTPUT
> IntFunction
<OUTPUT
> intFunction(
1278 final IntFunction
<OUTPUT
> function
,
1279 final Cache
<Integer
, OUTPUT
> cache
) {
1280 return intFunction(function
, Integer
::valueOf
, cache
);
1285 * Memoizes a {@link IntFunction} in a Guava {@link Cache}.
1289 * <li>Default cache</li>
1290 * <li>Custom cache key</li>
1294 * The {@link IntFunction} to memoize.
1295 * @param keyFunction
1296 * The {@link IntFunction} to compute the cache key.
1297 * @return The wrapped {@link IntFunction}.
1299 public static final <KEY
, OUTPUT
> IntFunction
<OUTPUT
> intFunction(
1300 final IntFunction
<OUTPUT
> function
,
1301 final IntFunction
<KEY
> keyFunction
) {
1302 return intFunction(function
, keyFunction
, CacheBuilder
.newBuilder().build());
1307 * Memoizes a {@link IntFunction} in a Guava {@link Cache}.
1311 * <li>Custom cache</li>
1312 * <li>Custom cache key</li>
1316 * The {@link IntFunction} to memoize.
1317 * @param keyFunction
1318 * The {@link IntFunction} to compute the cache key.
1320 * The {@link Cache} to use.
1321 * @return The wrapped {@link IntFunction}.
1323 public static final <KEY
, OUTPUT
> IntFunction
<OUTPUT
> intFunction(
1324 final IntFunction
<OUTPUT
> function
,
1325 final IntFunction
<KEY
> keyFunction
,
1326 final Cache
<KEY
, OUTPUT
> cache
) {
1327 return new GuavaCacheBasedIntFunctionMemoizer
<>(cache
, keyFunction
, function
);
1332 * Memoizes a {@link IntPredicate} in a Guava {@link Cache}.
1336 * <li>Default cache</li>
1337 * <li>Default cache key</li>
1340 * @param intPredicate
1341 * The {@link IntPredicate} to memoize.
1342 * @return The wrapped {@link IntPredicate}.
1344 public static final IntPredicate
intPredicate(
1345 final IntPredicate intPredicate
) {
1346 return intPredicate(intPredicate
, CacheBuilder
.newBuilder().build());
1351 * Memoizes a {@link IntPredicate} in a Guava {@link Cache}.
1355 * <li>Custom cache</li>
1356 * <li>Default cache key</li>
1359 * @param intPredicate
1360 * The {@link IntPredicate} to memoize.
1362 * The {@link Cache} to use.
1363 * @return The wrapped {@link IntPredicate}.
1365 public static final IntPredicate
intPredicate(
1366 final IntPredicate intPredicate
,
1367 final Cache
<Integer
, Boolean
> cache
) {
1368 return intPredicate(intPredicate
, Integer
::valueOf
, cache
);
1373 * Memoizes a {@link IntPredicate} in a Guava {@link Cache}.
1377 * <li>Default cache</li>
1378 * <li>Custom cache key</li>
1381 * @param intPredicate
1382 * The {@link IntPredicate} to memoize.
1383 * @param keyFunction
1384 * The {@link IntFunction} to compute the cache key.
1385 * @return The wrapped {@link IntPredicate}.
1387 public static final <KEY
> IntPredicate
intPredicate(
1388 final IntPredicate intPredicate
,
1389 final IntFunction
<KEY
> keyFunction
) {
1390 return intPredicate(intPredicate
, keyFunction
, CacheBuilder
.newBuilder().build());
1395 * Memoizes a {@link IntPredicate} in a Guava {@link Cache}.
1399 * <li>Custom cache</li>
1400 * <li>Custom cache key</li>
1403 * @param intPredicate
1404 * The {@link IntPredicate} to memoize.
1405 * @param keyFunction
1406 * The {@link IntFunction} to compute the cache key.
1408 * The {@link Cache} to use.
1409 * @return The wrapped {@link IntPredicate}.
1411 public static final <KEY
> IntPredicate
intPredicate(
1412 final IntPredicate intPredicate
,
1413 final IntFunction
<KEY
> keyFunction
,
1414 final Cache
<KEY
, Boolean
> cache
) {
1415 return new GuavaCacheBasedIntPredicateMemoizer
<>(cache
, keyFunction
, intPredicate
);
1420 * Memoizes a {@link IntSupplier} in a Guava {@link Cache}.
1424 * <li>Default cache</li>
1425 * <li>Default cache key</li>
1428 * @param intSupplier
1429 * The {@link IntSupplier} to memoize.
1430 * @return The wrapped {@link IntSupplier}.
1432 public static final IntSupplier
intSupplier(final IntSupplier intSupplier
) {
1433 return intSupplier(intSupplier
, CacheBuilder
.newBuilder().build());
1438 * Memoizes a {@link IntSupplier} in a Guava {@link Cache}.
1442 * <li>Custom cache</li>
1443 * <li>Default cache key</li>
1446 * @param intSupplier
1447 * The {@link IntSupplier} to memoize.
1449 * The {@link Cache} to use.
1450 * @return The wrapped {@link IntSupplier}.
1452 public static final IntSupplier
intSupplier(
1453 final IntSupplier intSupplier
,
1454 final Cache
<String
, Integer
> cache
) {
1455 return intSupplier(intSupplier
, defaultKeySupplier(), cache
);
1460 * Memoizes a {@link IntSupplier} in a Guava {@link Cache}.
1464 * <li>Default cache</li>
1465 * <li>Custom cache key</li>
1468 * @param intSupplier
1469 * The {@link IntSupplier} to memoize.
1470 * @param keySupplier
1471 * The {@link Supplier} for the cache key.
1472 * @return The wrapped {@link IntSupplier}.
1474 public static final <KEY
> IntSupplier
intSupplier(
1475 final IntSupplier intSupplier
,
1476 final Supplier
<KEY
> keySupplier
) {
1477 return intSupplier(intSupplier
, keySupplier
, CacheBuilder
.newBuilder().build());
1482 * Memoizes a {@link IntSupplier} in a Guava {@link Cache}.
1486 * <li>Custom cache</li>
1487 * <li>Custom cache key</li>
1490 * @param intSupplier
1491 * The {@link IntSupplier} to memoize.
1492 * @param keySupplier
1493 * The {@link Supplier} for the cache key.
1495 * The {@link Cache} to use.
1496 * @return The wrapped {@link IntSupplier}.
1498 public static final <KEY
> IntSupplier
intSupplier(
1499 final IntSupplier intSupplier
,
1500 final Supplier
<KEY
> keySupplier
,
1501 final Cache
<KEY
, Integer
> cache
) {
1502 return new GuavaCacheBasedIntSupplierMemoizer
<>(cache
, keySupplier
, intSupplier
);
1507 * Memoizes a {@link LongConsumer} in a Guava {@link Cache}.
1511 * <li>Default cache</li>
1512 * <li>Default cache key</li>
1515 * @param longConsumer
1516 * The {@link LongConsumer} to memoize.
1517 * @return The wrapped {@link LongConsumer}.
1519 public static final LongConsumer
longConsumer(
1520 final LongConsumer longConsumer
) {
1521 return longConsumer(longConsumer
, CacheBuilder
.newBuilder().build());
1526 * Memoizes a {@link LongConsumer} in a Guava {@link Cache}.
1530 * <li>Custom cache</li>
1531 * <li>Default cache key</li>
1534 * @param longConsumer
1535 * The {@link LongConsumer} to memoize.
1537 * The {@link Cache} to use.
1538 * @return The wrapped {@link LongConsumer}.
1540 public static final LongConsumer
longConsumer(
1541 final LongConsumer longConsumer
,
1542 final Cache
<Long
, Long
> cache
) {
1543 return longConsumer(longConsumer
, Long
::valueOf
, cache
);
1548 * Memoizes a {@link LongConsumer} in a Guava {@link Cache}.
1552 * <li>Default cache</li>
1553 * <li>Custom cache key</li>
1556 * @param longConsumer
1557 * The {@link LongConsumer} to memoize.
1558 * @param keyFunction
1559 * The {@link DoubleFunction} to compute the cache key.
1560 * @return The wrapped {@link LongConsumer}.
1562 public static final <KEY
> LongConsumer
longConsumer(
1563 final LongConsumer longConsumer
,
1564 final LongFunction
<KEY
> keyFunction
) {
1565 return longConsumer(longConsumer
, keyFunction
, CacheBuilder
.newBuilder().build());
1570 * Memoizes a {@link LongConsumer} in a Guava {@link Cache}.
1574 * <li>Custom cache</li>
1575 * <li>Custom cache key</li>
1578 * @param longConsumer
1579 * The {@link LongConsumer} to memoize.
1580 * @param keyFunction
1581 * The {@link Function} to compute the cache key.
1583 * The {@link Cache} to use.
1584 * @return The wrapped {@link LongConsumer}.
1586 public static final <KEY
> LongConsumer
longConsumer(
1587 final LongConsumer longConsumer
,
1588 final LongFunction
<KEY
> keyFunction
,
1589 final Cache
<KEY
, Long
> cache
) {
1590 return new GuavaCacheBasedLongConsumerMemoizer
<>(cache
, keyFunction
, longConsumer
);
1595 * Memoizes a {@link LongFunction} in a Guava {@link Cache}.
1599 * <li>Default cache</li>
1600 * <li>Default cache key</li>
1604 * The {@link LongFunction} to memoize.
1605 * @return The wrapped {@link LongFunction}.
1607 public static final <OUTPUT
> LongFunction
<OUTPUT
> longFunction(
1608 final LongFunction
<OUTPUT
> function
) {
1609 return longFunction(function
, CacheBuilder
.newBuilder().build());
1614 * Memoizes a {@link LongFunction} in a Guava {@link Cache}.
1618 * <li>Custom cache</li>
1619 * <li>Default cache key</li>
1623 * The {@link LongFunction} to memoize.
1625 * The {@link Cache} to use.
1626 * @return The wrapped {@link LongFunction}.
1628 public static final <OUTPUT
> LongFunction
<OUTPUT
> longFunction(
1629 final LongFunction
<OUTPUT
> function
,
1630 final Cache
<Long
, OUTPUT
> cache
) {
1631 return longFunction(function
, Long
::valueOf
, cache
);
1636 * Memoizes a {@link LongFunction} in a Guava {@link Cache}.
1640 * <li>Default cache</li>
1641 * <li>Custom cache key</li>
1645 * The {@link LongFunction} to memoize.
1646 * @param keyFunction
1647 * The {@link LongFunction} to compute the cache key.
1648 * @return The wrapped {@link LongFunction}.
1650 public static final <KEY
, OUTPUT
> LongFunction
<OUTPUT
> longFunction(
1651 final LongFunction
<OUTPUT
> function
,
1652 final LongFunction
<KEY
> keyFunction
) {
1653 return longFunction(function
, keyFunction
, CacheBuilder
.newBuilder().build());
1658 * Memoizes a {@link LongFunction} in a Guava {@link Cache}.
1662 * <li>Custom cache</li>
1663 * <li>Custom cache key</li>
1667 * The {@link LongFunction} to memoize.
1668 * @param keyFunction
1669 * The {@link LongFunction} to compute the cache key.
1671 * The {@link Cache} to use.
1672 * @return The wrapped {@link LongFunction}.
1674 public static final <KEY
, OUTPUT
> LongFunction
<OUTPUT
> longFunction(
1675 final LongFunction
<OUTPUT
> function
,
1676 final LongFunction
<KEY
> keyFunction
,
1677 final Cache
<KEY
, OUTPUT
> cache
) {
1678 return new GuavaCacheBasedLongFunctionMemoizer
<>(cache
, keyFunction
, function
);
1683 * Memoizes a {@link LongPredicate} in a Guava {@link Cache}.
1687 * <li>Default cache</li>
1688 * <li>Default cache key</li>
1691 * @param longPredicate
1692 * The {@link LongPredicate} to memoize.
1693 * @return The wrapped {@link LongPredicate}.
1695 public static final LongPredicate
longPredicate(
1696 final LongPredicate longPredicate
) {
1697 return longPredicate(longPredicate
, CacheBuilder
.newBuilder().build());
1702 * Memoizes a {@link LongPredicate} in a Guava {@link Cache}.
1706 * <li>Custom cache</li>
1707 * <li>Default cache key</li>
1710 * @param longPredicate
1711 * The {@link LongPredicate} to memoize.
1713 * The {@link Cache} to use.
1714 * @return The wrapped {@link LongPredicate}.
1716 public static final LongPredicate
longPredicate(
1717 final LongPredicate longPredicate
,
1718 final Cache
<Long
, Boolean
> cache
) {
1719 return longPredicate(longPredicate
, Long
::valueOf
, cache
);
1724 * Memoizes a {@link LongPredicate} in a Guava {@link Cache}.
1728 * <li>Default cache</li>
1729 * <li>Custom cache key</li>
1732 * @param longPredicate
1733 * The {@link LongPredicate} to memoize.
1734 * @param keyFunction
1735 * The {@link LongFunction} to compute the cache key.
1736 * @return The wrapped {@link LongPredicate}.
1738 public static final <KEY
> LongPredicate
longPredicate(
1739 final LongPredicate longPredicate
,
1740 final LongFunction
<KEY
> keyFunction
) {
1741 return longPredicate(longPredicate
, keyFunction
, CacheBuilder
.newBuilder().build());
1746 * Memoizes a {@link LongPredicate} in a Guava {@link Cache}.
1750 * <li>Custom cache</li>
1751 * <li>Custom cache key</li>
1754 * @param longPredicate
1755 * The {@link LongPredicate} to memoize.
1756 * @param keyFunction
1757 * The {@link LongFunction} to compute the cache key.
1759 * The {@link Cache} to use.
1760 * @return The wrapped {@link LongPredicate}.
1762 public static final <KEY
> LongPredicate
longPredicate(
1763 final LongPredicate longPredicate
,
1764 final LongFunction
<KEY
> keyFunction
,
1765 final Cache
<KEY
, Boolean
> cache
) {
1766 return new GuavaCacheBasedLongPredicateMemoizer
<>(cache
, keyFunction
, longPredicate
);
1771 * Memoizes a {@link LongSupplier} in a Guava {@link Cache}.
1775 * <li>Default cache</li>
1776 * <li>Default cache key</li>
1779 * @param longSupplier
1780 * The {@link LongSupplier} to memoize.
1781 * @return The wrapped {@link LongSupplier}.
1783 public static final LongSupplier
longSupplier(final LongSupplier longSupplier
) {
1784 return longSupplier(longSupplier
, CacheBuilder
.newBuilder().build());
1789 * Memoizes a {@link LongSupplier} in a Guava {@link Cache}.
1793 * <li>Custom cache</li>
1794 * <li>Default cache key</li>
1797 * @param longSupplier
1798 * The {@link LongSupplier} to memoize.
1800 * The {@link Cache} to use.
1801 * @return The wrapped {@link LongSupplier}.
1803 public static final LongSupplier
longSupplier(
1804 final LongSupplier longSupplier
,
1805 final Cache
<String
, Long
> cache
) {
1806 return longSupplier(longSupplier
, defaultKeySupplier(), cache
);
1811 * Memoizes a {@link LongSupplier} in a Guava {@link Cache}.
1815 * <li>Default cache</li>
1816 * <li>Custom cache key</li>
1819 * @param longSupplier
1820 * The {@link LongSupplier} to memoize.
1821 * @param keySupplier
1822 * The {@link Supplier} for the cache key.
1823 * @return The wrapped {@link LongSupplier}.
1825 public static final <KEY
> LongSupplier
longSupplier(
1826 final LongSupplier longSupplier
,
1827 final Supplier
<KEY
> keySupplier
) {
1828 return longSupplier(longSupplier
, keySupplier
, CacheBuilder
.newBuilder().build());
1833 * Memoizes a {@link LongSupplier} in a Guava {@link Cache}.
1837 * <li>Custom cache</li>
1838 * <li>Custom cache key</li>
1841 * @param longSupplier
1842 * The {@link LongSupplier} to memoize.
1843 * @param keySupplier
1844 * The {@link Supplier} for the cache key.
1846 * The {@link Cache} to use.
1847 * @return The wrapped {@link LongSupplier}.
1849 public static final <KEY
> LongSupplier
longSupplier(
1850 final LongSupplier longSupplier
,
1851 final Supplier
<KEY
> keySupplier
,
1852 final Cache
<KEY
, Long
> cache
) {
1853 return new GuavaCacheBasedLongSupplierMemoizer
<>(cache
, keySupplier
, longSupplier
);
1858 * Memoizes a {@link Predicate} in a Guava {@link Cache}.
1862 * <li>Default cache</li>
1863 * <li>Default cache key</li>
1867 * The {@link Predicate} to memoize.
1868 * @return The wrapped {@link Predicate}.
1870 public static final <INPUT
> Predicate
<INPUT
> predicate(
1871 final Predicate
<INPUT
> predicate
) {
1872 return predicate(predicate
, CacheBuilder
.newBuilder().build());
1877 * Memoizes a {@link Predicate} in a Guava {@link Cache}.
1881 * <li>Custom cache</li>
1882 * <li>Default cache key</li>
1886 * The {@link Predicate} to memoize.
1888 * The {@link Cache} to use.
1889 * @return The wrapped {@link Predicate}.
1891 public static final <INPUT
> Predicate
<INPUT
> predicate(
1892 final Predicate
<INPUT
> predicate
,
1893 final Cache
<INPUT
, Boolean
> cache
) {
1894 return predicate(predicate
, identity(), cache
);
1899 * Memoizes a {@link Predicate} in a Guava {@link Cache}.
1903 * <li>Default cache</li>
1904 * <li>Custom cache key</li>
1908 * The {@link Predicate} to memoize.
1909 * @param keyFunction
1910 * The {@link Function} to compute the cache key.
1911 * @return The wrapped {@link Predicate}.
1913 public static final <INPUT
, KEY
> Predicate
<INPUT
> predicate(
1914 final Predicate
<INPUT
> predicate
,
1915 final Function
<INPUT
, KEY
> keyFunction
) {
1916 return predicate(predicate
, keyFunction
, CacheBuilder
.newBuilder().build());
1921 * Memoizes a {@link Predicate} in a Guava {@link Cache}.
1925 * <li>Custom cache</li>
1926 * <li>Custom cache key</li>
1930 * The {@link Predicate} to memoize.
1931 * @param keyFunction
1932 * The {@link Function} to compute the cache key.
1934 * The {@link Cache} to use.
1935 * @return The wrapped {@link Predicate}.
1937 public static final <INPUT
, KEY
> Predicate
<INPUT
> predicate(
1938 final Predicate
<INPUT
> predicate
,
1939 final Function
<INPUT
, KEY
> keyFunction
,
1940 final Cache
<KEY
, Boolean
> cache
) {
1941 return new GuavaCacheBasedPredicateMemoizer
<>(cache
, keyFunction
, predicate
);
1946 * Memoizes a {@link Supplier} in a Guava {@link Cache}.
1950 * <li>Default cache</li>
1951 * <li>Default cache key</li>
1955 * The {@link Supplier} to memoize.
1956 * @return The wrapped {@link Supplier}.
1958 public static final <OUTPUT
> Supplier
<OUTPUT
> supplier(final Supplier
<OUTPUT
> supplier
) {
1959 return supplier(supplier
, CacheBuilder
.newBuilder().build());
1964 * Memoizes a {@link Supplier} in a Guava {@link Cache}.
1968 * <li>Custom cache</li>
1969 * <li>Default cache key</li>
1973 * The {@link Supplier} to memoize.
1975 * The {@link Cache} to use.
1976 * @return The wrapped {@link Supplier}.
1978 public static final <OUTPUT
> Supplier
<OUTPUT
> supplier(
1979 final Supplier
<OUTPUT
> supplier
,
1980 final Cache
<String
, OUTPUT
> cache
) {
1981 return supplier(supplier
, defaultKeySupplier(), cache
);
1986 * Memoizes a {@link Supplier} in a Guava {@link Cache}.
1990 * <li>Default cache</li>
1991 * <li>Custom cache key</li>
1995 * The {@link Supplier} to memoize.
1996 * @param keySupplier
1997 * The {@link Supplier} for the cache key.
1998 * @return The wrapped {@link Supplier}.
2000 public static final <KEY
, OUTPUT
> Supplier
<OUTPUT
> supplier(
2001 final Supplier
<OUTPUT
> supplier
,
2002 final Supplier
<KEY
> keySupplier
) {
2003 return supplier(supplier
, keySupplier
, CacheBuilder
.newBuilder().build());
2008 * Memoizes a {@link Supplier} in a Guava {@link Cache}.
2012 * <li>Custom cache</li>
2013 * <li>Custom cache key</li>
2017 * The {@link Supplier} to memoize.
2018 * @param keySupplier
2019 * The {@link Supplier} for the cache key.
2021 * The {@link Cache} to use.
2022 * @return The wrapped {@link Supplier}.
2024 public static final <KEY
, OUTPUT
> Supplier
<OUTPUT
> supplier(
2025 final Supplier
<OUTPUT
> supplier
,
2026 final Supplier
<KEY
> keySupplier
,
2027 final Cache
<KEY
, OUTPUT
> cache
) {
2028 return new GuavaCacheBasedSupplierMemoizer
<>(cache
, keySupplier
, supplier
);