1 |
package dk.thoerup.traininfoservice.banedk; |
package dk.thoerup.traininfoservice.banedk; |
2 |
|
|
3 |
public class DepartureBean { |
public class DepartureEntry implements Comparable<DepartureEntry> { |
4 |
private String time; |
private String time; |
5 |
private int updated; |
private int updated; |
6 |
private String trainNumber; |
private String trainNumber; |
9 |
private String location; |
private String location; |
10 |
private String status; |
private String status; |
11 |
private String note; |
private String note; |
12 |
|
private String type; |
13 |
|
|
14 |
|
|
15 |
public String getTime() { |
public String getTime() { |
61 |
this.note = note; |
this.note = note; |
62 |
} |
} |
63 |
|
|
64 |
|
public String getType() { |
65 |
|
return type; |
66 |
|
} |
67 |
|
|
68 |
|
public void setType(String type) { |
69 |
|
this.type = type; |
70 |
|
} |
71 |
|
|
72 |
|
@Override |
73 |
|
public int compareTo(DepartureEntry otherBean) { |
74 |
|
String timeStr1 = time.replace(":","").trim(); |
75 |
|
String timeStr2 = otherBean.time.replace(":","").trim(); |
76 |
|
|
77 |
|
int time1 = 0; |
78 |
|
int time2 = 0; |
79 |
|
|
80 |
|
if (timeStr1.length() > 0) |
81 |
|
time1 = Integer.parseInt(timeStr1); |
82 |
|
|
83 |
|
if (timeStr2.length() > 0) |
84 |
|
time2 = Integer.parseInt(timeStr2); |
85 |
|
|
86 |
|
//work correctly when clock wraps around at midnight |
87 |
|
if (Math.abs(time1-time2) < 1200) { |
88 |
|
if (time1 > time2) |
89 |
|
return 1; |
90 |
|
else |
91 |
|
return -1; |
92 |
|
} else { |
93 |
|
if (time1 < time2) |
94 |
|
return 1; |
95 |
|
else |
96 |
|
return -1; |
97 |
|
|
98 |
|
} |
99 |
|
|
100 |
|
} |
101 |
|
|
102 |
|
public String getUpdatedString() { |
103 |
|
String updStr; |
104 |
|
|
105 |
|
switch (updated) { |
106 |
|
case 1: |
107 |
|
updStr = "< 3 min"; |
108 |
|
break; |
109 |
|
case 2: |
110 |
|
updStr = "3-10 min"; |
111 |
|
break; |
112 |
|
case 3: |
113 |
|
updStr = "> 10 min"; |
114 |
|
break; |
115 |
|
case 4: |
116 |
|
updStr = "No info"; |
117 |
|
break; |
118 |
|
default: |
119 |
|
updStr = "Unknown:" + updated; |
120 |
|
} |
121 |
|
|
122 |
|
return updStr; |
123 |
|
} |
124 |
|
|
125 |
} |
} |