T - type of wrapped valuepublic class Lazy<T> extends java.lang.Object implements Value<T>
Lazy is intended as wrapper for lazily initialized objects.
It wraps an initialization method, which is called only once the value() method is invoked
(so it might be never called at all).
If initialization method provided a value, this value is cached an returned with every following value() call
and the initialization will be never triggered again.
In case the initialization resulted in an Exception then the Lazy is being considered uninitialized
and the following value() call will result into invoking the initialization method again.
This can be repeated until the initialization method is successful.| Constructor and Description |
|---|
Lazy(java.util.concurrent.Callable<T> valueProvider)
Constructor of
Lazy with value initialization method |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isInitialized()
Provides info if a successful initialization has already occurred
and the value has been initialized/cached.
|
static <T> Lazy<T> |
lazy(java.util.concurrent.Callable<T> valueProvider)
Factory method for Lazy value
|
<T2> Lazy<T2> |
map(java.util.function.Function<? super T,? extends T2> mapper)
Creates a derived
Lazy value by mapping currently wrapped value into a new one. |
T |
value()
If
Lazy is not yet initialized call, calls initialization and caches and returns its result. |
public Lazy(java.util.concurrent.Callable<T> valueProvider)
Lazy with value initialization methodvalueProvider - initialization methodjava.lang.IllegalArgumentException - if null is passed as input parameterpublic static <T> Lazy<T> lazy(java.util.concurrent.Callable<T> valueProvider)
valueProvider - initialization methodLazy valuepublic boolean isInitialized()
public T value() throws InitializationFailedException
Lazy is not yet initialized call, calls initialization and caches and returns its result.
If initialization was successful then on second call only the cached value is returned
and the initialization is NOT executed anymore.
In case the initialization has failed with any Exception
an InitializationFailedException is thrown and the Lazy is considered to be
not initialized.
Subsequent call of this method after failure will execution initialization again.
This can be repeated until the initialization is finally successful.value in interface Value<T>InitializationFailedException - wrapping Exception that occurred during initialization failurepublic <T2> Lazy<T2> map(java.util.function.Function<? super T,? extends T2> mapper)
Lazy value by mapping currently wrapped value into a new one.
Call to this operation does not change the state of this Lazy value, so if it was not initialized before
it stays un-initialized. If it was initialized it stays initialized.T2 - the type of generated valuemapper - function to map the wrapped value into a new oneLazy value generated via the mapping function