com.google.common.base
Class Suppliers

java.lang.Object
  extended by com.google.common.base.Suppliers

public final class Suppliers
extends Object

Useful Suppliers

Author:
Laurence Gonsalves, Harry Heymann

Nested Class Summary
static class Suppliers.CyclicDependencyException
          Exception thrown when a memoizing Supplier tries to get its own value.
 
Method Summary
static
<K,V> Supplier<V>
compose(Function<K,V> function, Supplier<? extends K> first)
          Returns a new Supplier which is the composition of the Function function and the Supplier first.
static
<T> Supplier<T>
memoize(Supplier<T> delegate)
          Returns a Supplier which delegates to the given Supplier on the first call to get(), records the value returned, and returns this recorded value on all subsequent calls to get().
static
<T> Supplier<T>
ofInstance(T instance)
          Returns a Supplier that always supplies instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compose

public static <K,V> Supplier<V> compose(Function<K,V> function,
                                        Supplier<? extends K> first)
Returns a new Supplier which is the composition of the Function function and the Supplier first. In other words, this new Supplier's value will be computed by retrieving the value from first, and then applying function to that value. Note that the resulting Supplier will not force first (or invoke function) until it is, itself, forced.


memoize

public static <T> Supplier<T> memoize(Supplier<T> delegate)
Returns a Supplier which delegates to the given Supplier on the first call to get(), records the value returned, and returns this recorded value on all subsequent calls to get(). See: memoization The returned Supplier will throw CyclicDependencyException if the call to get() tries to get its own value. The returned supplier is not MT-safe.


ofInstance

public static <T> Supplier<T> ofInstance(@Nullable
                                         T instance)
Returns a Supplier that always supplies instance.