static Generator serialInstanceGenerator ( final Predicate < ? super DateValue > filter , final Generator yearGenerator , final Generator monthGenerator , final Generator dayGenerator , final Generator hourGenerator , final Generator minuteGenerator , final Generator secondGenerator ) { if ( skipSubDayGenerators ( hourGenerator , minuteGenerator , secondGenerator ) ) { //fast case for generators that are not more frequent than daily return new Generator ( ) { @ Override public boolean generate ( DTBuilder builder ) throws IteratorShortCircuitingException { //cascade through periods to compute the next date do { //until we run out of days in the current month while ( ! dayGenerator . generate ( builder ) ) { //until we run out of months in the current year while ( ! monthGenerator . generate ( builder ) ) { //if there are more years available fetch one if ( ! yearGenerator . generate ( builder ) ) { //otherwise the recurrence is exhausted return false ; } } } //apply filters to generated dates } while ( ! filter . apply ( builder . toDateTime ( ) ) ) ; return true ; } } ; } else { return new Generator ( ) { @ Override public boolean generate ( DTBuilder builder ) throws IteratorShortCircuitingException { //cascade through periods to compute the next date do { //until we run out of seconds in the current minute while ( ! secondGenerator . generate ( builder ) ) { //until we run out of minutes in the current hour while ( ! minuteGenerator . generate ( builder ) ) { //until we run out of hours in the current day while ( ! hourGenerator . generate ( builder ) ) { //until we run out of days in the current month while ( ! dayGenerator . generate ( builder ) ) { //until we run out of months in the current year while ( ! monthGenerator . generate ( builder ) ) { //if there are more years available fetch one if ( ! yearGenerator . generate ( builder ) ) { //otherwise the recurrence is exhausted return false ; } } } } } } //apply filters to generated dates } while ( ! filter . apply ( builder . toDateTime ( ) ) ) ; //TODO: maybe group the filters into different kinds so we don't //apply filters that only affect days to every second. return true ; } } ; } }
A collector that yields each date in the period without doing any set collecting .