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 |
String timeStr1 = time.replace(":","").trim();
|
66 |
String timeStr2 = otherBean.time.replace(":","").trim();
|
67 |
|
68 |
int time1 = 0;
|
69 |
int time2 = 0;
|
70 |
|
71 |
if (timeStr1.length() > 0)
|
72 |
time1 = Integer.parseInt(timeStr1);
|
73 |
|
74 |
if (timeStr2.length() > 0)
|
75 |
time2 = Integer.parseInt(timeStr2);
|
76 |
|
77 |
//work correctly when clock wraps around at midnight
|
78 |
if (Math.abs(time1-time2) < 1200) {
|
79 |
if (time1 > time2)
|
80 |
return 1;
|
81 |
else
|
82 |
return -1;
|
83 |
} else {
|
84 |
if (time1 < time2)
|
85 |
return 1;
|
86 |
else
|
87 |
return -1;
|
88 |
|
89 |
}
|
90 |
|
91 |
}
|
92 |
|
93 |
public String getUpdatedString() {
|
94 |
String updStr;
|
95 |
|
96 |
switch (updated) {
|
97 |
case 1:
|
98 |
updStr = "< 3 min";
|
99 |
break;
|
100 |
case 2:
|
101 |
updStr = "3-10 min";
|
102 |
break;
|
103 |
case 3:
|
104 |
updStr = "> 10 min";
|
105 |
break;
|
106 |
case 4:
|
107 |
updStr = "No info";
|
108 |
break;
|
109 |
default:
|
110 |
updStr = "Unknown:" + updated;
|
111 |
}
|
112 |
|
113 |
return updStr;
|
114 |
}
|
115 |
|
116 |
}
|