protected List < DisabledDuration > createBlockingDurations ( final Iterable < BlockingState > inputBundleEvents ) { final List < DisabledDuration > result = new ArrayList < DisabledDuration > ( ) ; final Set < String > services = ImmutableSet . copyOf ( Iterables . transform ( inputBundleEvents , new Function < BlockingState , String > ( ) { @ Override public String apply ( final BlockingState input ) { return input . getService ( ) ; } } ) ) ; final Map < String , BlockingStateService > svcBlockedMap = new HashMap < String , BlockingStateService > ( ) ; for ( String svc : services ) { svcBlockedMap . put ( svc , new BlockingStateService ( ) ) ; } for ( final BlockingState e : inputBundleEvents ) { svcBlockedMap . get ( e . getService ( ) ) . addBlockingState ( e ) ; } final Iterable < DisabledDuration > unorderedDisabledDuration = Iterables . concat ( Iterables . transform ( svcBlockedMap . values ( ) , new Function < BlockingStateService , List < DisabledDuration > > ( ) { @ Override public List < DisabledDuration > apply ( final BlockingStateService input ) { return input . build ( ) ; } } ) ) ; final List < DisabledDuration > sortedDisabledDuration = Ordering . natural ( ) . sortedCopy ( unorderedDisabledDuration ) ; DisabledDuration prevDuration = null ; for ( DisabledDuration d : sortedDisabledDuration ) { // isDisjoint if ( prevDuration == null ) { prevDuration = d ; } else { if ( prevDuration . isDisjoint ( d ) ) { result . add ( prevDuration ) ; prevDuration = d ; } else { prevDuration = DisabledDuration . mergeDuration ( prevDuration , d ) ; } } } if ( prevDuration != null ) { result . add ( prevDuration ) ; } return result ; }
In ascending order