12 |
import org.jsoup.nodes.Element; |
import org.jsoup.nodes.Element; |
13 |
import org.jsoup.select.Elements; |
import org.jsoup.select.Elements; |
14 |
|
|
15 |
|
import dk.thoerup.android.traininfo.common.StationBean; |
16 |
|
import dk.thoerup.android.traininfo.common.StationEntry; |
17 |
import dk.thoerup.android.traininfo.common.TimetableBean; |
import dk.thoerup.android.traininfo.common.TimetableBean; |
18 |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
19 |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
27 |
|
|
28 |
|
|
29 |
Map<String, TimetableBean> cache; |
Map<String, TimetableBean> cache; |
30 |
Map<String, Integer> stationCache; |
Map<String, StationEntry> stationCache; |
31 |
|
|
32 |
StationDAO stationDao = new StationDAO(); |
StationDAO stationDao = new StationDAO(); |
33 |
|
|
40 |
this.settings = settings; |
this.settings = settings; |
41 |
|
|
42 |
cache = new TimeoutMap<String,TimetableBean>( settings.getCacheTimeout() ); |
cache = new TimeoutMap<String,TimetableBean>( settings.getCacheTimeout() ); |
43 |
stationCache = new TimeoutMap<String,Integer>( 3*60*60*1000 ); |
stationCache = new TimeoutMap<String,StationEntry>( 3*60*60*1000 ); |
44 |
} |
} |
45 |
|
|
46 |
|
|
67 |
} |
} |
68 |
} |
} |
69 |
|
|
70 |
int getStationId(String name) { |
StationEntry getStationId(String name) { |
71 |
Integer id = stationCache.get(name); |
StationEntry station = stationCache.get(name); |
72 |
|
|
73 |
if (id == null) { |
if (station == null) { |
74 |
try { |
try { |
75 |
id = stationDao.getIdByName(name); |
StationBean bean = stationDao.getByName(name); |
76 |
stationCache.put(name, id); |
if (bean.entries.size() == 1) { |
77 |
|
station = bean.entries.get(0); |
78 |
|
stationCache.put(name,station); |
79 |
|
} |
80 |
} catch (SQLException e) { |
} catch (SQLException e) { |
81 |
logger.log(Level.SEVERE, "getStationId failed", e); |
logger.log(Level.SEVERE, "getStationId failed", e); |
|
id = -1; |
|
82 |
} |
} |
83 |
} |
} |
84 |
|
|
85 |
return id; |
return station; |
86 |
} |
} |
87 |
|
|
88 |
String correctStationName(String name) { |
String correctStationName(String name) { |