private void validateBlocks () {
        // Iterate over each block and determine if there are any trips that overlap one another.
        for (String blockId : blockIntervals.keySet()) {
            List<BlockInterval> intervals = blockIntervals.get(blockId);
            intervals.sort(Comparator.comparingInt(i -> i.startTime));
            // Iterate over each interval (except for the last) comparing it to every other interval (so the last interval
            // is handled through the course of iteration).
            // FIXME this has complexity of n^2, there has to be a better way.
            for (int n = 0; n < intervals.size() - 1; n++) {
                BlockInterval interval1 = intervals.get(n);
                // Compare the interval at position N with all other intervals at position N+1 to the end of the list.
                for (BlockInterval interval2 : intervals.subList(n + 1, intervals.size())) {
                    if (interval1.lastStop.departure_time <= interval2.firstStop.arrival_time || interval2.lastStop.departure_time <= interval1.firstStop.arrival_time) {
                        continue;
                    }
                    // If either trip's last departure occurs after the other's first arrival, they overlap. We still
                    // need to determine if they operate on the same day though.
                    if (interval1.trip.service_id.equals(interval2.trip.service_id)) {
                        // If the overlapping trips share a service_id, record an error.
                        registerError(interval1.trip, TRIP_OVERLAP_IN_BLOCK, interval2.trip.trip_id);
                    } else {
                        // Trips overlap but don't have the same service_id.
                        // Check to see if service days fall on the same days of the week.
                        ServiceValidator.ServiceInfo info1 = serviceInfoForServiceId.get(interval1.trip.service_id);
                        ServiceValidator.ServiceInfo info2 = serviceInfoForServiceId.get(interval2.trip.service_id);
                        Set<LocalDate> overlappingDates = new HashSet<>(info1.datesActive); // use the copy constructor
                        overlappingDates.retainAll(info2.datesActive);
                        if (overlappingDates.size() > 0) {
                            registerError(interval1.trip, TRIP_OVERLAP_IN_BLOCK, interval2.trip.trip_id);
                        }
                    }
                }
            }
        }
    }
private void validateBlocks () {
        
        for (String blockId : blockIntervals.keySet()) {
            List<BlockInterval> intervals = blockIntervals.get(blockId);
            intervals.sort(Comparator.comparingInt(i -> i.startTime));
            
            
            
            for (int n = 0; n < intervals.size() - 1; n++) {
                BlockInterval interval1 = intervals.get(n);
                
                for (BlockInterval interval2 : intervals.subList(n + 1, intervals.size())) {
                    if (interval1.lastStop.departure_time <= interval2.firstStop.arrival_time || interval2.lastStop.departure_time <= interval1.firstStop.arrival_time) {
                        continue;
                    }
                    
                    
                    if (interval1.trip.service_id.equals(interval2.trip.service_id)) {
                        
                        registerError(interval1.trip, TRIP_OVERLAP_IN_BLOCK, interval2.trip.trip_id);
                    } else {
                        
                        
                        ServiceValidator.ServiceInfo info1 = serviceInfoForServiceId.get(interval1.trip.service_id);
                        ServiceValidator.ServiceInfo info2 = serviceInfoForServiceId.get(interval2.trip.service_id);
                        Set<LocalDate> overlappingDates = new HashSet<>(info1.datesActive); 
                        overlappingDates.retainAll(info2.datesActive);
                        if (overlappingDates.size() > 0) {
                            registerError(interval1.trip, TRIP_OVERLAP_IN_BLOCK, interval2.trip.trip_id);
                        }
                    }
                }
            }
        }
    }
private void validateBlocks ( ) { // Iterate over each block and determine if there are any trips that overlap one another. for ( String blockId : blockIntervals . keySet ( ) ) { List < BlockInterval > intervals = blockIntervals . get ( blockId ) ; intervals . sort ( Comparator . comparingInt ( i -> i . startTime ) ) ; // Iterate over each interval (except for the last) comparing it to every other interval (so the last interval // is handled through the course of iteration). // FIXME this has complexity of n^2, there has to be a better way. for ( int n = 0 ; n < intervals . size ( ) - 1 ; n ++ ) { BlockInterval interval1 = intervals . get ( n ) ; // Compare the interval at position N with all other intervals at position N+1 to the end of the list. for ( BlockInterval interval2 : intervals . subList ( n + 1 , intervals . size ( ) ) ) { if ( interval1 . lastStop . departure_time <= interval2 . firstStop . arrival_time || interval2 . lastStop . departure_time <= interval1 . firstStop . arrival_time ) { continue ; } // If either trip's last departure occurs after the other's first arrival, they overlap. We still // need to determine if they operate on the same day though. if ( interval1 . trip . service_id . equals ( interval2 . trip . service_id ) ) { // If the overlapping trips share a service_id, record an error. registerError ( interval1 . trip , TRIP_OVERLAP_IN_BLOCK , interval2 . trip . trip_id ) ; } else { // Trips overlap but don't have the same service_id. // Check to see if service days fall on the same days of the week. ServiceValidator . ServiceInfo info1 = serviceInfoForServiceId . get ( interval1 . trip . service_id ) ; ServiceValidator . ServiceInfo info2 = serviceInfoForServiceId . get ( interval2 . trip . service_id ) ; Set < LocalDate > overlappingDates = new HashSet <> ( info1 . datesActive ) ; // use the copy constructor overlappingDates . retainAll ( info2 . datesActive ) ; if ( overlappingDates . size ( ) > 0 ) { registerError ( interval1 . trip , TRIP_OVERLAP_IN_BLOCK , interval2 . trip . trip_id ) ; } } } } } }
Checks that trips which run on the same block (i.e., share a block_id) do not overlap. The block_id
represents a vehicle in service, so there must not be any trips on the same block interval that start while another
block trip is running.

NOTE: This validation check happens in the {@link ServiceValidator} because it depends on information derived
about which service calendars operate on which feed dates ({@link #serviceInfoForServiceId}).
Checks that trips which run on the same block ( i . e . share a block_id ) do not overlap . The block_id represents a vehicle in service so there must not be any trips on the same block interval that start while another block trip is running .