public final class Suppliers
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <F,T> java.util.function.Supplier<T> |
compose(java.util.function.Function<? super F,T> function,
java.util.function.Supplier<F> supplier)
Returns a new supplier which is the composition of the provided function
and supplier.
|
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> |
ofInstance(T instance)
Returns a supplier that always supplies
instance . |
static <T> java.util.function.Function<java.util.function.Supplier<T>,T> |
supplierFunction()
Returns a function that accepts a supplier and returns the result of
invoking
Supplier.get() on that supplier. |
static <T> java.util.function.Supplier<T> |
synchronizedSupplier(java.util.function.Supplier<T> delegate)
Returns a supplier whose
get() method synchronizes on
delegate before calling it, making it thread-safe. |
public static <F,T> java.util.function.Supplier<T> compose(java.util.function.Function<? super F,T> function, java.util.function.Supplier<F> supplier)
supplier
, and then applying
function
to that value. Note that the resulting supplier will not
call supplier
or invoke function
until it is called.public static <T> java.util.function.Supplier<T> memoize(java.util.function.Supplier<T> delegate)
get()
and returns that value on subsequent calls to
get()
. See:
memoization
The returned supplier is thread-safe.
If delegate
is an instance created by an earlier call to memoize
, it is returned directly.
public 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. See:
memoization
The returned supplier is thread-safe.
duration
- 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> ofInstance(@Nullable T instance)
instance
.public static <T> java.util.function.Supplier<T> synchronizedSupplier(java.util.function.Supplier<T> delegate)
get()
method synchronizes on
delegate
before calling it, making it thread-safe.public static <T> java.util.function.Function<java.util.function.Supplier<T>,T> supplierFunction()
Supplier.get()
on that supplier.