T - type of referencejava.util.function.Supplier<T>, CallableRaisingIOE<T>LazyAutoCloseableReferencepublic class LazyAtomicReference<T> extends java.lang.Object implements CallableRaisingIOE<T>, java.util.function.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 | Description |
|---|---|
LazyAtomicReference(CallableRaisingIOE<? extends T> constructor) |
Constructor for this instance.
|
| Modifier and Type | Method | 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 java.util.concurrent.atomic.AtomicReference<T> |
getReference() |
Get the reference.
|
boolean |
isSet() |
Is the reference set?
|
static <T> LazyAtomicReference<T> |
lazyAtomicReferenceFromSupplier(java.util.function.Supplier<T> supplier) |
Create from a supplier.
|
java.lang.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 java.util.concurrent.atomic.AtomicReference<T> getReference()
public T eval() throws java.io.IOException
java.io.IOException - on any evaluation failurejava.lang.NullPointerException - if the evaluated function returned null.public final T apply() throws java.io.IOException
CallableRaisingIOE.apply().
Invoke eval().apply in interface CallableRaisingIOE<T>java.io.IOException - on any evaluation failurepublic final T get() throws java.io.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 java.util.function.Supplier<T>java.io.UncheckedIOException - if the constructor raised an IOException.public final boolean isSet()
public java.lang.String toString()
toString in class java.lang.Objectpublic static <T> LazyAtomicReference<T> lazyAtomicReferenceFromSupplier(java.util.function.Supplier<T> supplier)
T - type of referencesupplier - supplier implementation.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.