org.glassfish.jersey.internal.util.collection
Class Values

java.lang.Object
  extended by org.glassfish.jersey.internal.util.collection.Values

public final class Values
extends Object

A collection of Value provider factory & utility methods.

Author:
Marek Potociar (marek.potociar at oracle.com)

Method Summary
static
<T> Value<T>
empty()
          Get an empty value provider whose get() method always returns null.
static
<T,E extends Throwable>
UnsafeValue<T,E>
emptyUnsafe()
          Get an empty value provider whose get() method always returns null.
static
<T,E extends Throwable>
UnsafeValue<T,E>
lazy(UnsafeValue<T,E> delegate)
          Get a new lazily initialized unsafe value provider.
static
<T> Value<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 Throwable>
UnsafeValue<T,E>
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 Throwable>
UnsafeValue<T,E>
unsafe(T value)
          Get a new constant value provider whose get() method always returns the instance supplied to the value parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

empty

public static <T> Value<T> empty()
Get an empty value provider whose get() method always returns null.

Type Parameters:
T - value type.
Returns:
empty value provider.

emptyUnsafe

public static <T,E extends Throwable> UnsafeValue<T,E> emptyUnsafe()
Get an empty value provider whose get() method always returns null.

Type Parameters:
T - value type.
Returns:
empty unsafe value provider.

of

public 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. In case the supplied value constant is null, an empty 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 Throwable> UnsafeValue<T,E> unsafe(T value)
Get a new constant 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.

Type Parameters:
T - value type.
Parameters:
value - value instance to be provided.
Returns:
constant value provider.

throwing

public static <T,E extends Throwable> UnsafeValue<T,E> throwing(E throwable)
                                                   throws NullPointerException
Get a new "throwing" 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.

Type Parameters:
T - value type.
E - exception type.
Parameters:
throwable - throwable instance to be thrown.
Returns:
"throwing" unsafe value provider.
Throws:
NullPointerException - in case the supplied throwable instance is null.

lazy

public static <T> Value<T> lazy(Value<T> delegate)
Get a new lazily initialized 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.

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.

lazy

public static <T,E extends Throwable> UnsafeValue<T,E> lazy(UnsafeValue<T,E> delegate)
Get a new lazily initialized 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.

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.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.