28 |
|
|
29 |
StationBean stations = new StationBean(); |
StationBean stations = new StationBean(); |
30 |
|
|
31 |
|
boolean statsByNameSend = false; |
32 |
|
|
33 |
public boolean hasStations() { |
public boolean hasStations() { |
34 |
return (stations != null && stations.entries.size() > 0); |
return (stations != null && stations.entries.size() > 0); |
35 |
} |
} |
86 |
File parent = context.getFilesDir(); |
File parent = context.getFilesDir(); |
87 |
File stationsFile = new File(parent, "stations.bin"); |
File stationsFile = new File(parent, "stations.bin"); |
88 |
|
|
89 |
|
long start = System.currentTimeMillis(); |
90 |
byte data[] = HttpUtil.getContent(XmlUtil.SERVICE_BASE + "/LocateStations?dump=1", 5000); |
byte data[] = HttpUtil.getContent(XmlUtil.SERVICE_BASE + "/LocateStations?dump=1", 5000); |
91 |
Serializer serializer = new Persister(); |
logElapsedTime(start, "download XML"); |
92 |
|
|
93 |
|
|
94 |
|
Serializer serializer = new Persister(); |
95 |
|
|
96 |
|
start = System.currentTimeMillis(); |
97 |
StationBean tmpStations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") ); |
StationBean tmpStations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") ); |
98 |
|
logElapsedTime(start, "parse XML"); |
99 |
|
|
100 |
|
|
101 |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
181 |
|
|
182 |
@Override |
@Override |
183 |
public StationBean lookupStationsByName(String name) { |
public StationBean lookupStationsByName(String name) { |
184 |
|
|
185 |
|
statsByName(name); |
186 |
|
|
187 |
long start = System.currentTimeMillis(); |
long start = System.currentTimeMillis(); |
188 |
|
|
189 |
name = name.toLowerCase(); |
name = name.toLowerCase(); |
190 |
StationBean tmpStations = new StationBean(); |
StationBean tmpStations = new StationBean(); |
191 |
for (StationEntry entry : stations.entries) { |
for (StationEntry entry : stations.entries) { |
192 |
if (entry.nameLower.startsWith(name) || entry.nameInternational.startsWith(name) ) { |
if (entry.nameLower.startsWith(name) || entry.nameInternational.startsWith(name) || aliasNameMatch(name,entry) ) { |
193 |
tmpStations.entries.add(entry); |
tmpStations.entries.add(entry); |
194 |
} |
} |
195 |
} |
} |
196 |
logElapsedTime(start, "name"); |
logElapsedTime(start, "name"); |
197 |
return tmpStations; |
return tmpStations; |
198 |
} |
} |
199 |
|
|
200 |
|
private boolean aliasNameMatch(String name, StationEntry station) { |
201 |
|
for(String alias : station.getAliases()) { |
202 |
|
if (alias.startsWith(name)) { |
203 |
|
return true; |
204 |
|
} |
205 |
|
} |
206 |
|
return false; |
207 |
|
} |
208 |
|
|
209 |
@Override |
@Override |
210 |
public StationBean lookupStationsByIds(String ids) { |
public StationBean lookupStationsByIds(String ids) { |
234 |
} |
} |
235 |
|
|
236 |
private void statsByName(String name) { |
private void statsByName(String name) { |
237 |
|
if (statsByNameSend == true) { |
238 |
|
return; |
239 |
|
} |
240 |
|
statsByNameSend = true; |
241 |
|
|
242 |
try { |
try { |
243 |
name = URLEncoder.encode(name, "ISO8859-1"); |
name = URLEncoder.encode(name, "ISO8859-1"); |