@ VisibleForTesting static List < Interval > filterSkipIntervals ( Interval totalInterval , List < Interval > skipIntervals ) { final List < Interval > filteredIntervals = new ArrayList <> ( skipIntervals . size ( ) + 1 ) ; DateTime remainingStart = totalInterval . getStart ( ) ; DateTime remainingEnd = totalInterval . getEnd ( ) ; for ( Interval skipInterval : skipIntervals ) { if ( skipInterval . getStart ( ) . isBefore ( remainingStart ) && skipInterval . getEnd ( ) . isAfter ( remainingStart ) ) { remainingStart = skipInterval . getEnd ( ) ; } else if ( skipInterval . getStart ( ) . isBefore ( remainingEnd ) && skipInterval . getEnd ( ) . isAfter ( remainingEnd ) ) { remainingEnd = skipInterval . getStart ( ) ; } else if ( ! remainingStart . isAfter ( skipInterval . getStart ( ) ) && ! remainingEnd . isBefore ( skipInterval . getEnd ( ) ) ) { filteredIntervals . add ( new Interval ( remainingStart , skipInterval . getStart ( ) ) ) ; remainingStart = skipInterval . getEnd ( ) ; } else { // Ignore this skipInterval log . warn ( "skipInterval[%s] is not contained in remainingInterval[%s]" , skipInterval , new Interval ( remainingStart , remainingEnd ) ) ; } } if ( ! remainingStart . equals ( remainingEnd ) ) { filteredIntervals . add ( new Interval ( remainingStart , remainingEnd ) ) ; } return filteredIntervals ; }
Returns a list of intervals which are contained by totalInterval but don t ovarlap with skipIntervals .