diff options
Diffstat (limited to 'pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java')
-rw-r--r-- | pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java new file mode 100644 index 00000000..8cca9230 --- /dev/null +++ b/pdf-over/pdf-signer-interface/src/main/java/at/asit/pdfover/pdfsignator/profileproperties/validators/FloatRangeValidator.java @@ -0,0 +1,57 @@ +package at.asit.pdfover.pdfsignator.profileproperties.validators; + +import at.asit.pdfover.pdfsignator.InvalidPropertyTypeException; +import at.asit.pdfover.pdfsignator.InvalidPropertyValueException; +import at.asit.pdfover.pdfsignator.profileproperties.FloatProfileProperty; +import at.asit.pdfover.pdfsignator.profileproperties.ProfileProperty; + +public class FloatRangeValidator extends PropertyValidator { + + /** + * The maximum value + */ + protected float max; + + /** + * The minimum value + */ + protected float min; + + /** + * Constructor + * @param min The minimum allowed value + * @param max The maximum allowed value + */ + public FloatRangeValidator(float min, float max) { + this.max = max; + this.min = min; + } + + @Override + public void validate(ProfileProperty property) + throws InvalidPropertyValueException, InvalidPropertyTypeException { + this.CheckPropertyType(property); + + FloatProfileProperty prop = (FloatProfileProperty) property; + + if (prop.GetValue() == null) { + throw new InvalidPropertyValueException(property, + "Value is not set!"); + } + + float value = prop.GetValue(); + + if (value < min || value > max) { + throw new InvalidPropertyValueException(property, String.format( + "Value has to be between %f and %f", min, max)); + } + } + + @Override + public void CheckPropertyType(ProfileProperty property) + throws InvalidPropertyTypeException { + if (!(property instanceof FloatProfileProperty)) { + throw new InvalidPropertyTypeException(property, this); + } + } +} |