use of com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor in project cron-utils by jmrozanec.
the class SingleCron method validate.
/**
* Validates this Cron instance by validating its cron expression.
*
* @return this Cron instance
* @throws IllegalArgumentException if the cron expression is invalid
*/
public Cron validate() {
for (final Map.Entry<CronFieldName, CronField> field : retrieveFieldsAsMap().entrySet()) {
final CronFieldName fieldName = field.getKey();
field.getValue().getExpression().accept(new ValidationFieldExpressionVisitor(getCronDefinition().getFieldDefinition(fieldName).getConstraints()));
}
for (final CronConstraint constraint : getCronDefinition().getCronConstraints()) {
if (!constraint.validate(this)) {
throw new IllegalArgumentException(String.format("Invalid cron expression: %s. %s", asString(), constraint.getDescription()));
}
}
return this;
}
use of com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor in project cron-utils by jmrozanec.
the class CronBuilder method addField.
@VisibleForTesting
CronBuilder addField(final CronFieldName name, final FieldExpression expression) {
checkState(definition != null, "CronBuilder not initialized.");
final FieldDefinition fieldDefinition = definition.getFieldDefinition(name);
checkState(fieldDefinition != null, "Cron field definition does not exist: %s", name);
final FieldConstraints constraints = fieldDefinition.getConstraints();
expression.accept(new ValidationFieldExpressionVisitor(constraints));
fields.put(name, new CronField(name, expression, constraints));
return this;
}
Aggregations