package de.wwwu.awolf.presenter.evaluation; import de.wwwu.awolf.model.Line; import de.wwwu.awolf.model.evaluation.ComparisonResult; import de.wwwu.awolf.presenter.algorithms.Algorithm; import de.wwwu.awolf.presenter.algorithms.AlgorithmHandler; import java.util.List; import java.util.Set; import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class AlgorithmComparison { private final List types; private final ExecutorService executorService; private final CompletionService completionService; private final Set lines; public AlgorithmComparison(List types, Set lines) { this.types = types; this.lines = lines; this.executorService = Executors.newFixedThreadPool(3); completionService = new ExecutorCompletionService<>(this.executorService); } public ComparisonResult compare() { ComparisonResult comparisonResult = new ComparisonResult(); AlgorithmHandler algorithmHandler = AlgorithmHandler.getInstance(); for (Algorithm.Type value : getTypes()) { Algorithm.Type type; synchronized (types) { type = value; } Line line = algorithmHandler.runAlgorithmByType(type, lines); comparisonResult.put(type, line); } return comparisonResult; } private List getTypes() { return types; } }