1 |
package dk.thoerup.traininfoservice.banedk;
|
2 |
|
3 |
public class DepartureBean implements Comparable<DepartureBean> {
|
4 |
private String time;
|
5 |
private int updated;
|
6 |
private String trainNumber;
|
7 |
private String destination;
|
8 |
private String origin;
|
9 |
private String location;
|
10 |
private String status;
|
11 |
private String note;
|
12 |
|
13 |
|
14 |
public String getTime() {
|
15 |
return time;
|
16 |
}
|
17 |
public void setTime(String time) {
|
18 |
this.time = time;
|
19 |
}
|
20 |
public int getUpdated() {
|
21 |
return updated;
|
22 |
}
|
23 |
public void setUpdated(int updated) {
|
24 |
this.updated = updated;
|
25 |
}
|
26 |
public String getTrainNumber() {
|
27 |
return trainNumber;
|
28 |
}
|
29 |
public void setTrainNumber(String trainNumber) {
|
30 |
this.trainNumber = trainNumber;
|
31 |
}
|
32 |
public String getDestination() {
|
33 |
return destination;
|
34 |
}
|
35 |
public void setDestination(String destination) {
|
36 |
this.destination = destination;
|
37 |
}
|
38 |
public String getOrigin() {
|
39 |
return origin;
|
40 |
}
|
41 |
public void setOrigin(String origin) {
|
42 |
this.origin = origin;
|
43 |
}
|
44 |
public String getLocation() {
|
45 |
return location;
|
46 |
}
|
47 |
public void setLocation(String location) {
|
48 |
this.location = location;
|
49 |
}
|
50 |
public String getStatus() {
|
51 |
return status;
|
52 |
}
|
53 |
public void setStatus(String status) {
|
54 |
this.status = status;
|
55 |
}
|
56 |
public String getNote() {
|
57 |
return note;
|
58 |
}
|
59 |
public void setNote(String note) {
|
60 |
this.note = note;
|
61 |
}
|
62 |
|
63 |
@Override
|
64 |
public int compareTo(DepartureBean otherBean) {
|
65 |
|
66 |
int time1 = Integer.parseInt(time.replace(":", ""));
|
67 |
int time2 = Integer.parseInt(otherBean.time.replace(":", ""));
|
68 |
|
69 |
//work correctly when clock wraps around at midnight
|
70 |
if (Math.abs(time1-time2) < 1200) {
|
71 |
if (time1 > time2)
|
72 |
return 1;
|
73 |
else
|
74 |
return -1;
|
75 |
} else {
|
76 |
if (time1 < time2)
|
77 |
return 1;
|
78 |
else
|
79 |
return -1;
|
80 |
|
81 |
}
|
82 |
|
83 |
}
|
84 |
|
85 |
public String getUpdatedString() {
|
86 |
String updStr;
|
87 |
|
88 |
switch (updated) {
|
89 |
case 1:
|
90 |
updStr = "< 3 min";
|
91 |
break;
|
92 |
case 2:
|
93 |
updStr = "3-10 min";
|
94 |
break;
|
95 |
case 3:
|
96 |
updStr = "> 10 min";
|
97 |
break;
|
98 |
case 4:
|
99 |
updStr = "No info";
|
100 |
break;
|
101 |
default:
|
102 |
updStr = "Unknown:" + updated;
|
103 |
}
|
104 |
|
105 |
return updStr;
|
106 |
}
|
107 |
|
108 |
}
|