<commit_before>package com.conveyal.r5.analyst.scenario;

import com.conveyal.r5.transit.TripPattern;
import com.conveyal.r5.transit.TripSchedule;

/**
 * Remove trips from a scenario.
 * This could remove all trips on a route, since its superclass TimetableFilter provides both route and trip matching.
 */
public class RemoveTrip extends TripScheduleModification {

    public static final long serialVersionUID = 1L;

    @Override
    public String getType() {
        return "remove-trip";
    }

    @Override
    public TripSchedule applyToTripSchedule(TripPattern tripPattern, TripSchedule tripSchedule) {
        return matches(tripSchedule.tripId) ? null : tripSchedule;
    }

}<commit_msg>remove entire trip patterns when routes are filtered<commit_after>package com.conveyal.r5.analyst.scenario;

import com.conveyal.r5.transit.TripPattern;
import com.conveyal.r5.transit.TripSchedule;

import java.util.Objects;

/**
 * Remove trips from a scenario.
 * This could remove all trips on a route, since its superclass TimetableFilter provides both route and trip matching.
 */
public class RemoveTrip extends TripScheduleModification {

    public static final long serialVersionUID = 1L;

    @Override
    public String getType() {
        return "remove-trip";
    }

    @Override
    public TripPattern applyToTripPattern(TripPattern originalTripPattern) {
        // Check first whether it's even possible that this Modification will apply to any trips on this pattern
        if (!couldMatch(originalTripPattern)) {
            return originalTripPattern;
        }
        // Stopgap efficient check for route filtration.
        // All trips on a TripPattern are on the same route so we can remove them all at once.
        if (routeId != null && (tripId == null || tripId.isEmpty())) {
            if (routeId.contains(originalTripPattern.routeId)) {
                return null;
            }
        }
        // Actually apply the Modification to each TripSchedule within this TripPattern individually.
        return super.applyToTripPattern(originalTripPattern);
    }

    @Override
    public TripSchedule applyToTripSchedule(TripPattern tripPattern, TripSchedule tripSchedule) {
        return matches(tripSchedule.tripId) ? null : tripSchedule;
    }

}
{'fraction_non_alphanumeric': 0.07186678352322524, 'fraction_numerical': 0.0035056967572304996, 'mean_word_length': 3.2752808988764044, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4440407', 'n_tokens_mistral': 635, 'n_tokens_neox': 600, 'n_words': 196}