T
- Type of the value to lazy initialize@FunctionalInterface public interface Initializer<T>
Modifier and Type | Method and Description |
---|---|
T |
get()
Gets the value, initializing it if the value is not already initialized before returning to caller.
|
static <T> T |
init(T value,
Supplier<T> initializer)
Lazy initializing method using given
initializer to initialize the value if given value
is null . |
static <T> Initializer<T> |
using(Supplier<T> initializer)
|
T get()
static <T> Initializer<T> using(Supplier<T> initializer)
Initializer
using given initializer
Supplier
for value initialization.
The returned Initializer
is thread-safe, ensuring that the initializer Supplier
is called exactly
one time following one or several calls of get()
by any number of threads.
T
- Type of the value to lazy initializeinitializer
- Supplier to initialize the value. Must never return null
.Initializer
instancestatic <T> T init(T value, Supplier<T> initializer)
initializer
to initialize the value if given value
is null
.T
- Type of the value to lazy initializevalue
- Value to return if not null
initializer
- Supplier to initialize the value. Must never return null
.value
if not null
, or the initialized value using
Supplier.get()
method of given initializer
Copyright © 2019 The Holon Platform. All rights reserved.