Search in sources :

Example 1 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue in project cron-utils by jmrozanec.

the class FieldParser method parseOnWithQuestionMark.

@VisibleForTesting
protected On parseOnWithQuestionMark(final String exp) {
    final SpecialCharFieldValue specialChar = new SpecialCharFieldValue(QUESTION_MARK);
    final String questionMarkExpression = exp.replace(QUESTION_MARK_STRING, EMPTY_STRING);
    if (EMPTY_STRING.equals(questionMarkExpression)) {
        return new On(new IntegerFieldValue(-1), specialChar, new IntegerFieldValue(-1));
    } else {
        throw new IllegalArgumentException(String.format("Expected: '?', found: %s", questionMarkExpression));
    }
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) VisibleForTesting(com.cronutils.utils.VisibleForTesting)

Example 2 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue in project cron-utils by jmrozanec.

the class FieldParser method parseOnWithHash.

@VisibleForTesting
protected On parseOnWithHash(final String exp) {
    if (!fieldConstraints.getSpecialChars().contains(HASH)) {
        throw new IllegalArgumentException("Invalid expression: " + exp);
    }
    final SpecialCharFieldValue specialChar = new SpecialCharFieldValue(HASH);
    final String[] array = exp.split(HASH_TAG);
    if (array.length == 0) {
        throw new IllegalArgumentException("Invalid Position of # Character!");
    }
    final IntegerFieldValue nth = mapToIntegerFieldValue(array[1]);
    if (array[0].isEmpty()) {
        throw new IllegalArgumentException("Time should be specified!");
    }
    return new On(mapToIntegerFieldValue(array[0]), specialChar, nth);
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) VisibleForTesting(com.cronutils.utils.VisibleForTesting)

Example 3 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue in project cron-utils by jmrozanec.

the class FieldParser method parseOnWithL.

protected On parseOnWithL(final String exp, final IntegerFieldValue daysBefore) {
    final SpecialCharFieldValue specialChar = new SpecialCharFieldValue(L);
    final String expression = exp.replace(L_STRING, EMPTY_STRING);
    IntegerFieldValue time = new IntegerFieldValue(-1);
    if (!EMPTY_STRING.equals(expression)) {
        time = mapToIntegerFieldValue(expression);
    }
    return new On(time, specialChar, daysBefore);
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue)

Example 4 with IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue 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 IntegerFieldValue

use of com.cronutils.model.field.value.IntegerFieldValue 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

IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)43 Test (org.junit.Test)32 CronField (com.cronutils.model.field.CronField)18 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)16 On (com.cronutils.model.field.expression.On)13 SingleCron (com.cronutils.model.SingleCron)10 ArrayList (java.util.ArrayList)10 Between (com.cronutils.model.field.expression.Between)6 Before (org.junit.Before)6 WeekDay (com.cronutils.mapper.WeekDay)4 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)4 Every (com.cronutils.model.field.expression.Every)3 VisibleForTesting (com.cronutils.utils.VisibleForTesting)3 And (com.cronutils.model.field.expression.And)1 SpecialChar (com.cronutils.model.field.value.SpecialChar)1