use of com.cronutils.model.SingleCron in project cron-utils by jmrozanec.
the class CronMapper method map.
/**
* Maps given cron to target cron definition.
*
* @param cron - Instance to be mapped;
* if null a NullPointerException will be raised
* @return new Cron instance, never null;
*/
public Cron map(final Cron cron) {
Preconditions.checkNotNull(cron, "Cron must not be null");
final List<CronField> fields = new ArrayList<>();
for (final CronFieldName name : CronFieldName.values()) {
if (mappings.containsKey(name)) {
final CronField field = mappings.get(name).apply(cron.retrieve(name));
if (field != null) {
fields.add(field);
}
}
}
return cronRules.apply(new SingleCron(to, fields)).validate();
}
use of com.cronutils.model.SingleCron 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.SingleCron in project cron-utils by jmrozanec.
the class CronDescriptorTest method testDescribeAtXHours.
@Test
public void testDescribeAtXHours() {
final int hour = 11;
final List<CronField> results = new ArrayList<>();
results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
results.add(new CronField(CronFieldName.MINUTE, FieldExpression.always(), nullFieldConstraints));
results.add(new CronField(CronFieldName.SECOND, FieldExpression.always(), nullFieldConstraints));
assertEquals(String.format("at %s:00", hour), descriptor.describe(new SingleCron(mockDefinition, results)));
}
use of com.cronutils.model.SingleCron in project cron-utils by jmrozanec.
the class CronDescriptorTest method testEveryMinuteBetweenMonths.
@Test
public void testEveryMinuteBetweenMonths() {
final int monthStart = 2;
final int monthEnd = 3;
final List<CronField> results = new ArrayList<>();
results.add(new CronField(CronFieldName.HOUR, FieldExpression.always(), nullFieldConstraints));
results.add(new CronField(CronFieldName.MINUTE, FieldExpression.always(), nullFieldConstraints));
results.add(new CronField(CronFieldName.MONTH, new Between(new IntegerFieldValue(monthStart), new IntegerFieldValue(monthEnd)), nullFieldConstraints));
assertEquals("every minute every month between February and March", descriptor.describe(new SingleCron(mockDefinition, results)));
}
use of com.cronutils.model.SingleCron 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