T - type of referencepublic class LazyAtomicReference<T> extends Object implements CallableRaisingIOE<T>, Supplier<T>
CallableRaisingIOE so
may raise IOExceptions.
This constructor is only invoked on demand
when the reference is first needed,
after which the same value is returned.
This value MUST NOT be null.
Implements CallableRaisingIOE and java.util.function.Supplier.
An instance of this can therefore be used in a functional IO chain.
As such, it can act as a delayed and caching invocator of a function:
the supplier passed in is only ever invoked once, and only when requested.
| Constructor and Description |
|---|
LazyAtomicReference(CallableRaisingIOE<? extends T> constructor)
Constructor for this instance.
|
| Modifier and Type | Method and Description |
|---|---|
T |
apply()
Implementation of
CallableRaisingIOE.apply(). |
T |
eval()
Get the value, constructing it if needed.
|
T |
get()
Implementation of
Supplier.get(). |
protected CallableRaisingIOE<? extends T> |
getConstructor()
Getter for the constructor.
|
protected AtomicReference<T> |
getReference()
Get the reference.
|
boolean |
isSet()
Is the reference set?
|
static <T> LazyAtomicReference<T> |
lazyAtomicReferenceFromSupplier(Supplier<T> supplier)
Create from a supplier.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waituncheckedpublic LazyAtomicReference(CallableRaisingIOE<? extends T> constructor)
constructor - method to invoke to actually construct the inner object.protected CallableRaisingIOE<? extends T> getConstructor()
protected AtomicReference<T> getReference()
public T eval() throws IOException
IOException - on any evaluation failureNullPointerException - if the evaluated function returned null.public final T apply() throws IOException
CallableRaisingIOE.apply().
Invoke eval().apply in interface CallableRaisingIOE<T>IOException - on any evaluation failurepublic final T get() throws UncheckedIOException
Supplier.get().
Invoke eval() and convert IOEs to
UncheckedIOException.
This is the Supplier.get() implementation, which allows
this class to passed into anything taking a supplier.
get in interface Supplier<T>UncheckedIOException - if the constructor raised an IOException.public final boolean isSet()
public static <T> LazyAtomicReference<T> lazyAtomicReferenceFromSupplier(Supplier<T> supplier)
T - type of referencesupplier - supplier implementation.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.