public class Lazy<T> extends Object implements Supplier<T>
Supplier
returning the produced object for
subsequent lookups. Note, that no concurrency control is applied during the lookup of get()
, which means in
concurrent access scenarios, the provided Supplier
can be called multiple times.Constructor and Description |
---|
Lazy(Supplier<? extends T> supplier)
Deprecated.
prefer
of(Supplier) , to be turned private in 2.5. |
Modifier and Type | Method and Description |
---|---|
static <T> Lazy<T> |
empty()
Creates a pre-resolved empty
Lazy . |
boolean |
equals(Object o) |
<S> Lazy<S> |
flatMap(Function<? super T,Lazy<? extends S>> function)
|
T |
get()
Returns the value created by the configured
Supplier . |
T |
getNullable()
Returns the value of the lazy evaluation.
|
Optional<T> |
getOptional()
|
int |
hashCode() |
<S> Lazy<S> |
map(Function<? super T,? extends S> function)
|
static <T> Lazy<T> |
of(Supplier<? extends T> supplier)
Creates a new
Lazy to produce an object lazily. |
static <T> Lazy<T> |
of(T value)
Creates a new
Lazy to return the given value. |
Lazy<T> |
or(Supplier<? extends T> supplier)
Returns a new Lazy that will consume the given supplier in case the current one does not yield in a result.
|
Lazy<T> |
or(T value)
Returns a new Lazy that will return the given value in case the current one does not yield in a result.
|
T |
orElse(T value)
Returns the value of the lazy computation or the given default value in case the computation yields
null.
|
@Deprecated public Lazy(Supplier<? extends T> supplier)
of(Supplier)
, to be turned private in 2.5.Lazy
instance for the given supplier.supplier
- public static <T> Lazy<T> of(Supplier<? extends T> supplier)
Lazy
to produce an object lazily.T
- the type of which to produce an object of eventually.supplier
- the Supplier
to create the object lazily.public static <T> Lazy<T> of(T value)
Lazy
to return the given value.T
- the type of the value to return eventually.value
- the value to return.public T get()
Supplier
. Will return the calculated instance for subsequent
lookups.public Optional<T> getOptional()
Optional
value created by the configured Supplier
, allowing the absence of values in
contrast to get()
. Will return the calculated instance for subsequent lookups.public Lazy<T> or(Supplier<? extends T> supplier)
supplier
- must not be null.public Lazy<T> or(T value)
supplier
- must not be null.@Nullable public T orElse(@Nullable T value)
value
- public <S> Lazy<S> map(Function<? super T,? extends S> function)
function
- must not be null.public <S> Lazy<S> flatMap(Function<? super T,Lazy<? extends S>> function)
function
- must not be null.@Nullable public T getNullable()
Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.