
com.conveyal.gtfs.validator.ReferencesTripValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gtfs-lib Show documentation
Show all versions of gtfs-lib Show documentation
A library to load and index GTFS feeds of arbitrary size using disk-backed storage
package com.conveyal.gtfs.validator;
import com.conveyal.gtfs.error.SQLErrorStorage;
import com.conveyal.gtfs.loader.Feed;
import com.conveyal.gtfs.model.Route;
import com.conveyal.gtfs.model.Stop;
import com.conveyal.gtfs.model.StopTime;
import com.conveyal.gtfs.model.Trip;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.conveyal.gtfs.error.NewGTFSErrorType.*;
/**
* Created by abyrd on 2017-04-18
*/
public class ReferencesTripValidator extends TripValidator {
Set referencedStops = new HashSet<>();
Set referencedTrips = new HashSet<>();
Set referencedRoutes = new HashSet<>();
public ReferencesTripValidator(Feed feed, SQLErrorStorage errorStorage) {
super(feed, errorStorage);
}
@Override
public void validateTrip(Trip trip, Route route, List stopTimes, List stops) {
if (trip != null) referencedTrips.add(trip.trip_id);
if (route != null) referencedRoutes.add(route.route_id);
for (Stop stop : stops) referencedStops.add(stop.stop_id);
}
@Override
public void complete() {
for (Stop stop : feed.stops) {
if (!referencedStops.contains(stop.stop_id)) {
registerError(stop, STOP_UNUSED, stop.stop_id);
}
}
for (Trip trip : feed.trips) {
if (!referencedTrips.contains(trip.trip_id)) {
registerError(trip, TRIP_EMPTY);
}
}
for (Route route : feed.routes) {
if (!referencedRoutes.contains(route.route_id)) {
registerError(route, ROUTE_UNUSED);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy