use of org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock in project onebusaway-application-modules by camsys.
the class BlockStatusServiceImpl method getBlockInstancesForIndexAndTimestamps.
private List<BlockInstance> getBlockInstancesForIndexAndTimestamps(BlockSequenceIndex index, List<Date> timestamps) {
Date tFrom = timestamps.get(0);
Date tTo = timestamps.get(timestamps.size() - 1);
ServiceIntervalBlock serviceIntervalBlock = index.getServiceIntervalBlock();
List<BlockSequence> sequences = index.getSequences();
Collection<Date> serviceDates = _extendedCalendarService.getServiceDatesWithinRange(index.getServiceIds(), serviceIntervalBlock.getRange(), tFrom, tTo);
List<BlockInstance> instances = new ArrayList<BlockInstance>();
for (Date serviceDate : serviceDates) {
int effectiveFromTime = (int) ((tFrom.getTime() - serviceDate.getTime()) / 1000);
int effectiveToTime = (int) ((tTo.getTime() - serviceDate.getTime()) / 1000);
int indexFrom = Arrays.binarySearch(serviceIntervalBlock.getMaxArrivals(), effectiveFromTime);
int indexTo = Arrays.binarySearch(serviceIntervalBlock.getMinDepartures(), effectiveToTime);
if (indexFrom < 0)
indexFrom = -(indexFrom + 1);
if (indexTo < 0)
indexTo = -(indexTo + 1);
InstanceState state = new InstanceState(serviceDate.getTime());
for (int i = indexFrom; i < indexTo; i++) {
BlockSequence sequence = sequences.get(i);
BlockConfigurationEntry blockConfig = sequence.getBlockConfig();
BlockInstance instance = new BlockInstance(blockConfig, state);
instances.add(instance);
}
}
return instances;
}
Aggregations