Search in sources :

Example 21 with IntegerFieldValue

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

the class ExecutionTimeBuilder method build.

protected ExecutionTime build() {
    boolean lowestAssigned = false;
    if (seconds == null) {
        seconds = timeNodeLowest(CronFieldName.SECOND, 0, 59);
    } else {
        lowestAssigned = true;
    }
    if (minutes == null) {
        minutes = lowestAssigned ? timeNodeAlways(CronFieldName.MINUTE, 0, 59) : timeNodeLowest(CronFieldName.MINUTE, 0, 59);
    } else {
        lowestAssigned = true;
    }
    if (hours == null) {
        hours = lowestAssigned ? timeNodeAlways(CronFieldName.HOUR, 0, 23) : timeNodeLowest(CronFieldName.HOUR, 0, 23);
    } else {
        lowestAssigned = true;
    }
    if (daysOfMonthCronField == null) {
        final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_MONTH);
        daysOfMonthCronField = lowestAssigned ? new CronField(CronFieldName.DAY_OF_MONTH, always(), constraints) : new CronField(CronFieldName.DAY_OF_MONTH, new On(new IntegerFieldValue(1)), constraints);
    } else {
        lowestAssigned = true;
    }
    if (daysOfWeekCronField == null) {
        final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_WEEK);
        daysOfWeekCronField = lowestAssigned ? new CronField(CronFieldName.DAY_OF_WEEK, always(), constraints) : new CronField(CronFieldName.DAY_OF_WEEK, new On(new IntegerFieldValue(1)), constraints);
    } else {
        lowestAssigned = true;
    }
    if (months == null) {
        months = lowestAssigned ? timeNodeAlways(CronFieldName.MONTH, 1, 12) : timeNodeLowest(CronFieldName.MONTH, 1, 12);
    }
    if (yearsValueGenerator == null) {
        yearsValueGenerator = FieldValueGeneratorFactory.forCronField(new CronField(CronFieldName.YEAR, always(), getConstraint(CronFieldName.YEAR)));
    }
    if (daysOfYearCronField == null) {
        final FieldConstraints constraints = getConstraint(CronFieldName.DAY_OF_YEAR);
        daysOfYearCronField = new CronField(CronFieldName.DAY_OF_YEAR, lowestAssigned ? FieldExpression.questionMark() : always(), constraints);
    }
    return new SingleExecutionTime(this.cron.getCronDefinition(), this.cron.retrieve(CronFieldName.YEAR), daysOfWeekCronField, daysOfMonthCronField, daysOfYearCronField, months, hours, minutes, seconds);
}
Also used : IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) FieldConstraints(com.cronutils.model.field.constraint.FieldConstraints) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On)

Example 22 with IntegerFieldValue

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

the class CronDescriptorTest method testEverySecondInMonth.

@Test
public void testEverySecondInMonth() {
    final int month = 2;
    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.SECOND, FieldExpression.always(), nullFieldConstraints));
    results.add(new CronField(CronFieldName.MONTH, new On(new IntegerFieldValue(month)), nullFieldConstraints));
    assertEquals("every second at February month", descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 23 with IntegerFieldValue

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

the class CronDescriptorTest method testDescribeEveryXMinutesBetweenTime.

@Test
public void testDescribeEveryXMinutesBetweenTime() {
    final int hour = 11;
    final int start = 0;
    final int end = 10;
    final Between expression = new Between(new IntegerFieldValue(start), new IntegerFieldValue(end));
    final List<CronField> results = new ArrayList<>();
    results.add(new CronField(CronFieldName.MINUTE, expression, nullFieldConstraints));
    results.add(new CronField(CronFieldName.HOUR, new On(new IntegerFieldValue(hour)), nullFieldConstraints));
    assertEquals(String.format("every minute between %s:%02d and %s:%02d", hour, start, hour, end), descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : Between(com.cronutils.model.field.expression.Between) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 24 with IntegerFieldValue

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

the class CronDescriptorTest method testNthDayOfWeekInMonth.

@Test
public void testNthDayOfWeekInMonth() {
    final int dayOfWeek = 2;
    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_WEEK, new On(new IntegerFieldValue(dayOfWeek), new SpecialCharFieldValue(SpecialChar.HASH), new IntegerFieldValue(dayOfWeek)), nullFieldConstraints));
    assertEquals(String.format("at %s:%s Tuesday %s of every month", hour, minute, dayOfWeek), descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : SpecialCharFieldValue(com.cronutils.model.field.value.SpecialCharFieldValue) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Example 25 with IntegerFieldValue

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

the class CronDescriptorTest method testDescribeAtXTimeBetweenDaysOfWeek.

@Test
public void testDescribeAtXTimeBetweenDaysOfWeek() {
    final int hour = 11;
    final int minute = 30;
    final int start = 2;
    final int end = 6;
    final Between expression = new Between(new IntegerFieldValue(start), new IntegerFieldValue(end));
    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_WEEK, expression, nullFieldConstraints));
    assertEquals(String.format("at %s:%s every day between Tuesday and Saturday", hour, minute), descriptor.describe(new SingleCron(mockDefinition, results)));
}
Also used : Between(com.cronutils.model.field.expression.Between) ArrayList(java.util.ArrayList) IntegerFieldValue(com.cronutils.model.field.value.IntegerFieldValue) SingleCron(com.cronutils.model.SingleCron) CronField(com.cronutils.model.field.CronField) On(com.cronutils.model.field.expression.On) Test(org.junit.Test)

Aggregations

IntegerFieldValue (com.cronutils.model.field.value.IntegerFieldValue)43 Test (org.junit.Test)32 CronField (com.cronutils.model.field.CronField)18 SpecialCharFieldValue (com.cronutils.model.field.value.SpecialCharFieldValue)16 On (com.cronutils.model.field.expression.On)13 SingleCron (com.cronutils.model.SingleCron)10 ArrayList (java.util.ArrayList)10 Between (com.cronutils.model.field.expression.Between)6 Before (org.junit.Before)6 WeekDay (com.cronutils.mapper.WeekDay)4 FieldConstraints (com.cronutils.model.field.constraint.FieldConstraints)4 Every (com.cronutils.model.field.expression.Every)3 VisibleForTesting (com.cronutils.utils.VisibleForTesting)3 And (com.cronutils.model.field.expression.And)1 SpecialChar (com.cronutils.model.field.value.SpecialChar)1