use of org.onebusaway.presentation.impl.ArrivalAndDepartureComparator in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesAction method buildPredictedArrivals.
protected void buildPredictedArrivals(List<ArrivalAndDepartureBean> arrivals, List<StopBean> list) {
if (arrivals.isEmpty()) {
addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
}
Collections.sort(arrivals, new ArrivalAndDepartureComparator());
long now = SystemTime.currentTimeMillis();
boolean hasAlerts = stopsHaveAlerts(list);
for (ArrivalAndDepartureBean adb : arrivals) {
TripBean trip = adb.getTrip();
RouteBean route = trip.getRoute();
addMessage(Messages.ROUTE);
String routeNumber = RoutePresenter.getNameForRoute(route);
addText(_routeNumberPronunciation.modify(routeNumber));
addText(", ");
String headsign = trip.getTripHeadsign();
if (headsign != null) {
// addMessage(Messages.TO);
String destination = _destinationPronunciation.modify(headsign);
destination = destination.replaceAll("\\&", "and");
addText(destination);
addText(", ");
}
if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
addText("is currently not in service");
continue;
}
long t = adb.computeBestDepartureTime();
boolean isPrediction = adb.hasPredictedDepartureTime();
int min = (int) ((t - now) / 1000 / 60);
if (min < 0) {
min = -min;
if (min > 60) {
String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
addMessage(message, new Date(t));
} else {
String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
addMessage(message, min);
}
} else {
if (min > 60) {
String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
addMessage(message, new Date(t));
} else {
String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
addMessage(message, min);
}
}
if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus())) {
addText("but is currently on adverse weather re-route.");
}
addText(". ");
if (!hasAlerts && adb.getSituations() != null && adb.getSituations().size() > 0) {
hasAlerts = true;
}
}
if (hasAlerts) {
addText(getAlertPresentText());
}
addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
if (!agencies.isEmpty()) {
addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
for (int i = 0; i < agencies.size(); i++) {
AgencyBean agency = agencies.get(i);
if (i == agencies.size() - 1 && agencies.size() > 1)
addText(Messages.AND);
addText(agency.getName());
addText(",");
}
}
addMessage(Messages.STOP_FOUND_BOOKMARK_THIS_LOCATION);
}
use of org.onebusaway.presentation.impl.ArrivalAndDepartureComparator in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesTemplate method buildPredictedArrivalsTemplate.
protected void buildPredictedArrivalsTemplate(List<ArrivalAndDepartureBean> arrivals) {
if (arrivals.isEmpty()) {
addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
}
Collections.sort(arrivals, new ArrivalAndDepartureComparator());
long now = SystemTime.currentTimeMillis();
for (ArrivalAndDepartureBean adb : arrivals) {
TripBean trip = adb.getTrip();
RouteBean route = trip.getRoute();
addMessage(Messages.ROUTE);
String routeNumber = RoutePresenter.getNameForRoute(route);
addText(_routeNumberPronunciation.modify(routeNumber));
String headsign = trip.getTripHeadsign();
if (headsign != null) {
addMessage(Messages.TO);
String destination = _destinationPronunciation.modify(headsign);
addText(destination);
}
if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
addText("is currently not in service");
continue;
}
long t = adb.computeBestDepartureTime();
boolean isPrediction = adb.hasPredictedDepartureTime();
int min = (int) ((t - now) / 1000 / 60);
if (min < 0) {
min = -min;
if (min > 60) {
String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
addMessage(message, new Date(t));
} else {
String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
addMessage(message, min);
}
} else {
if (min > 60) {
String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
addMessage(message, new Date(t));
} else {
String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
addMessage(message, min);
}
}
if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus()))
addText("but is currently on adverse weather re-route.");
}
addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
if (!agencies.isEmpty()) {
addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
for (int i = 0; i < agencies.size(); i++) {
AgencyBean agency = agencies.get(i);
if (i == agencies.size() - 1 && agencies.size() > 1)
addText(Messages.AND);
addText(agency.getName());
addText(",");
}
}
}
Aggregations