All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.aguacate.configuration.field.FieldFloat Maven / Gradle / Ivy

There is a newer version: 0.10.9
Show newest version
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");
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy