public String getVerifierRule(ConstraintConfiguration config) {
return template.replaceAll("\\{0\\}", String.valueOf(System.nanoTime())).replaceAll("\\{1\\}", config.getFactType()).replaceAll("\\{2\\}", config.getFieldName()).replaceAll("\\{3\\}", this.getMin(config)).replaceAll("\\{4\\}", this.getMax(config));
}
public ValidationResult validate(Object value, ConstraintConfiguration config) {
ValidationResult result = new ValidationResult();
try {
if (value == null || !(value instanceof Number || value instanceof String)) {
result.setSuccess(false);
if (value == null) {
result.setMessage("The value is null"); // TODO: I18N
} else {
result.setMessage("Invalid value type " + value.getClass().getName()); // TODO:
// I18N
}
} else {
double min = Double.parseDouble(getMin(config));
double max = Double.parseDouble(getMax(config));
double d = Double.parseDouble(value.toString());
result.setSuccess(d > min && d < max);
if (!result.isSuccess()) {
result.setMessage("The value should be between " + min + " and " + max); // TODO:
// I18N
}
}
} catch (Throwable t) {
result.setSuccess(false);
result.setMessage(t.getMessage()); // TODO: I18N
}
return result;
}