mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
support double value validation
This commit is contained in:
@@ -96,6 +96,7 @@ public class Validator {
|
|||||||
checkInteger(columnConfig, value, error);
|
checkInteger(columnConfig, value, error);
|
||||||
checkGroovy(column, columnConfig, value, error);
|
checkGroovy(column, columnConfig, value, error);
|
||||||
checkValueOf(columnConfig, value, error);
|
checkValueOf(columnConfig, value, error);
|
||||||
|
checkDouble(columnConfig, value, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error.isEmpty()) {
|
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) {
|
private void checkMinLength(Config columnConfig, String value, ValidationError error) {
|
||||||
Integer minLength = getInteger(columnConfig, "minlength");
|
Integer minLength = getInteger(columnConfig, "minlength");
|
||||||
if (minLength != null) {
|
if (minLength != null) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ title.validation.errors = Validation Errors:
|
|||||||
# validaton messages
|
# validaton messages
|
||||||
validation.message.not.empty = should not be empty
|
validation.message.not.empty = should not be empty
|
||||||
validation.message.integer = should be an integer
|
validation.message.integer = should be an integer
|
||||||
|
validation.message.double = should be a double
|
||||||
validation.message.alphanumeric = should be alphanumeric
|
validation.message.alphanumeric = should be alphanumeric
|
||||||
validation.message.groovy.exception = groovy script '{0}' throws exception: {1}
|
validation.message.groovy.exception = groovy script '{0}' throws exception: {1}
|
||||||
validation.message.groovy.return.null = groovy script '{0}' returns null
|
validation.message.groovy.return.null = groovy script '{0}' returns null
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ title.validation.errors = Fehler in der Datei:
|
|||||||
# validaton messages
|
# validaton messages
|
||||||
validation.message.not.empty = Darf nicht leer sein.
|
validation.message.not.empty = Darf nicht leer sein.
|
||||||
validation.message.integer = Muss eine Zahl 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.alphanumeric = Darf nur Zahlen und Buchstaben enthalten.
|
||||||
validation.message.groovy.exception = groovy script '{0}' wirft folgenden Fehler: {1}
|
validation.message.groovy.exception = groovy script '{0}' wirft folgenden Fehler: {1}
|
||||||
validation.message.groovy.return.null = groovy script '{0}' meldet "null"
|
validation.message.groovy.return.null = groovy script '{0}' meldet "null"
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ public class ValidatorTest {
|
|||||||
{ "column", "not empty", true, "column", null, false, new ValidationMessage("validation.message.not.empty") },
|
{ "column", "not empty", true, "column", null, false, new ValidationMessage("validation.message.not.empty") },
|
||||||
{ "column", "integer", true, "column", "999", true, null },
|
{ "column", "integer", true, "column", "999", true, null },
|
||||||
{ "column", "integer", true, "column", "a", false, new ValidationMessage("validation.message.integer") },
|
{ "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", "12", true, null },
|
||||||
{ "column", "minlength", 2, "column", "1", false, new ValidationMessage("validation.message.min.length", "2") },
|
{ "column", "minlength", 2, "column", "1", false, new ValidationMessage("validation.message.min.length", "2") },
|
||||||
{ "column", "maxlength", 2, "column", "12", true, null },
|
{ "column", "maxlength", 2, "column", "12", true, null },
|
||||||
|
|||||||
Reference in New Issue
Block a user