use of uk.org.siri.siri.NaturalLanguageStringStructure in project onebusaway-application-modules by camsys.
the class SiriSupport method getOnwardCallStructure.
private static OnwardCallStructure getOnwardCallStructure(StopBean stopBean, PresentationService presentationService, double distanceOfCallAlongTrip, double distanceOfVehicleFromCall, int visitNumber, int index, TimepointPredictionRecord prediction, boolean hasRealtimeData, long responseTimestamp, long scheduledArrivalTime) {
OnwardCallStructure onwardCallStructure = new OnwardCallStructure();
onwardCallStructure.setVisitNumber(BigInteger.valueOf(visitNumber));
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue(stopBean.getId());
onwardCallStructure.setStopPointRef(stopPointRef);
if (stopBean.getCode() != null) {
// Agency's prefer stop code display in UI, so override platform name for this use
NaturalLanguageStringStructure platform = new NaturalLanguageStringStructure();
platform.setValue(stopBean.getCode());
onwardCallStructure.setArrivalPlatformName(platform);
}
NaturalLanguageStringStructure stopPoint = new NaturalLanguageStringStructure();
stopPoint.setValue(stopBean.getName());
onwardCallStructure.setStopPointName(stopPoint);
if (prediction != null) {
if (prediction.getTimepointPredictedArrivalTime() < responseTimestamp) {
onwardCallStructure.setExpectedArrivalTime(new Date(responseTimestamp));
onwardCallStructure.setExpectedDepartureTime(new Date(responseTimestamp));
} else {
onwardCallStructure.setExpectedArrivalTime(new Date(prediction.getTimepointPredictedArrivalTime()));
onwardCallStructure.setExpectedDepartureTime(new Date(prediction.getTimepointPredictedDepartureTime()));
}
} else if (!hasRealtimeData) {
_log.debug("using arrival time of " + new Date(scheduledArrivalTime));
onwardCallStructure.setExpectedArrivalTime(new Date(scheduledArrivalTime));
onwardCallStructure.setExpectedDepartureTime(new Date(scheduledArrivalTime));
}
// siri extensions
SiriExtensionWrapper wrapper = new SiriExtensionWrapper();
ExtensionsStructure distancesExtensions = new ExtensionsStructure();
SiriDistanceExtension distances = new SiriDistanceExtension();
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
df.setGroupingUsed(false);
distances.setStopsFromCall(index);
distances.setCallDistanceAlongRoute(NumberUtils.toDouble(df.format(distanceOfCallAlongTrip)));
distances.setDistanceFromCall(NumberUtils.toDouble(df.format(distanceOfVehicleFromCall)));
distances.setPresentableDistance(presentationService.getPresentableDistance(distances));
wrapper.setDistances(distances);
distancesExtensions.setAny(wrapper);
onwardCallStructure.setExtensions(distancesExtensions);
return onwardCallStructure;
}
Aggregations