private void runExperiment(String experimentCode) { Class experimentClass = Arrays.stream(experimentsAvailable) .filter( (Class<? extends BaseExperiment> filteredexperimentClass) -> { try { return filteredexperimentClass .getConstructor() .newInstance() .getCodeName() .compareTo(experimentCode) == 0; } catch (Exception ex) { Logger.getLogger(Runner.class.getName()).log(Level.SEVERE, null, ex); } return false; }) .findFirst() .orElse(null); if (experimentClass != null) { try { BaseExperiment experiment = (BaseExperiment) experimentClass.getConstructor().newInstance(); experiment.run(arguments); } catch (Exception ex) { Logger.getLogger(Runner.class.getName()).log(Level.SEVERE, null, ex); } } }
private void printExperimentList() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Experiment list:\n"); Arrays.stream(experimentsAvailable) .forEach( (experimentClass) -> { try { BaseExperiment experiment = (BaseExperiment) experimentClass.getConstructor().newInstance(); String line = experiment.getCodeName() + ": " + experiment.getDescription(); stringBuilder.append("\t" + line + "\n"); } catch (Exception e) { } }); System.out.println(stringBuilder.toString()); }