use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class StopEntriesFactory method processStops.
/**
* Iterate over each stop, generating a StopEntry for the graph.
*
* @param graph
*/
public void processStops(TransitGraphImpl graph) {
int stopIndex = 0;
Collection<Stop> stops = _gtfsDao.getAllStops();
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(stops.size());
Map<String, ArrayList<StopEntry>> stopEntriesByAgencyId = new FactoryMap<String, ArrayList<StopEntry>>(new ArrayList<StopEntry>());
for (Stop stop : stops) {
if (stopIndex % logInterval == 0)
_log.info("stops: " + stopIndex + "/" + stops.size());
stopIndex++;
StopEntryImpl stopEntry = new StopEntryImpl(stop.getId(), stop.getLat(), stop.getLon());
stopEntry.setWheelchairBoarding(getWheelchairBoardingAccessibilityForStop(stop));
graph.putStopEntry(stopEntry);
stopEntriesByAgencyId.get(stop.getId().getAgencyId()).add(stopEntry);
}
for (Map.Entry<String, ArrayList<StopEntry>> entry : stopEntriesByAgencyId.entrySet()) {
String agencyId = entry.getKey();
ArrayList<StopEntry> stopEntries = entry.getValue();
stopEntries.trimToSize();
AgencyEntryImpl agency = graph.getAgencyForId(agencyId);
if (agency == null) {
String msg = null;
if (stopEntries.size() > 0) {
msg = "no agency found for agencyId=" + agencyId + " of stop entry " + stopEntries.get(0).getId();
} else {
msg = "no agency found for agencyId=" + agencyId + " of empty stop entry list.";
}
_log.error(msg);
throw new IllegalStateException(msg);
}
agency.setStops(stopEntries);
}
graph.refreshStopMapping();
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method isMatch.
private boolean isMatch(List<StopTimeEntry> stopTimes, AgencyAndId stopId, int index) {
if (index < 0 || index >= stopTimes.size())
return false;
StopTimeEntry stopTime = stopTimes.get(index);
StopEntry stop = stopTime.getStop();
return stop.getId().equals(stopId);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class RouteServiceImpl method getRouteCollectionIdsForStop.
@Override
@Cacheable
public Set<AgencyAndId> getRouteCollectionIdsForStop(AgencyAndId stopId) {
StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopId);
if (stopEntry == null)
throw new InternalErrorServiceException("no such stop: id=" + stopId);
Set<AgencyAndId> routeCollectionIds = new HashSet<AgencyAndId>();
List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
for (BlockStopTimeIndex blockStopTimeIndex : indices) {
for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
TripEntry trip = blockTrip.getTrip();
routeCollectionIds.add(trip.getRouteCollection().getId());
}
}
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
for (FrequencyBlockStopTimeIndex blockStopTimeIndex : frequencyIndices) {
for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
TripEntry trip = blockTrip.getTrip();
routeCollectionIds.add(trip.getRouteCollection().getId());
}
}
return routeCollectionIds;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithConflictingDirections.
@Test
public void testGenerateStopNarrativesWithConflictingDirections() {
StopEntryImpl stopEntry = stop("stopA", 47.663146, -122.300928);
Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList((StopEntry) stopEntry));
Stop stop = new Stop();
stop.setId(stopEntry.getId());
Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));
/**
* Two shapes heading in opposite directions
*/
AgencyAndId shapeIdA = aid("shapeA");
ShapePointsFactory factoryA = new ShapePointsFactory();
factoryA.addPoint(47.661225, -122.3009201);
factoryA.addPoint(47.664375, -122.3008986);
ShapePoints shapePointsA = factoryA.create();
_provider.setShapePointsForId(shapeIdA, shapePointsA);
AgencyAndId shapeIdB = aid("shapeB");
ShapePointsFactory factoryB = new ShapePointsFactory();
factoryB.addPoint(47.664375, -122.3008986);
factoryB.addPoint(47.661225, -122.3009201);
ShapePoints shapePointsB = factoryB.create();
_provider.setShapePointsForId(shapeIdB, shapePointsB);
TripEntryImpl tripA = trip("tripA");
tripA.setShapeId(shapeIdA);
TripEntryImpl tripB = trip("tripB");
tripB.setShapeId(shapeIdB);
StopTimeEntryImpl stopTimeA = stopTime(0, stopEntry, tripA, 0, 0.0);
stopTimeA.setShapePointIndex(0);
StopTimeEntryImpl stopTimeB = stopTime(0, stopEntry, tripB, 0, 0.0);
stopTimeB.setShapePointIndex(0);
BlockStopTimeEntry blockStopTimeA = Mockito.mock(BlockStopTimeEntry.class);
Mockito.when(blockStopTimeA.getStopTime()).thenReturn(stopTimeA);
BlockStopTimeEntry blockStopTimeB = Mockito.mock(BlockStopTimeEntry.class);
Mockito.when(blockStopTimeB.getStopTime()).thenReturn(stopTimeB);
BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
Mockito.when(index.getStopTimes()).thenReturn(Arrays.asList(blockStopTimeA, blockStopTimeB));
List<BlockStopTimeIndex> indices = Arrays.asList(index);
Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
_task.generateStopNarratives(_provider);
StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
assertNull(narrative.getDirection());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithHardCodedDirection.
@Test
public void testGenerateStopNarrativesWithHardCodedDirection() {
StopEntry stopEntry = stop("stopA", 47.0, -122.0);
Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList(stopEntry));
Stop stop = new Stop();
stop.setId(stopEntry.getId());
stop.setDirection("west");
Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));
List<BlockStopTimeIndex> indices = Collections.emptyList();
Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
_task.generateStopNarratives(_provider);
StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
assertEquals("W", narrative.getDirection());
}
Aggregations