Package io.fluxcapacitor.common
Class DefaultMemoizingBiFunction<T,U,R>
java.lang.Object
io.fluxcapacitor.common.DefaultMemoizingBiFunction<T,U,R>
- Type Parameters:
T
- the type of the first input argumentU
- the type of the second input argumentR
- the type of the computed result
- All Implemented Interfaces:
MemoizingBiFunction<T,
,U, R> BiFunction<T,
U, R>
A default implementation of the
MemoizingBiFunction
interface that memoizes (caches) results of a
BiFunction
based on a pair of input arguments. Cached results can be reused for identical subsequent
calls, and the cache can optionally be configured with a lifespan and a custom clock for time-based eviction.
This class internally uses a MemoizingFunction
, with the input arguments wrapped as
Map.Entry
for caching purposes.-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMemoizingBiFunction
(BiFunction<T, U, R> delegate) DefaultMemoizingBiFunction
(BiFunction<T, U, R> delegate, Duration lifespan, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears all cached values.void
Applies the given consumer to all currently cached values.boolean
Returnstrue
if the function has already cached a value for the given inputs.Removes the cached result for the given input pair, if present.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.function.BiFunction
andThen
Methods inherited from interface io.fluxcapacitor.common.MemoizingBiFunction
compose
-
Constructor Details
-
DefaultMemoizingBiFunction
-
DefaultMemoizingBiFunction
-
-
Method Details
-
apply
- Specified by:
apply
in interfaceBiFunction<T,
U, R>
-
isCached
Description copied from interface:MemoizingBiFunction
Returnstrue
if the function has already cached a value for the given inputs.- Specified by:
isCached
in interfaceMemoizingBiFunction<T,
U, R>
-
clear
public void clear()Description copied from interface:MemoizingBiFunction
Clears all cached values.- Specified by:
clear
in interfaceMemoizingBiFunction<T,
U, R>
-
remove
Description copied from interface:MemoizingBiFunction
Removes the cached result for the given input pair, if present.- Specified by:
remove
in interfaceMemoizingBiFunction<T,
U, R> - Returns:
- the previously cached result or
null
-
forEach
Description copied from interface:MemoizingBiFunction
Applies the given consumer to all currently cached values.- Specified by:
forEach
in interfaceMemoizingBiFunction<T,
U, R>
-