use of org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex in project onebusaway-application-modules by camsys.
the class StopTimeServiceImpl method getNextBlockSequenceDeparturesForStop.
@Override
public List<StopTimeInstance> getNextBlockSequenceDeparturesForStop(StopEntry stopEntry, long time, boolean includePrivateSerivce) {
List<StopTimeInstance> stopTimeInstances = new ArrayList<StopTimeInstance>();
List<BlockStopSequenceIndex> blockStopTripIndices = _blockIndexService.getStopSequenceIndicesForStop(stopEntry);
for (BlockStopSequenceIndex index : blockStopTripIndices) {
List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
for (Date serviceDate : serviceDates) {
int relativeFrom = effectiveTime(serviceDate.getTime(), time);
int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.BLOCK_STOP_TIME_DEPARTURE_INSTANCE);
if (fromIndex < index.size()) {
BlockStopTimeEntry blockStopTime = index.getBlockStopTimeForIndex(fromIndex);
InstanceState state = new InstanceState(serviceDate.getTime());
StopTimeInstance sti = new StopTimeInstance(blockStopTime, state);
stopTimeInstances.add(sti);
}
}
}
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
for (Date serviceDate : serviceDates) {
int relativeFrom = effectiveTime(serviceDate.getTime(), time);
int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
if (fromIndex < index.size()) {
FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(fromIndex);
BlockStopTimeEntry bst = entry.getStopTime();
FrequencyEntry frequency = entry.getFrequency();
InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
int stopTimeOffset = entry.getStopTimeOffset();
int frequencyOffset = computeFrequencyOffset(relativeFrom, bst, frequency, stopTimeOffset, true);
StopTimeInstance sti = new StopTimeInstance(bst, state, frequencyOffset);
stopTimeInstances.add(sti);
}
}
}
return stopTimeInstances;
}
use of org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex in project onebusaway-application-modules by camsys.
the class BlockIndexServiceImpl method loadStopTripIndices.
private void loadStopTripIndices() {
// Clear any existing indices
for (StopEntry stop : _graphDao.getAllStops()) {
StopEntryImpl stopImpl = (StopEntryImpl) stop;
stopImpl.getStopTripIndices().clear();
stopImpl.getFrequencyStopTripIndices().clear();
}
for (BlockSequenceIndex index : _blockSequenceIndices) {
BlockSequence sequence = index.getSequences().get(0);
int offset = 0;
for (BlockStopTimeEntry bst : sequence.getStopTimes()) {
StopTimeEntry stopTime = bst.getStopTime();
StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
BlockStopSequenceIndex blockStopTripIndex = new BlockStopSequenceIndex(index, offset);
stop.addBlockStopTripIndex(blockStopTripIndex);
offset++;
}
}
for (FrequencyBlockTripIndex index : _frequencyBlockTripIndices) {
BlockTripEntry trip = index.getTrips().get(0);
int offset = 0;
for (BlockStopTimeEntry bst : trip.getStopTimes()) {
StopTimeEntry stopTime = bst.getStopTime();
StopEntryImpl stop = (StopEntryImpl) stopTime.getStop();
FrequencyStopTripIndex stopTripIndex = new FrequencyStopTripIndex(index, offset);
stop.addFrequencyStopTripIndex(stopTripIndex);
offset++;
}
}
}
Aggregations