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));
}
}
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);
}
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);
}
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)));
}
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)));
}
Aggregations