Search in sources :

Example 1 with Every

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;
}
Also used : Every(com.cronutils.model.field.expression.Every)

Example 2 with Every

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;
}
Also used : Every(com.cronutils.model.field.expression.Every)

Example 3 with Every

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;
    }
}
Also used : Every(com.cronutils.model.field.expression.Every)

Example 4 with Every

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);
}
Also used : WeekDay(com.cronutils.mapper.WeekDay) Between(com.cronutils.model.field.expression.Between) Every(com.cronutils.model.field.expression.Every) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) CronField(com.cronutils.model.field.CronField) Before(org.junit.Before)

Example 5 with Every

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));
}
Also used : Every(com.cronutils.model.field.expression.Every) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) CronField(com.cronutils.model.field.CronField) Before(org.junit.Before)

Aggregations

Every (com.cronutils.model.field.expression.Every)6 CronField (com.cronutils.model.field.CronField)3 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)3 Before (org.junit.Before)2 WeekDay (com.cronutils.mapper.WeekDay)1 SingleCron (com.cronutils.model.SingleCron)1 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)1 Between (com.cronutils.model.field.expression.Between)1 On (com.cronutils.model.field.expression.On)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1