public final class Values
extends java.lang.Object
Value provider factory & utility methods.| Modifier and Type | Class and Description |
|---|---|
private static class |
Values.EagerValue<T> |
private static class |
Values.ExceptionValue<T,E extends java.lang.Throwable> |
private static class |
Values.InstanceUnsafeValue<T,E extends java.lang.Throwable> |
private static class |
Values.InstanceValue<T> |
private static class |
Values.LazyUnsafeValueImpl<T,E extends java.lang.Throwable> |
private static class |
Values.LazyValueImpl<T> |
| Modifier and Type | Field and Description |
|---|---|
private static LazyValue |
EMPTY |
private static LazyUnsafeValue |
EMPTY_UNSAFE |
| Modifier | Constructor and Description |
|---|---|
private |
Values() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Value<T> |
eager(Value<T> delegate)
Get a new eagerly initialized
value provider. |
static <T> Value<T> |
empty()
|
static <T,E extends java.lang.Throwable> |
emptyUnsafe()
|
static <T,E extends java.lang.Throwable> |
lazy(UnsafeValue<T,E> delegate)
Get a new lazily initialized
unsafe value provider. |
static <T> LazyValue<T> |
lazy(Value<T> delegate)
Get a new lazily initialized
value provider. |
static <T> Value<T> |
of(T value)
Get a new constant
value provider whose get()
method always returns the instance supplied to the value parameter. |
static <T,E extends java.lang.Throwable> |
throwing(E throwable)
Get a new "throwing"
unsafe value provider whose get()
method always throws the exception supplied to the throwable parameter. |
static <T,E extends java.lang.Throwable> |
unsafe(T value)
Get a new constant
value provider whose get()
method always returns the instance supplied to the value parameter. |
private static final LazyValue EMPTY
private static final LazyUnsafeValue EMPTY_UNSAFE
public static <T> Value<T> empty()
T - value type.public static <T,E extends java.lang.Throwable> UnsafeValue<T,E> emptyUnsafe()
T - value type.public static <T> Value<T> of(T value)
value provider whose get()
method always returns the instance supplied to the value parameter.
In case the supplied value constant is null, an empty value
provider is returned.T - value type.value - value instance to be provided.public static <T,E extends java.lang.Throwable> UnsafeValue<T,E> unsafe(T value)
value provider whose get()
method always returns the instance supplied to the value parameter.
In case the supplied value constant is null, an empty value
provider is returned.T - value type.value - value instance to be provided.public static <T,E extends java.lang.Throwable> UnsafeValue<T,E> throwing(E throwable)
unsafe value provider whose get()
method always throws the exception supplied to the throwable parameter.
In case the supplied throwable is null, an NullPointerException is thrown.T - value type.E - exception type.throwable - throwable instance to be thrown.java.lang.NullPointerException - in case the supplied throwable instance is null.public static <T> LazyValue<T> lazy(Value<T> delegate)
value provider.
The value returned by its get() method is lazily retrieved during a first
call to the method from the supplied delegate value provider and is then cached for
a subsequent retrieval.
The implementation of the returned lazy value provider is thread-safe and is guaranteed to
invoke the get() method on the supplied delegate value provider instance at
most once.
If the supplied value provider is null, an empty value
provider is returned.
T - value type.delegate - value provider delegate that will be used to lazily initialize the value provider.public static <T> Value<T> eager(Value<T> delegate)
value provider.
The value returned by its get() method is eagerly computed from the supplied
delegate value provider and is then stored in a final field for a subsequent retrieval.
The implementation of the returned eager value provider is thread-safe and is guaranteed to
invoke the get() method on the supplied delegate value provider instance once
and only once.
If the supplied value provider is null, an empty value
provider is returned.
T - value type.delegate - value provider delegate that will be used to eagerly initialize the value provider.public static <T,E extends java.lang.Throwable> LazyUnsafeValue<T,E> lazy(UnsafeValue<T,E> delegate)
unsafe value provider.
The value returned by its get() method is lazily retrieved during a first
call to the method from the supplied delegate value provider and is then cached for
a subsequent retrieval.
In case the call to underlying delegate.get() throws a throwable, the throwable is cached
and thrown on all subsequent retrievals.
The implementation of the returned lazy value provider is thread-safe and is guaranteed to
invoke the get() method on the supplied delegate value provider instance at
most once.
If the supplied value provider is null, an empty value
provider is returned.
T - value type.delegate - value provider delegate that will be used to lazily initialize the value provider.