use of com.cronutils.model.field.constraint.FieldConstraints in project cron-utils by jmrozanec.
the class ExecutionTimeBuilder method build.
protected ExecutionTime build() {
boolean lowestAssigned = false;
if (seconds == null) {
seconds = timeNodeLowest(CronFieldName.SECOND, 0, 59);
} else {
lowestAssigned = true;
}
if (minutes == null) {
minutes = lowestAssigned ? timeNodeAlways(CronFieldName.MINUTE, 0, 59) : timeNodeLowest(CronFieldName.MINUTE, 0, 59);
} else {
lowestAssigned = true;
}
if (hours == null) {
hours = lowestAssigned ? timeNodeAlways(CronFieldName.HOUR, 0, 23) : timeNodeLowest(CronFieldName.HOUR, 0, 23);
} else {
lowestAssigned = true;
}
if (daysOfMonthCronField == null) {
final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_MONTH);
daysOfMonthCronField = lowestAssigned ? new CronField(CronFieldName.DAY_OF_MONTH, always(), constraints) : new CronField(CronFieldName.DAY_OF_MONTH, new On(new IntegerFieldValue(1)), constraints);
} else {
lowestAssigned = true;
}
if (daysOfWeekCronField == null) {
final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_WEEK);
daysOfWeekCronField = lowestAssigned ? new CronField(CronFieldName.DAY_OF_WEEK, always(), constraints) : new CronField(CronFieldName.DAY_OF_WEEK, new On(new IntegerFieldValue(1)), constraints);
} else {
lowestAssigned = true;
}
if (months == null) {
months = lowestAssigned ? timeNodeAlways(CronFieldName.MONTH, 1, 12) : timeNodeLowest(CronFieldName.MONTH, 1, 12);
}
if (yearsValueGenerator == null) {
yearsValueGenerator = FieldValueGeneratorFactory.forCronField(new CronField(CronFieldName.YEAR, always(), getConstraint(CronFieldName.YEAR)));
}
if (daysOfYearCronField == null) {
final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_YEAR);
daysOfYearCronField = new CronField(CronFieldName.DAY_OF_YEAR, lowestAssigned ? FieldExpression.questionMark() : always(), constraints);
}
return new SingleExecutionTime(this.cron.getCronDefinition(), this.cron.retrieve(CronFieldName.YEAR), daysOfWeekCronField, daysOfMonthCronField, daysOfYearCronField, months, hours, minutes, seconds);
}
use of com.cronutils.model.field.constraint.FieldConstraints 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;
}
use of com.cronutils.model.field.constraint.FieldConstraints in project cron-utils by jmrozanec.
the class CronDefinitionBuilderTest method testRegister.
@Test
public void testRegister() {
final FieldDefinition testFieldDefinition = new FieldDefinition(CronFieldName.SECOND, new FieldConstraints(Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), 0, 1, true));
builder.register(testFieldDefinition);
final Set<FieldDefinition> definitions = builder.instance().getFieldDefinitions();
assertNotNull(definitions);
assertEquals(1, definitions.size());
assertEquals(testFieldDefinition, definitions.iterator().next());
}
use of com.cronutils.model.field.constraint.FieldConstraints in project cron-utils by jmrozanec.
the class ValidationFieldExpressionVisitorTest method testVisitBetweenOOOrderStrict.
@Test(expected = IllegalArgumentException.class)
public void testVisitBetweenOOOrderStrict() {
final int startRange = 0;
final int endRange = 59;
fieldConstraints = new FieldConstraints(Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), startRange, endRange, true);
visitor = new ValidationFieldExpressionVisitor(fieldConstraints, stringValidations);
final Between between = new Between(new IntegerFieldValue(HIGH), new IntegerFieldValue(LOW));
assertEquals(between, between.accept(visitor));
}
Aggregations