removed the special treatment of NotEmptyValidation

This commit is contained in:
2016-08-09 17:25:05 +02:00
parent 3ebf78805c
commit b79a20201e
14 changed files with 31 additions and 16 deletions

View File

@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.matchRegexp;
/**
* Checks if the value is alpha numeric
*/
public class AlphaNumericValidation implements Validation {
public class AlphaNumericValidation extends EmptyAllowedValidation {
@Override
public void check(int row, String value, ValidationError error) {
if (!matchRegexp(value, "[0-9a-zA-Z]*")) {
@@ -42,4 +42,6 @@ public class AlphaNumericValidation implements Validation {
public Type getType() {
return Type.ALPHANUMERIC;
}
}

View File

@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.isDate;
/**
* Checks if the date has the right format
*/
public class DateValidation implements Validation {
public class DateValidation extends EmptyAllowedValidation {
private String dateformat;

View File

@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.isDouble;
/**
* Checks if the value is a double
*/
public class DoubleValidation implements Validation {
public class DoubleValidation extends EmptyAllowedValidation {
@Override
public void check(int row, String value, ValidationError error) {

View File

@@ -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();
}
}

View File

@@ -33,7 +33,7 @@ import org.codehaus.groovy.control.CompilationFailedException;
/**
* Executes the given groovy as check
*/
public class GroovyValidation implements Validation {
public class GroovyValidation extends EmptyAllowedValidation {
private String groovyScript;
private GroovyShell shell = new GroovyShell();

View File

@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.isInt;
/**
* Checks if the value is an integer
*/
public class IntegerValidation implements Validation {
public class IntegerValidation extends EmptyAllowedValidation {
@Override
public void check(int row, String value, ValidationError error) {

View File

@@ -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
*/
public class MaxLengthValidation implements Validation {
public class MaxLengthValidation extends EmptyAllowedValidation {
private int maxLength;

View File

@@ -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
*/
public class MinLengthValidation implements Validation {
public class MinLengthValidation extends EmptyAllowedValidation {
private int minLength;

View File

@@ -43,4 +43,9 @@ public class NotEmptyValidation implements Validation {
public Type getType() {
return Type.NOT_EMPTY;
}
@Override
public boolean canBeChecked(String value) {
return true;
}
}

View File

@@ -30,7 +30,7 @@ import static org.apache.commons.validator.GenericValidator.matchRegexp;
/**
* Checks the value against the given reg exp
*/
public class RegExpValidation implements Validation {
public class RegExpValidation extends EmptyAllowedValidation {
private String regexp;

View File

@@ -30,7 +30,7 @@ import java.util.HashMap;
/**
* 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<>();

View File

@@ -33,4 +33,5 @@ public interface Validation {
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);
Type getType();
boolean canBeChecked(String value);
}

View File

@@ -86,13 +86,8 @@ public class Validator {
Map<Validation.Type, Validation> validationMap = columnValidationMap.get(column);
if (validationMap != null) {
for (Validation validation: validationMap.values()) {
if (validation.getType() == Validation.Type.NOT_EMPTY) {
if (validation.canBeChecked(value)) {
validation.check(row, value, error);
} else {
if (value != null && !value.isEmpty()) {
validation.check(row, value, error);
}
}
}
}

View File

@@ -32,7 +32,7 @@ import static java.util.stream.Collectors.joining;
/**
* 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;