Search in sources :

Example 1 with QuestionMark

use of com.cronutils.model.field.expression.QuestionMark in project cron-utils by jmrozanec.

the class ValueMappingFieldExpressionVisitorTest method testVisitQuestionMark.

@Test
public void testVisitQuestionMark() {
    final FieldExpression param = FieldExpression.questionMark();
    final QuestionMark questionMark = (QuestionMark) param.accept(valueMappingFieldExpressionVisitor);
    // always the same cause of singleton pattern
    assertTrue(param == questionMark);
}
Also used : QuestionMark(com.cronutils.model.field.expression.QuestionMark) FieldExpression(com.cronutils.model.field.expression.FieldExpression) Test(org.junit.Test)

Example 2 with QuestionMark

use of com.cronutils.model.field.expression.QuestionMark in project cron-utils by jmrozanec.

the class CronConstraintsFactory method ensureEitherDayOfWeekOrDayOfMonth.

public static CronConstraint ensureEitherDayOfWeekOrDayOfMonth() {
    // both a day-of-week AND a day-of-month parameter should fail for QUARTZ
    return new CronConstraint("Both, a day-of-week AND a day-of-month parameter, are not supported.") {

        private static final long serialVersionUID = -4423693913868081656L;

        @Override
        public boolean validate(Cron cron) {
            CronField dayOfYearField = cron.retrieve(CronFieldName.DAY_OF_YEAR);
            CronField dayOfMonthField = cron.retrieve(CronFieldName.DAY_OF_MONTH);
            CronField dayOfWeekField = cron.retrieve(CronFieldName.DAY_OF_WEEK);
            if (dayOfYearField == null || dayOfYearField.getExpression() instanceof QuestionMark) {
                if (dayOfMonthField != null && !(dayOfMonthField.getExpression() instanceof QuestionMark)) {
                    return dayOfWeekField != null && dayOfWeekField.getExpression() instanceof QuestionMark;
                } else {
                    return dayOfWeekField != null && !(dayOfWeekField.getExpression() instanceof QuestionMark);
                }
            }
            return true;
        }
    };
}
Also used : QuestionMark(com.cronutils.model.field.expression.QuestionMark) Cron(com.cronutils.model.Cron) CronField(com.cronutils.model.field.CronField)

Aggregations

QuestionMark (com.cronutils.model.field.expression.QuestionMark)2 Cron (com.cronutils.model.Cron)1 CronField (com.cronutils.model.field.CronField)1 FieldExpression (com.cronutils.model.field.expression.FieldExpression)1 Test (org.junit.Test)1