All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.uci.qa.performancedriver.result.GenericResultFactory Maven / Gradle / Ivy

The newest version!
package edu.uci.qa.performancedriver.result;

import java.lang.reflect.InvocationTargetException;

import edu.uci.qa.performancedriver.thread.ResultId;

public class GenericResultFactory implements ResultFactory {
  private final Class clzz;
  
  // TODO: Check for public access (or give itself access)
  
  public GenericResultFactory(Class clzz) {
    this.clzz = clzz;
    try {
      clzz.getConstructor(ResultId.class);
    } catch (NoSuchMethodException | SecurityException e) {
      throw new IllegalArgumentException("Result class must have a 1 arg ResultId constructor"
          + " in order to use the GenericResultFactory!");
    }
  }
  
  @Override
  public T create(ResultId id) {
    try {
      return clzz.getConstructor(ResultId.class).newInstance(id);
    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException 
        | InvocationTargetException | NoSuchMethodException | SecurityException e) {
      throw new RuntimeException(e);
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy