T - the generic type of the provided valuepublic class MuleLazyValue<T> extends Object implements Supplier<T>
The value is only computed on the first invokation of get(). Subsequent calls to such method will always return the
same value.
This class is thread-safe. When invoking get(), it is guaranteed that the value will be computed only once.
| Constructor and Description |
|---|
MuleLazyValue(Supplier<T> supplier)
Creates a new instance which lazily obtains its value from the given
supplier. |
MuleLazyValue(T value)
Creates a new instance which is already initialised with the given
value. |
| Modifier and Type | Method and Description |
|---|---|
<R> R |
flatMap(Function<T,R> function)
Applies the given
function through the output of get(). |
T |
get()
Returns the lazy value.
|
void |
ifComputed(Consumer<T> consumer)
If the value has already been computed, if passes it to the given
consumer. |
boolean |
isComputed() |
public MuleLazyValue(Supplier<T> supplier)
supplier. It is guaranteed that
Supplier.get() will only be invoked once. Because this class is thread-safe, the supplier is not required to be.supplier - A Supplier through which the value is obtainedpublic MuleLazyValue(T value)
value.value - the initialization valuepublic T get()
public boolean isComputed()
public void ifComputed(Consumer<T> consumer)
consumer.
This method does not perform any synchronization so keep in mind that dirty reads are possible if this method is being called
from one thread while another thread is triggering the value's computationconsumer - a Consumerpublic <R> R flatMap(Function<T,R> function)
function through the output of get().
If the value has not already been computed, this method will trigger computation. This method is thread-safe.R - the generic type of the function's outputfunction - a transformation functionCopyright © 2021 MuleSoft, Inc.. All rights reserved.