public final class Suppliers
extends java.lang.Object
Supplier instances| Modifier and Type | Method and Description |
|---|---|
static <S,T> java.util.function.Supplier<T> |
map(java.util.function.Supplier<S> supplier,
java.util.function.Function<S,T> function)
Returns a new supplier which calls the provided supplier and then applies the provided function to map the result
to a new representation.
|
static <T> java.util.function.Supplier<T> |
memoize(java.util.function.Supplier<T> delegate)
Returns a supplier which caches the instance retrieved during the first call to
get() and returns that
value on subsequent calls to get() |
static <T> java.util.function.Supplier<T> |
memoizeWithExpiration(java.util.function.Supplier<T> delegate,
long duration,
java.util.concurrent.TimeUnit unit)
Returns a supplier that caches the instance supplied by the delegate and removes the cached value after the
specified time has passed.
|
static <T> java.util.function.Supplier<T> |
synchronizedSupplier(java.util.function.Supplier<T> delegate) |
public static <S,T> java.util.function.Supplier<T> map(java.util.function.Supplier<S> supplier,
java.util.function.Function<S,T> function)
supplier or invoke
function until it is calledS - Original representation provided via supplierT - Representation to convert the original to when requested via Supplier.get()supplier - Supplier which provides an initial valuefunction - Mapping function which converts the supplied value to a different formfunctionpublic static <T> java.util.function.Supplier<T> memoize(java.util.function.Supplier<T> delegate)
get() and returns that
value on subsequent calls to get()
The returned supplier is thread-safe. The delegate's get() method will be invoked at most once unless the
underlying get() throws an exception
T - Representation supplied by the provided and memoized supplierdelegate - Supplier which will provide values when a valid cached value has not been storedget() and returns that
value on subsequent callspublic static <T> java.util.function.Supplier<T> memoizeWithExpiration(java.util.function.Supplier<T> delegate,
long duration,
java.util.concurrent.TimeUnit unit)
get() return the cached value if the expiration time has
not passed. After the expiration time, a new value is retrieved, cached, and returned
The returned supplier is thread-safe
T - Representation supplied by the provided and memoized supplierdelegate - Supplier which will provide values when a valid cached value has not been stored or has expiredduration - the length of time after a value is created that it should stop being returned by subsequent
get() callsunit - the unit that duration is expressed injava.lang.IllegalArgumentException - if duration is not positivepublic static <T> java.util.function.Supplier<T> synchronizedSupplier(java.util.function.Supplier<T> delegate)
T - Representation supplied by the provided and synchronized supplierdelegate - Supplier to create a thread-safe wrapper arounddelegate before calling its get method, making it
thread-safe