public class LazyLong extends Object implements LongSupplier
The value is only computed on the first invokation of getAsLong() ()}. Subsequent calls to such method will always
return the same value.
This class is thread-safe. When invoking getAsLong() ()}, it is guaranteed that the value will be computed only once.
| Constructor and Description |
|---|
LazyLong(long value)
Creates a new instance which is already initialised with the given
value. |
LazyLong(LongSupplier supplier)
Creates a new instance which lazily obtains its value from the given
supplier. |
| Modifier and Type | Method and Description |
|---|---|
<R> R |
flatMap(Function<Long,R> function)
Applies the given
function through the output of getAsLong() ()}. |
long |
getAsLong()
Returns the lazy value.
|
void |
ifComputed(LongConsumer consumer)
If the value has already been computed, if passes it to the given
consumer. |
boolean |
isComputed() |
public LazyLong(LongSupplier supplier)
supplier. It is guaranteed that
Supplier.get() will only be invoked once. Because this class is thread-safe, the supplier is not required to be.supplier - A Supplier through which the value is obtainedpublic LazyLong(long value)
value.value - the initialization valuepublic long getAsLong()
getAsLong in interface LongSupplierpublic boolean isComputed()
public void ifComputed(LongConsumer consumer)
consumer.
This method does not perform any synchronization so keep in mind that dirty reads are possible if this method is being called
from one thread while another thread is triggering the value's computationconsumer - a Consumerpublic <R> R flatMap(Function<Long,R> function)
function through the output of getAsLong() ()}.
If the value has not already been computed, this method will trigger computation. This method is thread-safe.R - the generic type of the function's outputfunction - a transformation functionCopyright © 2025 MuleSoft, Inc.. All rights reserved.