edu.kit.ifv.mobitopp.result.ResultRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mobitopp Show documentation
Show all versions of mobitopp Show documentation
mobiTopp (http://mobitopp.ifv.kit.edu/) is an agent-based travel demand model developed at the Institute for transport studies at the Karlsruhe Institute of Technology (http://www.ifv.kit.edu/english/index.php). Publications about mobiTopp can be found on the project site (http://mobitopp.ifv.kit.edu/28.php).
The newest version!
package edu.kit.ifv.mobitopp.result;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
public class ResultRepository {
private final Map outputs;
private final Function factory;
public ResultRepository(Function factory) {
super();
this.outputs = new HashMap<>();
this.factory = factory;
}
public ResultOutput fileFor(Category category) {
ensureOutputIsAvailableFor(category);
return outputs.get(category);
}
private void ensureOutputIsAvailableFor(Category category) {
if (misses(category)) {
outputs.put(category, factory.apply(category));
}
}
private boolean misses(Category category) {
return !outputs.containsKey(category);
}
public void close() throws IOException {
for (ResultOutput output : outputs.values()) {
output.close();
}
}
}