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, Greg Turnquist
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T> Lazy<T>empty()Creates a pre-resolved emptyLazy.boolean<S> Lazy<S>Creates a newLazywith the givenFunctionlazily applied to the current one.get()Returns the value created by the configuredSupplier.Returns the value of the lazy evaluation.inthashCode()<S> Lazy<S>Creates a newLazywith the givenFunctionlazily applied to the current one.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 newLazythat will consume the given supplier in case the current one does not yield in a result.Returns a newLazythat 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.Returns the value of the lazy computation or the value produced by the givenSupplierin case the original value is null.toString()
- 
Method Details- 
ofCreates a newLazyto produce an object lazily.
- 
ofCreates a newLazyto return the given value.- Type Parameters:
- T- the type of the value to return eventually.
- Parameters:
- value- the value to return.
- Returns:
- a Lazywrappingvalue.
 
- 
emptyCreates a pre-resolved emptyLazy.- Returns:
- an empty Lazy.
- Since:
- 2.1
 
- 
getReturns the value created by the configuredSupplier. Will return the same instance for subsequent lookups.- Specified by:
- getin interface- Supplier<T>
- Returns:
- the value created by the configured Supplier. Will return the same instance for subsequent lookups.
- Throws:
- IllegalStateException- if the resolved value is null.
 
- 
getNullableReturns the value of the lazy evaluation.- Returns:
- the value of the lazy evaluation, can be null.
- Since:
- 2.2
 
- 
getOptional
- 
orReturns a newLazythat will return the given value in case the current one does not yield in a result.- Parameters:
- other- must not be null.
- Returns:
- a new Lazythat will yield its value if present, otherwiseother.
 
- 
orReturns a newLazythat will consume the given supplier in case the current one does not yield in a result.- Parameters:
- supplier- the supplying function that produces a value to be returned, must not be null.
- Returns:
- a new Lazythat will yield its value if present, otherwise the result produced by the supplying function.
 
- 
orElseReturns the value of the lazy computation or the given default value in case the computation yields null.- Parameters:
- other- the value to be returned, if no value is present. May be null.
- Returns:
- the value, if present, otherwise other.
 
- 
orElseGetReturns the value of the lazy computation or the value produced by the givenSupplierin case the original value is null.- Parameters:
- supplier- the supplying function that produces a value to be returned, must not be null.
- Returns:
- the value, if present, otherwise the result produced by the supplying function.
 
- 
mapCreates a newLazywith the givenFunctionlazily applied to the current one.- Parameters:
- function- must not be null.
- Returns:
- an Lazydescribing the result of applying a mapping function to the value of thisLazyor throwingIllegalStateExceptionif theLazyis empty.
 
- 
flatMapCreates a newLazywith the givenFunctionlazily applied to the current one.- Parameters:
- function- must not be null.
- Returns:
- the result of applying an Lazy-bearing mapping function to the value of thisLazyor aLazythrowingIllegalStateExceptionif theLazyis empty.
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
- 
toStringReturns 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
 
 
-