Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package uk.sponte.automation.seleniumpom.dependencies;
 
 import  org.openqa.selenium.WebDriver;
 
Created by n450777 on 07/04/15.
 
    private final HashMap<Class<?>, DependencyFactory<?>> factoryMapping = new HashMap<Class<?>, DependencyFactory<?>>();
    public DefaultDependencyInjectorImpl() {
        registerFactory(WebDriver.classnew WebDriverFactory());
    }
    public <T> void registerFactory(Class<T> klassDependencyFactory<T> factory) {
        this..put(klassfactory);
    }
    @Override
    public <T> T get(Class<T> klass) {
        try {
            if(.containsKey(klass)) {
                Object objectInstance = .get(klass).get();
                return klass.cast(objectInstance);
            }
            return klass.newInstance();
        } catch (InstantiationException e) {
            throw new InjectionError(e.getCause());
        } catch(IllegalAccessException e) {
            throw new InjectionError(e.getCause());
        }
    }
New to GrepCode? Check out our FAQ X