support double value validation

This commit is contained in:
Andreas Billmann
2015-12-17 23:55:08 +01:00
parent a67937a262
commit a5435c6b5f
4 changed files with 15 additions and 0 deletions

View File

@@ -96,6 +96,7 @@ public class Validator {
checkInteger(columnConfig, value, error);
checkGroovy(column, columnConfig, value, error);
checkValueOf(columnConfig, value, error);
checkDouble(columnConfig, value, error);
}
if (!error.isEmpty()) {
@@ -174,6 +175,15 @@ public class Validator {
}
}
private void checkDouble(Config columnConfig, String value, ValidationError error) {
if (getBoolean(columnConfig, "double")) {
if (!isDouble(value)) {
error.add("validation.message.double");
}
}
}
private void checkMinLength(Config columnConfig, String value, ValidationError error) {
Integer minLength = getInteger(columnConfig, "minlength");
if (minLength != null) {

View File

@@ -12,6 +12,7 @@ title.validation.errors = Validation Errors:
# validaton messages
validation.message.not.empty = should not be empty
validation.message.integer = should be an integer
validation.message.double = should be a double
validation.message.alphanumeric = should be alphanumeric
validation.message.groovy.exception = groovy script '{0}' throws exception: {1}
validation.message.groovy.return.null = groovy script '{0}' returns null

View File

@@ -20,6 +20,7 @@ title.validation.errors = Fehler in der Datei:
# validaton messages
validation.message.not.empty = Darf nicht leer sein.
validation.message.integer = Muss eine Zahl sein.
validation.message.double = Muss eine Gleitkommazahl sein
validation.message.alphanumeric = Darf nur Zahlen und Buchstaben enthalten.
validation.message.groovy.exception = groovy script '{0}' wirft folgenden Fehler: {1}
validation.message.groovy.return.null = groovy script '{0}' meldet "null"

View File

@@ -89,6 +89,9 @@ public class ValidatorTest {
{ "column", "not empty", true, "column", null, false, new ValidationMessage("validation.message.not.empty") },
{ "column", "integer", true, "column", "999", true, null },
{ "column", "integer", true, "column", "a", false, new ValidationMessage("validation.message.integer") },
{ "column", "double", true, "column", "999", true, null },
{ "column", "double", true, "column", "999.000", true, null },
{ "column", "double", true, "column", "a", false, new ValidationMessage("validation.message.double") },
{ "column", "minlength", 2, "column", "12", true, null },
{ "column", "minlength", 2, "column", "1", false, new ValidationMessage("validation.message.min.length", "2") },
{ "column", "maxlength", 2, "column", "12", true, null },