this.magnitudeValueValidator = new MagnitudeValueValidator(
new InclusiveRangePredicate(-10, 25));
}
public Magnitude validate(String str) throws ObservationValidationError {
Magnitude mag = null;
String[] fields = this.regexValidator.validate(str);
// Here we determine the parts present in the magnitude field.
// The magnitude value itself is non-optional whereas the magnitude
// modifier (fainter/brighter-than) and uncertainty parts are both
// optional, so we test for combinations of these two optional parts.
double magnitude = this.magnitudeValueValidator
.validate(fields[MAG_INDEX]);
if (fields[MAG_MODIFIER_INDEX] != null
&& fields[UNCERTAINTY_INDEX] != null) {
// All 3 parts are present.
mag = new Magnitude(magnitude,
getMagModValue(fields[MAG_MODIFIER_INDEX]),
Magnitude.IS_UNCERTAIN);
} else if (fields[MAG_MODIFIER_INDEX] != null
&& fields[UNCERTAINTY_INDEX] == null) {
// Magnitude modifier and magnitude parts are present.
mag = new Magnitude(magnitude,
getMagModValue(fields[MAG_MODIFIER_INDEX]),
!Magnitude.IS_UNCERTAIN);
} else if (fields[MAG_MODIFIER_INDEX] == null
&& fields[UNCERTAINTY_INDEX] != null) {
// Magnitude and uncertainty parts are present.
mag = new Magnitude(magnitude, MagnitudeModifier.NO_DELTA,
Magnitude.IS_UNCERTAIN);
} else if (fields[MAG_MODIFIER_INDEX] == null
&& fields[UNCERTAINTY_INDEX] == null) {
// Only the magnitude part is present.
mag = new Magnitude(magnitude, MagnitudeModifier.NO_DELTA,
!Magnitude.IS_UNCERTAIN);
}
return mag;
}