use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getBlockStopTime.
private BlockStopTimeEntry getBlockStopTime(BlockTripInstance blockTripInstance, AgencyAndId stopId, int stopSequence, int timeOfServiceDate) {
/**
* We don't iterate over block stop times directly because there is
* performance penalty with instantiating each. Also note that this will
* currently miss the case where a stop is visited twice in the same trip.
*/
BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
TripEntry trip = blockTrip.getTrip();
List<StopTimeEntry> stopTimes = trip.getStopTimes();
if (stopSequence > -1) {
/**
* If a stop sequence has been specified, we start our search at the
* specified index, expanding our search until we find the target stop. We
* allow this flexibility in the case of a bookmarked arrival-departure
* where the stop sequence has changed slightly due to the addition or
* subtraction of a previous stop.
*/
int offset = 0;
while (true) {
int before = stopSequence - offset;
if (isMatch(stopTimes, stopId, before)) {
return blockTrip.getStopTimes().get(before);
}
int after = stopSequence + offset;
if (isMatch(stopTimes, stopId, after)) {
return blockTrip.getStopTimes().get(after);
}
if (before < 0 && after >= stopTimes.size())
return null;
offset++;
}
} else {
Min<BlockStopTimeEntry> m = new Min<BlockStopTimeEntry>();
int index = 0;
for (StopTimeEntry stopTime : stopTimes) {
if (stopTime.getStop().getId().equals(stopId)) {
int a = Math.abs(timeOfServiceDate - stopTime.getArrivalTime());
int b = Math.abs(timeOfServiceDate - stopTime.getDepartureTime());
int delta = Math.min(a, b);
m.add(delta, blockTrip.getStopTimes().get(index));
}
index++;
}
if (m.isEmpty())
return null;
return m.getMinElement();
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntriesFactory method processTripsForServiceIdConfiguration.
private BlockConfigurationEntryImpl.Builder processTripsForServiceIdConfiguration(BlockEntryImpl block, Map<LocalizedServiceId, List<TripEntryImpl>> tripsByServiceId, ServiceIdActivation serviceIds) {
ArrayList<TripEntry> trips = new ArrayList<TripEntry>();
for (LocalizedServiceId serviceId : serviceIds.getActiveServiceIds()) {
trips.addAll(tripsByServiceId.get(serviceId));
}
Collections.sort(trips, _blockTripComparator);
trips.trimToSize();
double[] tripGapDistances = computeGapDistancesBetweenTrips(trips);
BlockConfigurationEntryImpl.Builder builder = BlockConfigurationEntryImpl.builder();
builder.setBlock(block);
builder.setServiceIds(serviceIds);
builder.setTrips(trips);
builder.setTripGapDistances(tripGapDistances);
return builder;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntriesFactory method computeGapDistancesBetweenTrips.
private double[] computeGapDistancesBetweenTrips(List<TripEntry> trips) {
double[] tripGapDistances = new double[trips.size()];
if (_shapePointHelper == null)
return tripGapDistances;
for (int index = 0; index < trips.size() - 1; index++) {
TripEntry tripA = trips.get(index);
TripEntry tripB = trips.get(index + 1);
double d = 0;
ShapePoints shapeFrom = _shapePointHelper.getShapePointsForShapeId(tripA.getShapeId());
ShapePoints shapeTo = _shapePointHelper.getShapePointsForShapeId(tripB.getShapeId());
if (shapeFrom != null && shapeTo != null && !shapeFrom.isEmpty() && !shapeTo.isEmpty()) {
int n = shapeFrom.getSize();
double lat1 = shapeFrom.getLatForIndex(n - 1);
double lon1 = shapeFrom.getLonForIndex(n - 1);
double lat2 = shapeTo.getLatForIndex(0);
double lon2 = shapeTo.getLonForIndex(0);
d = SphericalGeometryLibrary.distance(lat1, lon1, lat2, lon2);
}
tripGapDistances[index] = d;
}
return tripGapDistances;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class FrequencyEntriesFactory method computeBlockFrequencies.
private List<FrequencyEntry> computeBlockFrequencies(BlockEntryImpl block, List<BlockTripEntry> trips, Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlock) {
List<FrequencyEntry> frequencies = null;
for (BlockTripEntry blockTrip : trips) {
TripEntry trip = blockTrip.getTrip();
List<FrequencyEntry> potentialFrequencies = frequenciesAlongBlock.get(trip.getId());
if (frequencies == null) {
frequencies = potentialFrequencies;
} else {
if (!frequencies.equals(potentialFrequencies)) {
throw new IllegalStateException("frequency-based trips in same block don't have same frequencies: blockId=" + block.getId());
}
}
}
return frequencies;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class RouteServiceImpl method getStopsForRouteCollection.
@Override
@Cacheable
public Collection<AgencyAndId> getStopsForRouteCollection(AgencyAndId id) {
Set<AgencyAndId> stopIds = new HashSet<AgencyAndId>();
RouteCollectionEntry routeCollectionEntry = _transitGraphDao.getRouteCollectionForId(id);
for (RouteEntry route : routeCollectionEntry.getChildren()) {
List<TripEntry> trips = route.getTrips();
for (TripEntry trip : trips) {
List<StopTimeEntry> stopTimes = trip.getStopTimes();
for (StopTimeEntry stopTime : stopTimes) stopIds.add(stopTime.getStop().getId());
}
}
return new ArrayList<AgencyAndId>(stopIds);
}
Aggregations