com.github.rawls238.scientist4j.Result Maven / Gradle / Ivy
package com.github.rawls238.scientist4j;
import com.github.rawls238.scientist4j.exceptions.MismatchException;
import java.util.Map;
import java.util.Optional;
public class Result {
private Experiment experiment;
private Observation control;
private Optional> candidate;
private Optional match;
private Map context;
public Result(Experiment experiment, Observation control, Optional> candidate, Map context) throws MismatchException {
this.experiment = experiment;
this.control = control;
this.candidate = candidate;
this.context = context;
this.match = Optional.empty();
if (candidate.isPresent()) {
Optional ex = Optional.empty();
try {
this.match = Optional.of(experiment.compare(control, candidate.get()));
} catch (MismatchException e) {
ex = Optional.of(e);
this.match = Optional.of(false);
} finally {
if (experiment.getRaiseOnMismatch() && ex.isPresent()) {
throw ex.get();
}
}
}
}
public Optional getMatch() {
return match;
}
public Observation getControl() {
return control;
}
public Optional> getCandidate() {
return candidate;
}
public Map getContext() {
return context;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy