use of com.cronutils.model.field.expression.Every in project cron-utils by jmrozanec.
the class EveryFieldValueGenerator method generateNextValue.
@Override
public int generateNextValue(final int reference) throws NoSuchValueException {
// intuition: for valid values, we have: offset+period*i
if (reference >= to) {
throw new NoSuchValueException();
}
final Every every = (Every) cronField.getExpression();
final int next = getNext(reference, every);
if (next < from) {
return from;
}
if (next > to) {
throw new NoSuchValueException();
}
return next;
}
use of com.cronutils.model.field.expression.Every in project cron-utils by jmrozanec.
the class EveryFieldValueGenerator method isMatch.
@Override
public boolean isMatch(final int value) {
final Every every = (Every) cronField.getExpression();
final int start = offset();
return value >= start && ((value - start) % every.getPeriod().getValue()) == 0 && value >= from && value <= to;
}
use of com.cronutils.model.field.expression.Every in project cron-utils by jmrozanec.
the class EveryFieldValueGenerator method generatePreviousValue.
@Override
public int generatePreviousValue(final int reference) throws NoSuchValueException {
final Every every = (Every) cronField.getExpression();
if (reference < from) {
throw new NoSuchValueException();
}
if (reference > to) {
return to;
}
final int period = every.getPeriod().getValue();
final int remainder = (reference - from) % period;
if (remainder == 0) {
return reference - period;
} else {
return reference - remainder;
}
}
use of com.cronutils.model.field.expression.Every 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.Every in project cron-utils by jmrozanec.
the class EveryFieldValueGeneratorTest method setUp.
@Before
public void setUp() {
constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
fieldValueGenerator = new EveryFieldValueGenerator(new CronField(CronFieldName.HOUR, new Every(new IntegerFieldValue(TIME)), constraints));
}
Aggregations