use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class DeduplicateServiceIdsStrategyTest method test.
@Test
public void test() throws IOException {
_gtfs.putTrips(2, "r0", "sid0,sid1");
_gtfs.putCalendars(2, "start_date=20120630", "end_date=20121224", "mask=1111100");
GtfsMutableRelationalDao dao = _gtfs.read();
assertEquals(2, dao.getAllCalendars().size());
_strategy.run(_context, dao);
assertEquals(1, dao.getAllCalendars().size());
AgencyAndId serviceId = new AgencyAndId("a0", "sid0");
assertNotNull(dao.getCalendarForServiceId(serviceId));
for (Trip trip : dao.getAllTrips()) {
assertEquals(serviceId, trip.getServiceId());
}
assertNull(dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1")));
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class TrimTripTransformStrategyTest method testMatching.
@Test
public void testMatching() throws IOException {
_gtfs.putAgencies(1);
_gtfs.putStops(6);
_gtfs.putRoutes(2);
_gtfs.putTrips(2, "r0,r1", "sid0");
_gtfs.putStopTimes("t0,t1", "s0,s1,s2,s3,s4,s5");
GtfsMutableRelationalDao dao = _gtfs.read();
TrimOperation operation = new TrimOperation();
operation.setMatch(new TypedEntityMatch(Trip.class, new PropertyValueEntityMatch(new PropertyPathExpression("route.id.id"), new SimpleValueMatcher("r1"))));
operation.setFromStopId("s4");
_strategy.addOperation(operation);
_strategy.run(_context, dao);
{
Trip trip = dao.getTripForId(new AgencyAndId("a0", "t0"));
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
assertEquals(6, stopTimes.size());
}
{
Trip trip = dao.getTripForId(new AgencyAndId("a0", "t1-s4"));
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
assertEquals(4, stopTimes.size());
assertEquals("s0", stopTimes.get(0).getStop().getId().getId());
assertEquals("s3", stopTimes.get(3).getStop().getId().getId());
}
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsRelationalDaoImpl method getTripAgencyIdsReferencingServiceId.
@Override
public List<String> getTripAgencyIdsReferencingServiceId(AgencyAndId serviceId) {
if (_tripAgencyIdsByServiceId == null) {
Map<AgencyAndId, Set<String>> agencyIdsByServiceIds = new HashMap<AgencyAndId, Set<String>>();
for (Trip trip : getAllTrips()) {
AgencyAndId tripId = trip.getId();
String tripAgencyId = tripId.getAgencyId();
AgencyAndId tripServiceId = trip.getServiceId();
Set<String> agencyIds = agencyIdsByServiceIds.get(tripServiceId);
if (agencyIds == null) {
agencyIds = new HashSet<String>();
agencyIdsByServiceIds.put(tripServiceId, agencyIds);
}
agencyIds.add(tripAgencyId);
}
_tripAgencyIdsByServiceId = new HashMap<AgencyAndId, List<String>>();
for (Map.Entry<AgencyAndId, Set<String>> entry : agencyIdsByServiceIds.entrySet()) {
AgencyAndId tripServiceId = entry.getKey();
List<String> agencyIds = new ArrayList<String>(entry.getValue());
Collections.sort(agencyIds);
_tripAgencyIdsByServiceId.put(tripServiceId, agencyIds);
}
}
List<String> agencyIds = _tripAgencyIdsByServiceId.get(serviceId);
if (agencyIds == null)
agencyIds = new ArrayList<String>();
return agencyIds;
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsRelationalDaoImpl method getTripsForBlockId.
@Override
public List<Trip> getTripsForBlockId(AgencyAndId blockId) {
if (_tripsByBlockId == null) {
_tripsByBlockId = new HashMap<AgencyAndId, List<Trip>>();
for (Trip trip : getAllTrips()) {
if (trip.getBlockId() != null) {
AgencyAndId bid = new AgencyAndId(trip.getId().getAgencyId(), trip.getBlockId());
List<Trip> trips = _tripsByBlockId.get(bid);
if (trips == null) {
trips = new ArrayList<Trip>();
_tripsByBlockId.put(bid, trips);
}
trips.add(trip);
}
}
}
return list(_tripsByBlockId.get(blockId));
}
use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyMethodResolverImplTest method testRouteTripsVirtualMethod.
@Test
public void testRouteTripsVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Route route = new Route();
route.setId(new AgencyAndId("1", "r0"));
_dao.saveEntity(route);
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "t0"));
trip.setRoute(route);
_dao.saveEntity(trip);
PropertyMethod method = _resolver.getPropertyMethod(Route.class, "trips");
assertEquals(Arrays.asList(trip), method.invoke(route));
}
Aggregations