Class CachingSupplier<T>
- java.lang.Object
-
- io.axoniq.dataprotection.serialization.CachingSupplier<T>
-
- All Implemented Interfaces:
Serializable,Supplier<T>
public class CachingSupplier<T> extends Object implements Supplier<T>, Serializable
A Supplier that caches its result, useful if the supplier operation is expensive and expected to always yield the same result. This supplier can be used concurrently by multiple threads.- Author:
- Rene de Waele
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()static <T> CachingSupplier<T>of(Supplier<T> supplier)Factory method for aCachingSupplierthat delegates to the givensupplierwhen asked to supply a value.static <T> CachingSupplier<T>of(T value)Factory method for aCachingSupplierthat will supply the givenvalue.
-
-
-
Method Detail
-
of
public static <T> CachingSupplier<T> of(T value)
Factory method for aCachingSupplierthat will supply the givenvalue. This factory method should be used when the value is already available. Used this way this supplier can be serialized.- Type Parameters:
T- the type of results supplied by this supplier- Parameters:
value- the value to supply- Returns:
- a
CachingSupplierthat supplies the given value
-
of
public static <T> CachingSupplier<T> of(Supplier<T> supplier)
Factory method for aCachingSupplierthat delegates to the givensupplierwhen asked to supply a value. If the givensupplieris aCachingSupplierthe instance is returned as is, if not a newCachingSupplierinstance is created.- Type Parameters:
T- the type of results supplied by this supplier- Parameters:
supplier- supplier for which to cache the result- Returns:
- a
CachingSupplierbased on givensupplier
-
-