public final HourRanges compress ( ) { final List < HourRanges > normalized = normalize ( ) ; if ( normalized . size ( ) == 1 ) { return valueOf ( normalized . get ( 0 ) . toMinutes ( ) ) ; } else if ( normalized . size ( ) == 2 ) { final HourRanges firstDay = valueOf ( normalized . get ( 0 ) . toMinutes ( ) ) ; final HourRanges secondDay = normalized . get ( 1 ) ; if ( secondDay . ranges . size ( ) != 1 ) { throw new IllegalStateException ( "Expected exactly 1 hour range for the seond day, but was " + secondDay . ranges . size ( ) + ": " + secondDay ) ; } final HourRange seondDayHR = secondDay . ranges . get ( 0 ) ; final List < HourRange > newRanges = new ArrayList <> ( ) ; int lastIdx = 0 ; if ( firstDay . ranges . size ( ) > 1 ) { lastIdx = firstDay . ranges . size ( ) - 1 ; newRanges . addAll ( firstDay . ranges . subList ( 0 , lastIdx ) ) ; } final HourRange firstDayHR = firstDay . ranges . get ( lastIdx ) ; newRanges . add ( firstDayHR . joinWithNextDay ( seondDayHR ) ) ; return new HourRanges ( newRanges . toArray ( new HourRange [ newRanges . size ( ) ] ) ) ; } else { throw new IllegalStateException ( "Normalized hour ranges returned an unexpected number of elements (" + normalized . size ( ) + "): " + normalized ) ; } }
Returns a compressed version of the