}
private ScheduledBlockLocation getScheduledBlockLocationBetweenStopTimes(
List<BlockStopTimeEntry> stopTimes, int scheduleTime, int stopTimeIndex) {
BlockStopTimeEntry blockBefore = stopTimes.get(stopTimeIndex - 1);
BlockStopTimeEntry blockAfter = stopTimes.get(stopTimeIndex);
StopTimeEntry before = blockBefore.getStopTime();
StopTimeEntry after = blockAfter.getStopTime();
ScheduledBlockLocation result = new ScheduledBlockLocation();
result.setScheduledTime(scheduleTime);
result.setInService(true);
result.setStopTimeIndex(stopTimeIndex);
int fromTime = before.getDepartureTime();
int toTime = after.getArrivalTime();
int fromTimeOffset = fromTime - scheduleTime;
int toTimeOffset = toTime - scheduleTime;
if (Math.abs(fromTimeOffset) < Math.abs(toTimeOffset)) {
result.setClosestStop(blockBefore);
result.setClosestStopTimeOffset(fromTimeOffset);
} else {
result.setClosestStop(blockAfter);
result.setClosestStopTimeOffset(toTimeOffset);
}
result.setPreviousStop(blockBefore);
result.setNextStop(blockAfter);
result.setNextStopTimeOffset(toTimeOffset);
double ratio = (scheduleTime - fromTime) / ((double) (toTime - fromTime));
double fromDistance = blockBefore.getDistanceAlongBlock();
double toDistance = blockAfter.getDistanceAlongBlock();
double distanceAlongBlock = ratio * (toDistance - fromDistance)
+ fromDistance;
result.setDistanceAlongBlock(distanceAlongBlock);
int shapePointIndexFrom = -1;
int shapePointIndexTo = -1;
/**
* Are we between trips? Where is the transition point?
*/
if (!before.getTrip().equals(after.getTrip())) {
if (distanceAlongBlock >= blockAfter.getTrip().getDistanceAlongBlock()) {
result.setActiveTrip(blockAfter.getTrip());
shapePointIndexFrom = 0;
shapePointIndexTo = nextShapePointIndex(after);
} else {
result.setActiveTrip(blockBefore.getTrip());
shapePointIndexFrom = before.getShapePointIndex();