Package org.springframework.data.util
Class Lazy<T>
java.lang.Object
org.springframework.data.util.Lazy<T>
- All Implemented Interfaces:
Supplier<T>
Simple value type to delay the creation of an object using a
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.- Since:
- 2.0
- Author:
- Oliver Gierke, Mark Paluch, Henning Rohlfs, Johannes Englmeier
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Lazy<T>
empty()
Creates a pre-resolved emptyLazy
.boolean
<S> Lazy<S>
get()
Returns the value created by the configuredSupplier
.Returns the value of the lazy evaluation.int
hashCode()
<S> Lazy<S>
static <T> Lazy<T>
Creates a newLazy
to produce an object lazily.static <T> Lazy<T>
of
(T value) Creates a newLazy
to return the given value.Returns a new Lazy that will consume the given supplier in case the current one does not yield in a result.Returns a new Lazy that will return the given value in case the current one does not yield in a result.Returns the value of the lazy computation or the given default value in case the computation yields null.
-
Method Details
-
of
Creates a newLazy
to produce an object lazily.- Type Parameters:
T
- the type of which to produce an object of eventually.- Parameters:
supplier
- theSupplier
to create the object lazily.- Returns:
-
of
Creates a newLazy
to return the given value.- Type Parameters:
T
- the type of the value to return eventually.- Parameters:
value
- the value to return.- Returns:
-
empty
Creates a pre-resolved emptyLazy
.- Returns:
- Since:
- 2.1
-
get
Returns the value created by the configuredSupplier
. Will return the calculated instance for subsequent lookups. -
getOptional
Returns theOptional
value created by the configuredSupplier
, allowing the absence of values in contrast toget()
. Will return the calculated instance for subsequent lookups.- Returns:
-
or
Returns a new Lazy that will consume the given supplier in case the current one does not yield in a result.- Parameters:
supplier
- must not be null.- Returns:
-
or
Returns a new Lazy that will return the given value in case the current one does not yield in a result.- Parameters:
value
- must not be null.- Returns:
-
orElse
Returns the value of the lazy computation or the given default value in case the computation yields null.- Parameters:
value
-- Returns:
-
map
- Parameters:
function
- must not be null.- Returns:
-
flatMap
- Parameters:
function
- must not be null.- Returns:
-
getNullable
Returns the value of the lazy evaluation.- Returns:
- Since:
- 2.2
-
equals
-
hashCode
public int hashCode()
-