@Test public void shouldInstantiateAnObjectFromAGivenClass() { final String type = "STRING"; Configuration conf = new Configuration("No file"); conf.set(type, "java.lang.String"); SingletonsFactory<String> factory = new SingletonsFactory<String>(conf); String singleton = factory.getInstance(type); assertEquals(String.class, singleton.getClass()); }
public T getInstance(String type) { if (!singletons.containsKey(type)) { synchronized (SingletonsFactory.class) { if (!singletons.containsKey(type)) { T singleton = newInstance(type); singletons.put(type, singleton); } } } return singletons.get(type); }
SingletonsFactory { public T getInstance(String type) { if (!singletons.containsKey(type)) { synchronized (SingletonsFactory.class) { if (!singletons.containsKey(type)) { T singleton = newInstance(type); singletons.put(type, singleton); } } } return singletons.get(type); } }
SingletonsFactory { public T getInstance(String type) { if (!singletons.containsKey(type)) { synchronized (SingletonsFactory.class) { if (!singletons.containsKey(type)) { T singleton = newInstance(type); singletons.put(type, singleton); } } } return singletons.get(type); } SingletonsFactory(Configuration classMap); }
SingletonsFactory { public T getInstance(String type) { if (!singletons.containsKey(type)) { synchronized (SingletonsFactory.class) { if (!singletons.containsKey(type)) { T singleton = newInstance(type); singletons.put(type, singleton); } } } return singletons.get(type); } SingletonsFactory(Configuration classMap); T getInstance(String type); }
SingletonsFactory { public T getInstance(String type) { if (!singletons.containsKey(type)) { synchronized (SingletonsFactory.class) { if (!singletons.containsKey(type)) { T singleton = newInstance(type); singletons.put(type, singleton); } } } return singletons.get(type); } SingletonsFactory(Configuration classMap); T getInstance(String type);  }