package com.conveyal.r5.analyst.scenario;

import com.conveyal.r5.transit.TransitLayer;

/**
 * A Filter that removes any trips that are not running in a given time window.
 * This reduces the size of the timetables before the search.
 */
public class InactiveTripsFilter extends TransitLayerModification {

    @Override
    public String getType() {
        return null; // Should never be serialized
    }

    @Override
    protected TransitLayer applyToTransitLayer(TransitLayer originalTransitLayer) {
        // TODO implement
        return originalTransitLayer;
    }

}

@@ -63,248 +63,1032 @@
 .r5.
-transit.TransitLayer;%0A%0A/**%0A * A Filter that removes any trips that are not running in a given time window.%0A * This reduces the size of the timetables before the search.%0A */%0Apublic class InactiveTripsFilter extends TransitLayerModification %7B
+profile.ProfileRequest;%0Aimport com.conveyal.r5.transit.TransitLayer;%0Aimport com.conveyal.r5.transit.TransportNetwork;%0Aimport com.conveyal.r5.transit.TripPattern;%0Aimport com.conveyal.r5.transit.TripSchedule;%0Aimport org.joda.time.LocalDate;%0A%0Aimport java.util.BitSet;%0A%0A/**%0A * A Filter that removes any trips that are not running in a given time window.%0A * This reduces the size of the timetables before the search.%0A */%0Apublic class InactiveTripsFilter extends TripScheduleModification %7B%0A%0A    BitSet activeServices;%0A    int fromTime;%0A    int toTime;%0A%0A    public InactiveTripsFilter (TransportNetwork network, ProfileRequest request) %7B%0A        if (network.transitLayer != null) %7B%0A            activeServices = network.transitLayer.getActiveServicesForDate(request.date);%0A            fromTime = request.fromTime;%0A            // The supplied time window is the departure time window.%0A            // Account for the fact that arrivals can be up to two hours later.%0A            toTime = request.toTime + (60 * 60 * 2);%0A        %7D%0A    %7D
 %0A%0A  
@@ -1153,17 +1153,45 @@
 ull; // 
-S
+This is used internally and s
 hould ne
@@ -1238,16 +1238,13 @@
    p
-rotected
+ublic
  Tra
@@ -1322,62 +1322,1281 @@
     
-// TODO implement%0A        return originalTransitLayer;
+if (activeServices == null) %7B%0A            return originalTransitLayer;%0A        %7D%0A        return super.applyToTransitLayer(originalTransitLayer);%0A    %7D%0A%0A    /**%0A     * For each trip pattern, if that trip pattern is used on any of the service scehedules that are active on%0A     * the date in question, apply the filter to each trip schedule individually. Otherwise reject the entire pattern,%0A     * it will not be used in the search.%0A     */%0A    @Override%0A    public TripPattern applyToTripPattern(TripPattern originalTripPattern) %7B%0A        if (activeServices.intersects(originalTripPattern.servicesActive)) %7B%0A            return super.applyToTripPattern(originalTripPattern);%0A        %7D else %7B%0A            return null;%0A        %7D%0A    %7D%0A%0A%0A    /**%0A     * For each trip within a pattern, check whether that trip occurs on the supplied date. If so, keep the trip. If%0A     * not, return null eliminating it from the TransportNetwork that will be used in the search.%0A     */%0A    @Override%0A    public TripSchedule applyToTripSchedule(TripPattern tripPattern, TripSchedule tripSchedule) %7B%0A        if (activeServices.get(tripSchedule.serviceCode) && tripSchedule.overlapsTimeRange(fromTime, toTime)) %7B%0A            return tripSchedule;%0A        %7D else %7B%0A            return null;%0A        %7D
 %0A   

implement inactive trip filter