T
- result type of the evaluationpublic interface Lazy<T>
extends java.util.function.Supplier<T>
The underlying value is only created if the Supplier.get()
method is called the first time.
Later calls will return the value created on the first call.
Modifier and Type | Method and Description |
---|---|
static <V> Lazy<V> |
from(ReferenceType referenceType,
java.util.function.Supplier<? extends V> supplier)
Helper method allowing to define the type of the reference
which holds the value after it is provided by the supplier.
|
static <V> Lazy<V> |
from(java.util.function.Supplier<? extends V> supplier)
Create a lazy evaluation from a supplier.
|
static <V> Lazy<V> |
fromFragile(FragileFunction0<? extends V,?> fragileSupplier)
Create a lazy evaluation from a fragile supplier.
|
static <V> Lazy<V> |
softFrom(java.util.function.Supplier<? extends V> supplier)
Create a lazy evaluation from a fragile supplier,
but reference the value internally only via a soft reference.
|
static <V> Lazy<V> |
softFromFragile(FragileFunction0<? extends V,?> fragileSupplier)
Create a lazy evaluation from a fragile supplier,
but reference the value internally only via a soft reference.
|
static <V> Lazy<V> |
weakFrom(java.util.function.Supplier<? extends V> supplier)
Create a lazy evaluation from a fragile supplier,
but reference the value internally only via a weak reference.
|
static <V> Lazy<V> |
weakFromFragile(FragileFunction0<? extends V,?> fragileSupplier)
Create a lazy evaluation from a fragile supplier,
but reference the value internally only via a weak reference.
|
static <V> java.util.function.Supplier<V> |
wrapFragile(FragileFunction0<? extends V,?> fragileSupplier)
Wrap a fragile supplier to be fragile no longer.
|
@NotNull static <V> Lazy<V> from(@NotNull java.util.function.Supplier<? extends V> supplier)
Supplier.get()
.V
- value type the lazy evaluation will providesupplier
- The supplier which creates the value.
Will only be called at most once.@NotNull static <V> Lazy<V> fromFragile(@NotNull FragileFunction0<? extends V,?> fragileSupplier)
Supplier.get()
method of the returned
Lazy
will throw a LazyEvalutionFailure
.V
- value type of the returned lazy evaluatorfragileSupplier
- supplier which might throw a checked exception@NotNull static <V> Lazy<V> from(@NotNull ReferenceType referenceType, @NotNull java.util.function.Supplier<? extends V> supplier)
V
- value type of the returned lazy evaluatorreferenceType
- reference type used for keeping the valuesupplier
- the value supplier, which might be called more than once depending on referenceType
@NotNull static <V> Lazy<V> softFrom(@NotNull java.util.function.Supplier<? extends V> supplier)
This allows the value to be garbage-collected when it is no longer used elsewhere, with the cost of creating it again if it is requested afterward.
V
- value type of the returned lazy evaluatorsupplier
- supplier which is possibly called more than once,
so it should be idempotentSoftReference
@NotNull static <V> Lazy<V> softFromFragile(@NotNull FragileFunction0<? extends V,?> fragileSupplier)
This allows the value to be garbage-collected when it is no longer used elsewhere, with the cost of creating it again if it is requested afterward.
V
- value type of the returned lazy evaluatorfragileSupplier
- supplier which is possibly called more than once,
so it should be idempotentSoftReference
@NotNull static <V> Lazy<V> weakFrom(@NotNull java.util.function.Supplier<? extends V> supplier)
This allows the value to be garbage-collected when it is no longer used elsewhere, with the cost of creating it again if it is requested afterward.
V
- value type of the returned lazy evaluatorsupplier
- supplier which is possibly called more than once,
so it should be idempotentWeakReference
@NotNull static <V> Lazy<V> weakFromFragile(@NotNull FragileFunction0<? extends V,?> fragileSupplier)
This allows the value to be garbage-collected when it is no longer used elsewhere, with the cost of creating it again if it is requested afterward.
V
- value type of the returned lazy evaluatorfragileSupplier
- supplier which is possibly called more than once,
so it should be idempotentWeakReference
@NotNull static <V> java.util.function.Supplier<V> wrapFragile(@NotNull FragileFunction0<? extends V,?> fragileSupplier)
V
- type of supplied valuefragileSupplier
- fragile supplierLazyEvalutionFailure
if
the original fragileSupplier
throws an exception