use of com.cronutils.model.field.CronField 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.field.CronField 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);
}
use of com.cronutils.model.field.CronField 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));
}
use of com.cronutils.model.field.CronField in project cron-utils by jmrozanec.
the class AndFieldValueGeneratorTest method setUp.
@Before
public void setUp() {
constraints = FieldConstraintsBuilder.instance().createConstraintsInstance();
fieldValueGenerator = new AndFieldValueGenerator(new CronField(CronFieldName.MONTH, new And().and(new On(new IntegerFieldValue(VALUE0))).and(new On(new IntegerFieldValue(VALUE1))).and(new On(new IntegerFieldValue(VALUE2))), constraints));
}
use of com.cronutils.model.field.CronField 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)));
}
Aggregations