private void buildPossibleExpressions ( final CronDefinition cronDefinition ) { final List < CronParserField > sortedExpression = cronDefinition . getFieldDefinitions ( ) . stream ( ) . map ( this :: toCronParserField ) . sorted ( CronParserField . createFieldTypeComparator ( ) ) . collect ( Collectors . toList ( ) ) ; List < CronParserField > tempExpression = sortedExpression ; while ( lastFieldIsOptional ( tempExpression ) ) { int expressionLength = tempExpression . size ( ) - 1 ; ArrayList < CronParserField > possibleExpression = new ArrayList <> ( tempExpression . subList ( 0 , expressionLength ) ) ; expressions . put ( expressionLength , possibleExpression ) ; tempExpression = possibleExpression ; } expressions . put ( sortedExpression . size ( ) , sortedExpression ) ; }
Build possible cron expressions from definitions . One is built for sure . A second one may be build if last field is optional .