net.sf.aguacate.configuration.field.FieldFloat Maven / Gradle / Ivy
package net.sf.aguacate.configuration.field;
import java.math.BigDecimal;
import net.sf.aguacate.validator.ValidationConversionResult;
public class FieldFloat extends FieldNumber {
private final BigDecimal minValue;
private final BigDecimal maxValue;
public FieldFloat(String name, boolean optional, String minValue, String maxValue) {
super(name, Field.FLOAT, optional);
this.minValue = new BigDecimal(minValue);
this.maxValue = new BigDecimal(maxValue);
}
@Override
public ValidationConversionResult validateAndConvert(Object value) {
if (value.getClass() == String.class) {
try {
return validate(minValue, new BigDecimal((String) value), maxValue);
} catch (NumberFormatException e) {
return new ValidationConversionResult("Invalid format");
}
} else {
return new ValidationConversionResult("Invalid value");
}
}
}