1 |
package dk.thoerup.traininfoservice.banedk; |
package dk.thoerup.traininfoservice.banedk; |
2 |
|
|
3 |
public class DepartureBean implements Comparable<DepartureBean> { |
import org.simpleframework.xml.Element; |
4 |
private String time; |
import org.simpleframework.xml.Root; |
5 |
private int updated; |
|
6 |
|
@Root(name="train") |
7 |
|
public class DepartureEntry implements Comparable<DepartureEntry> { |
8 |
|
|
9 |
|
@Element |
10 |
|
private String time; |
11 |
|
|
12 |
|
@Element |
13 |
|
private int updated; |
14 |
|
|
15 |
|
@Element(name="trainnumber") |
16 |
private String trainNumber; |
private String trainNumber; |
17 |
|
|
18 |
|
@Element |
19 |
private String destination; |
private String destination; |
20 |
private String origin; |
|
21 |
private String location; |
@Element |
22 |
private String status; |
private String origin; |
23 |
|
|
24 |
|
@Element |
25 |
|
private String location; |
26 |
|
|
27 |
|
@Element |
28 |
|
private String status; |
29 |
|
|
30 |
|
@Element |
31 |
private String note; |
private String note; |
32 |
|
|
33 |
|
@Element |
34 |
|
private String type; |
35 |
|
|
36 |
|
|
37 |
public String getTime() { |
public String getTime() { |
38 |
return time; |
return time; |
83 |
this.note = note; |
this.note = note; |
84 |
} |
} |
85 |
|
|
86 |
|
public String getType() { |
87 |
|
return type; |
88 |
|
} |
89 |
|
|
90 |
|
public void setType(String type) { |
91 |
|
this.type = type; |
92 |
|
} |
93 |
|
|
94 |
@Override |
@Override |
95 |
public int compareTo(DepartureBean otherBean) { |
public int compareTo(DepartureEntry otherBean) { |
96 |
|
String timeStr1 = time.replace(":","").trim(); |
97 |
|
String timeStr2 = otherBean.time.replace(":","").trim(); |
98 |
|
|
99 |
|
int time1 = 0; |
100 |
|
int time2 = 0; |
101 |
|
|
102 |
int time1 = Integer.parseInt(time.replace(":", "")); |
if (timeStr1.length() > 0) |
103 |
int time2 = Integer.parseInt(otherBean.time.replace(":", "")); |
time1 = Integer.parseInt(timeStr1); |
104 |
if (time1 > time2) |
|
105 |
return 1; |
if (timeStr2.length() > 0) |
106 |
else |
time2 = Integer.parseInt(timeStr2); |
107 |
return -1; |
|
108 |
|
//work correctly when clock wraps around at midnight |
109 |
|
if (Math.abs(time1-time2) < 1200) { |
110 |
|
if (time1 > time2) |
111 |
|
return 1; |
112 |
|
else |
113 |
|
return -1; |
114 |
|
} else { |
115 |
|
if (time1 < time2) |
116 |
|
return 1; |
117 |
|
else |
118 |
|
return -1; |
119 |
|
|
120 |
|
} |
121 |
|
|
122 |
} |
} |
123 |
|
|
124 |
|
public String getUpdatedString() { |
125 |
|
String updStr; |
126 |
|
|
127 |
|
switch (updated) { |
128 |
|
case 1: |
129 |
|
updStr = "< 3 min"; |
130 |
|
break; |
131 |
|
case 2: |
132 |
|
updStr = "3-10 min"; |
133 |
|
break; |
134 |
|
case 3: |
135 |
|
updStr = "> 10 min"; |
136 |
|
break; |
137 |
|
case 4: |
138 |
|
updStr = "No info"; |
139 |
|
break; |
140 |
|
default: |
141 |
|
updStr = "Unknown:" + updated; |
142 |
|
} |
143 |
|
|
144 |
|
return updStr; |
145 |
|
} |
146 |
|
|
147 |
} |
} |