Search in sources :

Example 1 with SpecialCharFieldValue

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

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

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

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

the class CronDescriptorTest method testLastDayOfMonth.

@Test
public void testLastDayOfMonth() {
    final int hour = 10;
    final int minute = 15;
    final List<CronField> results = new ArrayList<>();
    results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
    results.add(new CronField(CronFieldName.MINUTE, new On(new IntegerFieldValue(minute)), nullFieldConstraints));
    results.add(new CronField(CronFieldName.DAY_OF_MONTH, new On(new SpecialCharFieldValue(SpecialChar.L)), nullFieldConstraints));
    assertEquals(String.format("at %s:%s last day of month", hour, minute), descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 5 with SpecialCharFieldValue

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

the class CronDescriptorTest method testNearestWeekdayToNthOfMonth.

@Test
public void testNearestWeekdayToNthOfMonth() {
    final int dayOfMonth = 22;
    final int hour = 10;
    final int minute = 15;
    final List<CronField> results = new ArrayList<>();
    results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
    results.add(new CronField(CronFieldName.MINUTE, new On(new IntegerFieldValue(minute)), nullFieldConstraints));
    results.add(new CronField(CronFieldName.DAY_OF_MONTH, new On(new IntegerFieldValue(dayOfMonth), new SpecialCharFieldValue(SpecialChar.W)), nullFieldConstraints));
    assertEquals(String.format("at %s:%s the nearest weekday to the %s of the month", hour, minute, dayOfMonth), descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Aggregations

SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)23 Test (org.junit.Test)17 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)16 CronField (com.cronutils.model.field.CronField)5 On (com.cronutils.model.field.expression.On)5 SingleCron (com.cronutils.model.SingleCron)4 ArrayList (java.util.ArrayList)4 SpecialChar (com.cronutils.model.field.value.SpecialChar)3 VisibleForTesting (com.cronutils.utils.VisibleForTesting)3 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)1 Before (org.junit.Before)1