mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
removed the special treatment of NotEmptyValidation
This commit is contained in:
@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.matchRegexp;
|
|||||||
/**
|
/**
|
||||||
* Checks if the value is alpha numeric
|
* Checks if the value is alpha numeric
|
||||||
*/
|
*/
|
||||||
public class AlphaNumericValidation implements Validation {
|
public class AlphaNumericValidation extends EmptyAllowedValidation {
|
||||||
@Override
|
@Override
|
||||||
public void check(int row, String value, ValidationError error) {
|
public void check(int row, String value, ValidationError error) {
|
||||||
if (!matchRegexp(value, "[0-9a-zA-Z]*")) {
|
if (!matchRegexp(value, "[0-9a-zA-Z]*")) {
|
||||||
@@ -42,4 +42,6 @@ public class AlphaNumericValidation implements Validation {
|
|||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.ALPHANUMERIC;
|
return Type.ALPHANUMERIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.isDate;
|
|||||||
/**
|
/**
|
||||||
* Checks if the date has the right format
|
* Checks if the date has the right format
|
||||||
*/
|
*/
|
||||||
public class DateValidation implements Validation {
|
public class DateValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
private String dateformat;
|
private String dateformat;
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.isDouble;
|
|||||||
/**
|
/**
|
||||||
* Checks if the value is a double
|
* Checks if the value is a double
|
||||||
*/
|
*/
|
||||||
public class DoubleValidation implements Validation {
|
public class DoubleValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check(int row, String value, ValidationError error) {
|
public void check(int row, String value, ValidationError error) {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package ninja.javafx.smartcsv.validation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by abi on 09.08.2016.
|
||||||
|
*/
|
||||||
|
public abstract class EmptyAllowedValidation implements Validation {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeChecked(String value) {
|
||||||
|
return value != null && !value.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ import org.codehaus.groovy.control.CompilationFailedException;
|
|||||||
/**
|
/**
|
||||||
* Executes the given groovy as check
|
* Executes the given groovy as check
|
||||||
*/
|
*/
|
||||||
public class GroovyValidation implements Validation {
|
public class GroovyValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
private String groovyScript;
|
private String groovyScript;
|
||||||
private GroovyShell shell = new GroovyShell();
|
private GroovyShell shell = new GroovyShell();
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.isInt;
|
|||||||
/**
|
/**
|
||||||
* Checks if the value is an integer
|
* Checks if the value is an integer
|
||||||
*/
|
*/
|
||||||
public class IntegerValidation implements Validation {
|
public class IntegerValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check(int row, String value, ValidationError error) {
|
public void check(int row, String value, ValidationError error) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.maxLength;
|
|||||||
/**
|
/**
|
||||||
* Checks if the value is shorter or exactly as long as the given max length
|
* Checks if the value is shorter or exactly as long as the given max length
|
||||||
*/
|
*/
|
||||||
public class MaxLengthValidation implements Validation {
|
public class MaxLengthValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
private int maxLength;
|
private int maxLength;
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.minLength;
|
|||||||
/**
|
/**
|
||||||
* Checks if the value is at minimum long as the given min length
|
* Checks if the value is at minimum long as the given min length
|
||||||
*/
|
*/
|
||||||
public class MinLengthValidation implements Validation {
|
public class MinLengthValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
private int minLength;
|
private int minLength;
|
||||||
|
|
||||||
|
|||||||
@@ -43,4 +43,9 @@ public class NotEmptyValidation implements Validation {
|
|||||||
public Type getType() {
|
public Type getType() {
|
||||||
return Type.NOT_EMPTY;
|
return Type.NOT_EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeChecked(String value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.matchRegexp;
|
|||||||
/**
|
/**
|
||||||
* Checks the value against the given reg exp
|
* Checks the value against the given reg exp
|
||||||
*/
|
*/
|
||||||
public class RegExpValidation implements Validation {
|
public class RegExpValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
private String regexp;
|
private String regexp;
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import java.util.HashMap;
|
|||||||
/**
|
/**
|
||||||
* Checks if the value is unique in the column
|
* Checks if the value is unique in the column
|
||||||
*/
|
*/
|
||||||
public class UniqueValidation implements Validation {
|
public class UniqueValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
private HashMap<String, Integer> columnValueMap = new HashMap<>();
|
private HashMap<String, Integer> columnValueMap = new HashMap<>();
|
||||||
|
|
||||||
|
|||||||
@@ -33,4 +33,5 @@ public interface Validation {
|
|||||||
enum Type { NOT_EMPTY, UNIQUE, DOUBLE, INTEGER, MIN_LENGTH, MAX_LENGTH, DATE, ALPHANUMERIC, REGEXP, VALUE_OF, GROOVY }
|
enum Type { NOT_EMPTY, UNIQUE, DOUBLE, INTEGER, MIN_LENGTH, MAX_LENGTH, DATE, ALPHANUMERIC, REGEXP, VALUE_OF, GROOVY }
|
||||||
void check(int row, String value, ValidationError error);
|
void check(int row, String value, ValidationError error);
|
||||||
Type getType();
|
Type getType();
|
||||||
|
boolean canBeChecked(String value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,13 +86,8 @@ public class Validator {
|
|||||||
Map<Validation.Type, Validation> validationMap = columnValidationMap.get(column);
|
Map<Validation.Type, Validation> validationMap = columnValidationMap.get(column);
|
||||||
if (validationMap != null) {
|
if (validationMap != null) {
|
||||||
for (Validation validation: validationMap.values()) {
|
for (Validation validation: validationMap.values()) {
|
||||||
|
if (validation.canBeChecked(value)) {
|
||||||
if (validation.getType() == Validation.Type.NOT_EMPTY) {
|
|
||||||
validation.check(row, value, error);
|
validation.check(row, value, error);
|
||||||
} else {
|
|
||||||
if (value != null && !value.isEmpty()) {
|
|
||||||
validation.check(row, value, error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import static java.util.stream.Collectors.joining;
|
|||||||
/**
|
/**
|
||||||
* Checks if the value is part of a list of values
|
* Checks if the value is part of a list of values
|
||||||
*/
|
*/
|
||||||
public class ValueOfValidation implements Validation {
|
public class ValueOfValidation extends EmptyAllowedValidation {
|
||||||
|
|
||||||
private List<String> values;
|
private List<String> values;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user