org.testatoo.config
Class SingletonProvider<T>

java.lang.Object
  extended by org.testatoo.config.SingletonProvider<T>
All Implemented Interfaces:
Provider<T>

public abstract class SingletonProvider<T>
extends java.lang.Object
implements Provider<T>

Wrapper for Provider which returns always the same instance, as a singleton

Example:

Provider<Container> singleton = SingletonProvider.from(container);


Constructor Summary
SingletonProvider()
           
 
Method Summary
protected abstract  T create()
           
static
<T> SingletonProvider<T>
from(Provider<T> provider)
          Wrap the given Provider to return always the same instance all the time.
 T get()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingletonProvider

public SingletonProvider()
Method Detail

get

public final T get()
Specified by:
get in interface Provider<T>
Returns:
an instance of the given type. To create a singleton provider, you can use SingletonProvider

create

protected abstract T create()

from

public static <T> SingletonProvider<T> from(Provider<T> provider)
Wrap the given Provider to return always the same instance all the time. like a singleton.

Type Parameters:
T - Type of object returned
Parameters:
provider - The provider to wrap
Returns:
A Provider that will always returns the same instance


Copyright © 2008-2010 Ovea. All Rights Reserved.