use of com.cronutils.model.field.expression.Between in project cron-utils by jmrozanec.
the class BetweenFieldValueGenerator method generateNextValue.
@Override
public int generateNextValue(final int reference) throws NoSuchValueException {
final Between between = (Between) cronField.getExpression();
// TODO validate from/to logic
int candidate = reference;
do {
++candidate;
} while (candidate < map(between.getFrom()));
if (candidate > map(between.getTo())) {
throw new NoSuchValueException();
}
return candidate;
}
use of com.cronutils.model.field.expression.Between in project cron-utils by jmrozanec.
the class BetweenFieldValueGenerator method generatePreviousValue.
@Override
public int generatePreviousValue(final int reference) throws NoSuchValueException {
final Between between = (Between) cronField.getExpression();
// TODO deal with from/to logic, to ensure correct values are assumed
int candidate = reference;
do {
--candidate;
} while (candidate > map(between.getTo()));
if (candidate < map(between.getFrom())) {
throw new NoSuchValueException();
}
return candidate;
}
use of com.cronutils.model.field.expression.Between in project cron-utils by jmrozanec.
the class EveryDayOfWeekValueGeneratorTest method setUp.
@Before
public void setUp() {
FieldConstraints constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
// every 2 days between 1-5
final CronField cronField = new CronField(CronFieldName.DAY_OF_WEEK, new Every(new Between(new IntegerFieldValue(1), new IntegerFieldValue(5)), new IntegerFieldValue(2)), constraints);
// Using monday = 1
WeekDay mondayDoWValue = new WeekDay(1, false);
// so MON-FRI/2, which should translate to MON,WED,FRI
validDow = EnumSet.of(DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY, DayOfWeek.FRIDAY);
fieldValueGenerator = new EveryDayOfWeekValueGenerator(cronField, year, month, mondayDoWValue);
}
use of com.cronutils.model.field.expression.Between in project cron-utils by jmrozanec.
the class CronDescriptorTest method testEveryMinuteBetweenMonths.
@Test
public void testEveryMinuteBetweenMonths() {
final int monthStart = 2;
final int monthEnd = 3;
final List<CronField> results = new ArrayList<>();
results.add(new CronField(CronFieldName.HOUR, FieldExpression.always(), nullFieldConstraints));
results.add(new CronField(CronFieldName.MINUTE, FieldExpression.always(), nullFieldConstraints));
results.add(new CronField(CronFieldName.MONTH, new Between(new IntegerFieldValue(monthStart), new IntegerFieldValue(monthEnd)), nullFieldConstraints));
assertEquals("every minute every month between February and March", descriptor.describe(new SingleCron(mockDefinition, results)));
}
use of com.cronutils.model.field.expression.Between in project cron-utils by jmrozanec.
the class BetweenFieldValueGenerator method generateCandidatesNotIncludingIntervalExtremes.
@Override
protected List<Integer> generateCandidatesNotIncludingIntervalExtremes(final int start, final int end) {
final List<Integer> values = new ArrayList<>();
// check overlapping ranges: x1 <= y2 && y1 <= x2
final Between between = (Between) cronField.getExpression();
final int expressionStart = map(between.getFrom());
final int expressionEnd = map(between.getTo());
int rangestart = start;
int rangeend = end;
if (start <= expressionEnd && expressionStart <= end) {
// ranges overlap
if (expressionEnd < end) {
rangeend = expressionEnd;
}
if (map(between.getFrom()) > start) {
rangestart = expressionStart;
}
try {
if (rangestart != start) {
values.add(rangestart);
}
int reference = generateNextValue(rangestart);
while (reference < rangeend) {
values.add(reference);
reference = generateNextValue(reference);
}
if (rangeend != end) {
values.add(reference);
}
} catch (final NoSuchValueException e) {
// TODO: Explain why this exception is ignored
}
}
return values;
}
Aggregations