]> git.basschouten.com Git - openhab-addons.git/blob
0bc0a486aff7dd2052d84af12839272e2b5038a4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.onebusaway.internal.handler;
14
15 /**
16  * The {@link ObaStopArrivalResponse} is a representation of the OneBusAway response for requesting a stops arrival
17  * data.
18  *
19  * @see <a href=
20  *      "http://developer.onebusaway.org/modules/onebusaway-application-modules/current/api/where/methods/arrivals-and-departures-for-stop.html">arrivals-and-departures-for-stop
21  *      documentation</a>
22  *
23  * @author Shawn Wilsher - Initial contribution
24  */
25 public class ObaStopArrivalResponse {
26     public long currentTime;
27     public Data data;
28
29     public class Data {
30         public Entry entry;
31     }
32
33     public class Entry {
34         public ArrivalAndDeparture[] arrivalsAndDepartures;
35     }
36
37     public class ArrivalAndDeparture implements Comparable<ArrivalAndDeparture> {
38         public boolean predicted;
39         public long predictedArrivalTime;
40         public long predictedDepartureTime;
41         public long scheduledArrivalTime;
42         public long scheduledDepartureTime;
43         public String routeLongName;
44         public String routeShortName;
45         public String routeId;
46         public String stopId;
47         public String tripHeadsign;
48
49         /**
50          * Assumes other is for the same routeId and stopId. Sorts based on arrival time.
51          */
52         @Override
53         public int compareTo(ArrivalAndDeparture other) {
54             // Prefer predicated over scheduled times for order
55             return (int) ((predicted ? predictedArrivalTime : scheduledArrivalTime)
56                     - (other.predicted ? other.predictedArrivalTime : other.scheduledArrivalTime));
57         }
58     }
59 }