mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
little performance optimization (less method calls)
This commit is contained in:
@@ -73,32 +73,27 @@ public class ValidationConfiguration {
|
||||
}
|
||||
|
||||
public Integer getMaxLengthRuleFor(String column) {
|
||||
if (noRulesFor(column)) return null;
|
||||
return doubleToInteger((Double)getValue(column, "maxlength"));
|
||||
Double value = (Double)getValue(column, "maxlength");
|
||||
return value != null ? doubleToInteger(value) : null;
|
||||
}
|
||||
|
||||
public String getDateRuleFor(String column) {
|
||||
if (noRulesFor(column)) return null;
|
||||
return (String)getValue(column, "date");
|
||||
}
|
||||
|
||||
public Boolean getAlphanumericRuleFor(String column) {
|
||||
if (noRulesFor(column)) return null;
|
||||
return (Boolean)getValue(column, "alphanumeric");
|
||||
}
|
||||
|
||||
public String getRegexpRuleFor(String column) {
|
||||
if (noRulesFor(column)) return null;
|
||||
return (String)getValue(column, "regexp");
|
||||
}
|
||||
|
||||
public List<String> getValueOfRuleFor(String column) {
|
||||
if (noRulesFor(column)) return null;
|
||||
return (List<String>)getValue(column, "value of");
|
||||
}
|
||||
|
||||
public String getGroovyRuleFor(String column) {
|
||||
if (noRulesFor(column)) return null;
|
||||
return (String)getValue(column, "groovy");
|
||||
}
|
||||
|
||||
@@ -160,18 +155,19 @@ public class ValidationConfiguration {
|
||||
}
|
||||
|
||||
private Object getValue(String column, String key) {
|
||||
if (noRulesFor(column)) return null;
|
||||
return columnConfigurations.get(column).get(key);
|
||||
if (columnConfigurations != null) {
|
||||
Map rulesForColumn = columnConfigurations.get(column);
|
||||
if (rulesForColumn != null) {
|
||||
return columnConfigurations.get(column).get(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean noHeader() {
|
||||
return headerConfiguration == null;
|
||||
}
|
||||
|
||||
private boolean noRulesFor(String column) {
|
||||
return columnConfigurations == null || columnConfigurations.get(column) == null;
|
||||
}
|
||||
|
||||
private Integer doubleToInteger(Double value) {
|
||||
if (value == null) return null;
|
||||
return (int)Math.round(value);
|
||||
|
||||
@@ -111,7 +111,8 @@ public class Validator {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void checkUniqueness(String column, String value, Integer lineNumber, ValidationError error) {
|
||||
if (validationConfig.getUniqueRuleFor(column) != null && validationConfig.getUniqueRuleFor(column)) {
|
||||
Boolean uniqueRule = validationConfig.getUniqueRuleFor(column);
|
||||
if (uniqueRule != null && uniqueRule) {
|
||||
HashMap<String, Integer> columnValueMap = uniquenessLookupTable.get(column);
|
||||
columnValueMap = getColumnValueMap(column, columnValueMap);
|
||||
Integer valueInLineNumber = columnValueMap.get(value);
|
||||
@@ -180,7 +181,8 @@ public class Validator {
|
||||
}
|
||||
|
||||
private void checkBlankOrNull(String column, String value, ValidationError error) {
|
||||
if (validationConfig.getNotEmptyRuleFor(column) != null && validationConfig.getNotEmptyRuleFor(column)) {
|
||||
Boolean notEmptyRule = validationConfig.getNotEmptyRuleFor(column);
|
||||
if (notEmptyRule != null && notEmptyRule) {
|
||||
if (isBlankOrNull(value)) {
|
||||
error.add("validation.message.not.empty");
|
||||
}
|
||||
@@ -188,7 +190,8 @@ public class Validator {
|
||||
}
|
||||
|
||||
private void checkInteger(String column, String value, ValidationError error) {
|
||||
if (validationConfig.getIntegerRuleFor(column) != null && validationConfig.getIntegerRuleFor(column)) {
|
||||
Boolean integerRule = validationConfig.getIntegerRuleFor(column);
|
||||
if (integerRule != null && integerRule) {
|
||||
if (!isInt(value)) {
|
||||
error.add("validation.message.integer");
|
||||
}
|
||||
@@ -196,7 +199,8 @@ public class Validator {
|
||||
}
|
||||
|
||||
private void checkDouble(String column, String value, ValidationError error) {
|
||||
if (validationConfig.getDoubleRuleFor(column) != null && validationConfig.getDoubleRuleFor(column)) {
|
||||
Boolean doubleRule = validationConfig.getDoubleRuleFor(column);
|
||||
if (doubleRule != null && doubleRule) {
|
||||
if (!isDouble(value)) {
|
||||
error.add("validation.message.double");
|
||||
}
|
||||
@@ -231,7 +235,8 @@ public class Validator {
|
||||
}
|
||||
|
||||
private void checkAlphaNumeric(String column, String value, ValidationError error) {
|
||||
if (validationConfig.getAlphanumericRuleFor(column) != null && validationConfig.getAlphanumericRuleFor(column)) {
|
||||
Boolean alphaNumericRule = validationConfig.getAlphanumericRuleFor(column);
|
||||
if (alphaNumericRule != null && alphaNumericRule) {
|
||||
if (!matchRegexp(value, "[0-9a-zA-Z]*")) {
|
||||
error.add("validation.message.alphanumeric");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user