Class DefaultMemoizingBiFunction<T,U,R>
java.lang.Object
io.fluxzero.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 TypeMethodDescriptionvoidclear()Clears all cached values.voidApplies the given consumer to all currently cached values.booleanReturnstrueif 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiFunction
andThenMethods inherited from interface MemoizingBiFunction
compose
-
Constructor Details
-
DefaultMemoizingBiFunction
-
DefaultMemoizingBiFunction
-
-
Method Details
-
apply
-
isCached
Description copied from interface:MemoizingBiFunctionReturnstrueif the function has already cached a value for the given inputs.- Specified by:
isCachedin interfaceMemoizingBiFunction<T,U, R>
-
clear
public void clear()Description copied from interface:MemoizingBiFunctionClears all cached values.- Specified by:
clearin interfaceMemoizingBiFunction<T,U, R>
-
remove
Description copied from interface:MemoizingBiFunctionRemoves the cached result for the given input pair, if present.- Specified by:
removein interfaceMemoizingBiFunction<T,U, R> - Returns:
- the previously cached result or
null
-
forEach
Description copied from interface:MemoizingBiFunctionApplies the given consumer to all currently cached values.- Specified by:
forEachin interfaceMemoizingBiFunction<T,U, R>
-