Class Values
- java.lang.Object
-
- org.glassfish.jersey.internal.util.collection.Values
-
public final class Values extends java.lang.Object
A collection ofValue provider
factory & utility methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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>
-
Field Summary
Fields Modifier and Type Field Description private static LazyValue
EMPTY
private static LazyUnsafeValue
EMPTY_UNSAFE
-
Constructor Summary
Constructors Modifier Constructor Description private
Values()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Value<T>
eager(Value<T> delegate)
Get a new eagerly initializedvalue provider
.static <T> Value<T>
empty()
static <T,E extends java.lang.Throwable>
UnsafeValue<T,E>emptyUnsafe()
static <T,E extends java.lang.Throwable>
LazyUnsafeValue<T,E>lazy(UnsafeValue<T,E> delegate)
Get a new lazily initializedunsafe value provider
.static <T> LazyValue<T>
lazy(Value<T> delegate)
Get a new lazily initializedvalue provider
.static <T> Value<T>
of(T value)
Get a new constantvalue provider
whoseget()
method always returns the instance supplied to thevalue
parameter.static <T,E extends java.lang.Throwable>
UnsafeValue<T,E>throwing(E throwable)
Get a new "throwing"unsafe value provider
whoseget()
method always throws the exception supplied to thethrowable
parameter.static <T,E extends java.lang.Throwable>
UnsafeValue<T,E>unsafe(T value)
Get a new constantvalue provider
whoseget()
method always returns the instance supplied to thevalue
parameter.
-
-
-
Field Detail
-
EMPTY
private static final LazyValue EMPTY
-
EMPTY_UNSAFE
private static final LazyUnsafeValue EMPTY_UNSAFE
-
-
Method Detail
-
empty
public static <T> Value<T> empty()
- Type Parameters:
T
- value type.- Returns:
- empty value provider.
-
emptyUnsafe
public static <T,E extends java.lang.Throwable> UnsafeValue<T,E> emptyUnsafe()
- Type Parameters:
T
- value type.- Returns:
- empty unsafe value provider.
-
of
public static <T> Value<T> of(T value)
Get a new constantvalue provider
whoseget()
method always returns the instance supplied to thevalue
parameter. In case the supplied value constant isnull
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
value
- value instance to be provided.- Returns:
- constant value provider.
-
unsafe
public static <T,E extends java.lang.Throwable> UnsafeValue<T,E> unsafe(T value)
Get a new constantvalue provider
whoseget()
method always returns the instance supplied to thevalue
parameter. In case the supplied value constant isnull
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
value
- value instance to be provided.- Returns:
- constant value provider.
-
throwing
public static <T,E extends java.lang.Throwable> UnsafeValue<T,E> throwing(E throwable)
Get a new "throwing"unsafe value provider
whoseget()
method always throws the exception supplied to thethrowable
parameter. In case the supplied throwable isnull
, anNullPointerException
is thrown.- Type Parameters:
T
- value type.E
- exception type.- Parameters:
throwable
- throwable instance to be thrown.- Returns:
- "throwing" unsafe value provider.
- Throws:
java.lang.NullPointerException
- in case the supplied throwable instance isnull
.
-
lazy
public static <T> LazyValue<T> lazy(Value<T> delegate)
Get a new lazily initializedvalue provider
. The value returned by itsget()
method is lazily retrieved during a first call to the method from the supplieddelegate
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 supplieddelegate
value provider instance at most once.If the supplied value provider is
null
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
delegate
- value provider delegate that will be used to lazily initialize the value provider.- Returns:
- lazily initialized value provider.
-
eager
public static <T> Value<T> eager(Value<T> delegate)
Get a new eagerly initializedvalue provider
. The value returned by itsget()
method is eagerly computed from the supplieddelegate
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 supplieddelegate
value provider instance once and only once.If the supplied value provider is
null
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
delegate
- value provider delegate that will be used to eagerly initialize the value provider.- Returns:
- eagerly initialized, constant value provider.
-
lazy
public static <T,E extends java.lang.Throwable> LazyUnsafeValue<T,E> lazy(UnsafeValue<T,E> delegate)
Get a new lazily initializedunsafe value provider
. The value returned by itsget()
method is lazily retrieved during a first call to the method from the supplieddelegate
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 supplieddelegate
value provider instance at most once.If the supplied value provider is
null
, anempty
value provider is returned.- Type Parameters:
T
- value type.- Parameters:
delegate
- value provider delegate that will be used to lazily initialize the value provider.- Returns:
- lazily initialized value provider.
-
-