use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockTripIndexData method createIndex.
public BlockTripIndex createIndex(TransitGraphDao dao) {
List<BlockTripEntry> trips = new ArrayList<BlockTripEntry>();
for (BlockTripReference blockTripReference : _blockTripReferences) {
BlockTripEntry trip = ReferencesLibrary.getReferenceAsTrip(blockTripReference, dao);
trips.add(trip);
}
return new BlockTripIndex(trips, _serviceIntervalBlock);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockTripInstanceLibrary method getBlockTripInstance.
/**
* Creates a {@link BlockTripInstance} from the specified
* {@link BlockInstance} with the trip from the block matching the specified
* tripId. If no trip is found in the block with the specified id, then null
* is returned.
*
* Note that this is just a linear search. If this ends up being a performance
* bottle-neck, we may have to look for a faster method here
*
* @param blockInstance
* @param tripId
* @return the new matching BlockTripInstance
*/
public static BlockTripInstance getBlockTripInstance(BlockInstance blockInstance, AgencyAndId tripId) {
BlockConfigurationEntry blockConfig = blockInstance.getBlock();
List<BlockTripEntry> blockTrips = blockConfig.getTrips();
for (int i = 0; i < blockTrips.size(); ++i) {
BlockTripEntry blockTrip = blockTrips.get(i);
if (blockTrip.getTrip().getId().equals(tripId)) {
return new BlockTripInstance(blockTrip, blockInstance.getState());
}
}
return null;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class ReferencesLibrary method getReferenceAsTrip.
public static BlockTripEntry getReferenceAsTrip(BlockTripReference reference, TransitGraphDao dao) {
BlockConfigurationEntry blockConfig = getReferenceAsBlockConfiguration(reference.getBlockConfigurationReference(), dao);
List<BlockTripEntry> trips = blockConfig.getTrips();
int tripIndex = reference.getTripIndex();
return trips.get(tripIndex);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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.BlockTripEntry 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;
}
Aggregations