Search in sources :

Example 11 with CronField

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

the class CronParserFieldTest method testParse_lastDoWInteger.

@Test
public void testParse_lastDoWInteger() {
    cronParserField = new CronParserField(CronFieldName.DAY_OF_WEEK, mockConstraints);
    Mockito.when(mockConstraints.getStringMappingValue("1")).thenReturn(null);
    final CronField result = cronParserField.parse("1L");
    Assert.assertEquals(mockParseResponse, result.getExpression());
    Assert.assertEquals(CronFieldName.DAY_OF_WEEK, result.getField());
    Mockito.verify(mockConstraints).getStringMappingValue("1");
    Mockito.verify(mockParser).parse("1L");
}
Also used : CronField(com.cronutils.model.field.CronField) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with CronField

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

the class CronParserFieldTest method testParse_lastDoWString.

@Test
public void testParse_lastDoWString() {
    cronParserField = new CronParserField(CronFieldName.DAY_OF_WEEK, mockConstraints);
    Mockito.when(mockConstraints.getStringMappingValue("MON")).thenReturn(1);
    final CronField result = cronParserField.parse("MONL");
    Assert.assertEquals(mockParseResponse, result.getExpression());
    Assert.assertEquals(CronFieldName.DAY_OF_WEEK, result.getField());
    Mockito.verify(mockConstraints).getStringMappingValue("MON");
    Mockito.verify(mockParser).parse("1L");
}
Also used : CronField(com.cronutils.model.field.CronField) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with CronField

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

the class AndDayOfWeekValueGenerator method generateCandidatesNotIncludingIntervalExtremes.

@Override
protected List<Integer> generateCandidatesNotIncludingIntervalExtremes(final int start, final int end) {
    final List<Integer> values = new ArrayList<>();
    final And and = (And) cronField.getExpression();
    for (final FieldExpression expression : and.getExpressions()) {
        final CronField cronField = new CronField(CronFieldName.DAY_OF_WEEK, expression, this.cronField.getConstraints());
        final List<Integer> candidatesList = FieldValueGeneratorFactory.createDayOfWeekValueGeneratorInstance(cronField, year, month, mondayDoWValue).generateCandidates(start, end);
        // add them to the master list
        if (candidatesList != null) {
            values.addAll(candidatesList);
        }
    }
    return values;
}
Also used : And(com.cronutils.model.field.expression.And) ArrayList(java.util.ArrayList) FieldExpression(com.cronutils.model.field.expression.FieldExpression) CronField(com.cronutils.model.field.CronField)

Example 14 with CronField

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

the class AndFieldValueGenerator method computeCandidates.

private List<Integer> computeCandidates(final Function<FieldValueGenerator, Integer> function) {
    final And and = (And) cronField.getExpression();
    final List<Integer> candidates = new ArrayList<>();
    for (final FieldExpression expression : and.getExpressions()) {
        candidates.add(function.apply(createCandidateGeneratorInstance(new CronField(cronField.getField(), expression, cronField.getConstraints()))));
    }
    final List<Integer> filteredCandidates = new ArrayList<>();
    for (final Integer candidate : candidates) {
        if (candidate >= 0) {
            filteredCandidates.add(candidate);
        }
    }
    Collections.sort(filteredCandidates);
    return filteredCandidates;
}
Also used : ArrayList(java.util.ArrayList) CronField(com.cronutils.model.field.CronField)

Example 15 with CronField

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

the class BetweenDayOfWeekValueGenerator method generateCandidatesNotIncludingIntervalExtremes.

@Override
protected List<Integer> generateCandidatesNotIncludingIntervalExtremes(final int start, final int end) {
    final List<Integer> values = new ArrayList<>();
    for (Integer dayOfWeek : dowValidValues) {
        // Build a CronField representing a single day of the week
        final FieldConstraintsBuilder fcb = FieldConstraintsBuilder.instance().forField(CronFieldName.DAY_OF_WEEK);
        final CronParserField parser = new CronParserField(CronFieldName.DAY_OF_WEEK, fcb.createConstraintsInstance());
        final CronField cronField = parser.parse(dayOfWeek.toString());
        // now a generator for matching days
        final OnDayOfWeekValueGenerator odow = new OnDayOfWeekValueGenerator(cronField, year, month, mondayDoWValue);
        // get the list of matching days
        final List<Integer> candidatesList = odow.generateCandidates(start, end);
        // add them to the master list
        if (candidatesList != null) {
            values.addAll(candidatesList);
        }
    }
    Collections.sort(values);
    return values;
}
Also used : CronParserField(com.cronutils.parser.CronParserField) FieldConstraintsBuilder(com.cronutils.model.field.constraint.FieldConstraintsBuilder) CronField(com.cronutils.model.field.CronField)

Aggregations

CronField (com.cronutils.model.field.CronField)34 IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)18 Test (org.junit.Test)16 On (com.cronutils.model.field.expression.On)15 SingleCron (com.cronutils.model.SingleCron)13 ArrayList (java.util.ArrayList)13 Before (org.junit.Before)7 Between (com.cronutils.model.field.expression.Between)6 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)5 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)4 WeekDay (com.cronutils.mapper.WeekDay)3 Cron (com.cronutils.model.Cron)3 CronFieldName (com.cronutils.model.field.CronFieldName)3 Every (com.cronutils.model.field.expression.Every)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 CompositeCron (com.cronutils.model.CompositeCron)2 And (com.cronutils.model.field.expression.And)2 ValidationFieldExpressionVisitor (com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor)2 CronConstraint (com.cronutils.model.definition.CronConstraint)1 FieldConstraintsBuilder (com.cronutils.model.field.constraint.FieldConstraintsBuilder)1