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.inthashCode()<S> Lazy<S>static <T> Lazy<T>Creates a newLazyto produce an object lazily.static <T> Lazy<T>of(T value) Creates a newLazyto 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.toString()
-
Method Details
-
of
Creates a newLazyto produce an object lazily.- Type Parameters:
T- the type of which to produce an object of eventually.- Parameters:
supplier- theSupplierto create the object lazily.- Returns:
-
of
Creates a newLazyto 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 theOptionalvalue 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:
-
toString
Returns theStringrepresentation of the already resolved value or the one provided through the givenSupplierif the value has not been resolved yet.- Parameters:
fallback- must not be null.- Returns:
- will never be null.
- Since:
- 3.0.1
-
getNullable
Returns the value of the lazy evaluation.- Returns:
- Since:
- 2.2
-
toString
-
equals
-
hashCode
public int hashCode()
-