use of com.cronutils.model.definition.CronConstraint 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;
}
Aggregations