4 |
import java.net.URL; |
import java.net.URL; |
5 |
import java.net.URLEncoder; |
import java.net.URLEncoder; |
6 |
import java.util.Collections; |
import java.util.Collections; |
7 |
|
import java.util.Comparator; |
8 |
import java.util.Map; |
import java.util.Map; |
9 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
10 |
|
|
45 |
|
|
46 |
private TraininfoSettings settings; |
private TraininfoSettings settings; |
47 |
|
|
48 |
|
Comparator<DepartureEntry> departureTimeComparator = new Comparator<DepartureEntry>() { |
49 |
|
|
50 |
|
@Override |
51 |
|
public int compare(DepartureEntry arg0, DepartureEntry arg1) { |
52 |
|
String timeStr1 = arg0.getTime().replace(":","").trim(); |
53 |
|
String timeStr2 = arg1.getTime().replace(":","").trim(); |
54 |
|
|
55 |
|
int time1 = 0; |
56 |
|
int time2 = 0; |
57 |
|
|
58 |
|
if (timeStr1.length() > 0) |
59 |
|
time1 = Integer.parseInt(timeStr1); |
60 |
|
|
61 |
|
if (timeStr2.length() > 0) |
62 |
|
time2 = Integer.parseInt(timeStr2); |
63 |
|
|
64 |
|
//work correctly when clock wraps around at midnight |
65 |
|
if (Math.abs(time1-time2) < 1200) { |
66 |
|
if (time1 > time2) |
67 |
|
return 1; |
68 |
|
else |
69 |
|
return -1; |
70 |
|
} else { |
71 |
|
if (time1 < time2) |
72 |
|
return 1; |
73 |
|
else |
74 |
|
return -1; |
75 |
|
|
76 |
|
} |
77 |
|
|
78 |
|
} |
79 |
|
|
80 |
|
}; |
81 |
|
|
82 |
public DepartureFetcher(TraininfoSettings settings) { |
public DepartureFetcher(TraininfoSettings settings) { |
83 |
this.settings = settings; |
this.settings = settings; |
84 |
cache = new TimeoutMap<String,DepartureBean>( settings.getCacheTimeout() ); |
cache = new TimeoutMap<String,DepartureBean>( settings.getCacheTimeout() ); |
132 |
|
|
133 |
//TODO: FetchTraintype.Both should be removed some time after 0.9.5 release |
//TODO: FetchTraintype.Both should be removed some time after 0.9.5 release |
134 |
if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time |
if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time |
135 |
Collections.sort( departureBean.entries ); |
Collections.sort( departureBean.entries, departureTimeComparator); |
136 |
} |
} |
137 |
|
|
138 |
|
|