From a5435c6b5fe8d5f0595ca97c16efd1303810fdc8 Mon Sep 17 00:00:00 2001 From: Andreas Billmann Date: Thu, 17 Dec 2015 23:55:08 +0100 Subject: [PATCH] support double value validation --- .../ninja/javafx/smartcsv/validation/Validator.java | 10 ++++++++++ .../ninja/javafx/smartcsv/fx/smartcsv.properties | 1 + .../ninja/javafx/smartcsv/fx/smartcsv_de.properties | 1 + .../javafx/smartcsv/validation/ValidatorTest.java | 3 +++ 4 files changed, 15 insertions(+) diff --git a/src/main/java/ninja/javafx/smartcsv/validation/Validator.java b/src/main/java/ninja/javafx/smartcsv/validation/Validator.java index 51e5b55..ec394d4 100644 --- a/src/main/java/ninja/javafx/smartcsv/validation/Validator.java +++ b/src/main/java/ninja/javafx/smartcsv/validation/Validator.java @@ -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) { diff --git a/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv.properties b/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv.properties index 3361793..4c232f5 100644 --- a/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv.properties +++ b/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv.properties @@ -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 diff --git a/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv_de.properties b/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv_de.properties index 471ce9a..e4af204 100644 --- a/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv_de.properties +++ b/src/main/resources/ninja/javafx/smartcsv/fx/smartcsv_de.properties @@ -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" diff --git a/src/test/java/ninja/javafx/smartcsv/validation/ValidatorTest.java b/src/test/java/ninja/javafx/smartcsv/validation/ValidatorTest.java index 354c80b..729ab0f 100644 --- a/src/test/java/ninja/javafx/smartcsv/validation/ValidatorTest.java +++ b/src/test/java/ninja/javafx/smartcsv/validation/ValidatorTest.java @@ -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 },