Top Description Methods
org.apache.logging.log4j.util

public Interface Lazy<T>

extends Supplier<T>
Known Direct Implementers
org.apache.logging.log4j.util.LazyUtil.Constant, org.apache.logging.log4j.util.LazyUtil.WeakConstant, org.apache.logging.log4j.util.LazyUtil.SafeLazy, org.apache.logging.log4j.util.LazyUtil.PureLazy
Type Parameters
<T>
type of value
Imports
java.util.Objects, java.util.function.Function, .Supplier

Provides a lazily-initialized value from a Supplier<T>.

Method Summary

Modifier and TypeMethod and Description
public default T
get()

Implements java.util.function.Supplier.get.

Returns the value held by this lazy.

public boolean
isInitialized()

Indicates whether this lazy value has been initialized.

public static <T> Lazy<T>
lazy(final Supplier<T> supplier)

Creates a strict lazy value using the provided Supplier.

public default <R> Lazy<R>
map(final Function<? super T, ? extends R> function)

Creates a new lazy value derived from this lazy value using the provided value mapping function.

public static <T> Lazy<T>
pure(final Supplier<T> supplier)

Creates a pure lazy value using the provided Supplier to initialize the value.

public void
set(final T newValue)

Sets this lazy value to the provided value.

public T
value()

Returns the value held by this lazy.

public static <T> Lazy<T>
value(final T value)

Creates a lazy value using the provided constant value.

public static <T> Lazy<T>
weak(final T value)

Creates a lazy value using a weak reference to the provided value.

Method Detail

getback to summary
public default T get()

Implements java.util.function.Supplier.get.

Returns the value held by this lazy. This may cause the value to initialize if it hasn't been already.

Returns:T

Doc from java.util.function.Supplier.get.

a result

Annotations
@Override
isInitializedback to summary
public boolean isInitialized()

Indicates whether this lazy value has been initialized.

lazyback to summary
public static <T> Lazy<T> lazy(final Supplier<T> supplier)

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.

mapback to summary
public default <R> Lazy<R> map(final Function<? super T, ? extends R> function)

Creates a new lazy value derived from this lazy value using the provided value mapping function.

pureback to summary
public static <T> Lazy<T> pure(final Supplier<T> supplier)

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.

setback to summary
public void set(final T newValue)

Sets this lazy value to the provided value.

Exceptions
UnsupportedOperationException:
if this type of lazy value cannot be updated
valueback to summary
public T value()

Returns the value held by this lazy. This may cause the value to initialize if it hasn't been already.

valueback to summary
public static <T> Lazy<T> value(final T value)

Creates a lazy value using the provided constant value.

weakback to summary
public static <T> Lazy<T> weak(final T value)

Creates a lazy value using a weak reference to the provided value.