Package org.apache.logging.log4j.util
Interface Lazy<T>
- Type Parameters:
T
- type of value
- All Superinterfaces:
Supplier<T>
Provides a lazily-initialized value from a
Supplier<T>
.- Since:
- 2.22.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault T
get()
Returns the value held by this lazy.boolean
Indicates whether this lazy value has been initialized.static <T> Lazy<T>
Creates a strict lazy value using the provided Supplier.default <R> Lazy<R>
Creates a new lazy value derived from this lazy value using the provided value mapping function.static <T> Lazy<T>
Creates a pure lazy value using the provided Supplier to initialize the value.void
Sets this lazy value to the provided value.value()
Returns the value held by this lazy.static <T> Lazy<T>
value
(T value) Creates a lazy value using the provided constant value.static <T> Lazy<T>
weak
(T value) Creates a lazy value using a weak reference to the provided value.
-
Method Details
-
value
T value()Returns the value held by this lazy. This may cause the value to initialize if it hasn't been already. -
get
Returns the value held by this lazy. This may cause the value to initialize if it hasn't been already. -
map
Creates a new lazy value derived from this lazy value using the provided value mapping function. -
isInitialized
boolean isInitialized()Indicates whether this lazy value has been initialized. -
set
Sets this lazy value to the provided value.- Throws:
UnsupportedOperationException
- if this type of lazy value cannot be updated
-
lazy
Creates a strict lazy value using the provided Supplier. The supplier is guaranteed to only be invoked by at most one thread, and all threads will see the same published value when this returns. -
value
Creates a lazy value using the provided constant value. -
weak
Creates a lazy value using a weak reference to the provided value. -
pure
Creates a pure lazy value using the provided Supplier to initialize the value. The supplier may be invoked more than once, and the return value should be a purely computed value as the result may be a different instance each time. This is useful for building cache tables and other pure computations.
-