Class Values
Value provider
factory & utility methods.- Author:
- Marek Potociar
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Value
<T> Get a new eagerly initializedvalue provider
.static <T> Value
<T> empty()
static <T> LazyValue
<T> Get a new lazily initializedvalue provider
.static <T> Value
<T> of
(T value) Get a new constantvalue provider
whoseget()
method always returns the instance supplied to thevalue
parameter.
-
Method Details
-
empty
- Type Parameters:
T
- value type.- Returns:
- empty value provider.
-
of
Get a new constant
value provider
whoseget()
method always returns the instance supplied to thevalue
parameter.In case the supplied value constant is
null
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
value
- value instance to be provided.- Returns:
- constant value provider.
-
lazy
Get a new lazily initializedvalue provider
.The value returned by its
get()
method is lazily retrieved during a first call to the method from the supplieddelegate
value provider and is then cached for a subsequent retrieval.The implementation of the returned lazy value provider is thread-safe and is guaranteed to invoke the
get()
method on the supplieddelegate
value provider instance at most once.If the supplied value provider is
null
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
delegate
- value provider delegate that will be used to lazily initialize the value provider.- Returns:
- lazily initialized value provider.
-
eager
Get a new eagerly initializedvalue provider
.The value returned by its
get()
method is eagerly computed from the supplieddelegate
value provider and is then stored in a final field for a subsequent retrieval.The implementation of the returned eager value provider is thread-safe and is guaranteed to invoke the
get()
method on the supplieddelegate
value provider instance once and only once.If the supplied value provider is
null
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
delegate
- value provider delegate that will be used to eagerly initialize the value provider.- Returns:
- eagerly initialized, constant value provider.
-