/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1247 by torben, Mon Nov 8 12:39:27 2010 UTC revision 1248 by torben, Thu Mar 31 17:13:19 2011 UTC
# Line 26  public class DepartureFetcher { Line 26  public class DepartureFetcher {
26                  REGIONAL                  REGIONAL
27          }          }
28                    
29            enum FetchTrainType {
30                    STOG,
31                    REGIONAL,
32                    BOTH
33            }
34            
35          Logger logger = Logger.getLogger(DepartureFetcher.class.getName());          Logger logger = Logger.getLogger(DepartureFetcher.class.getName());
36                    
37          Map<String, DepartureBean> cache;          Map<String, DepartureBean> cache;
# Line 44  public class DepartureFetcher { Line 50  public class DepartureFetcher {
50                    
51                                    
52                    
53          public DepartureBean cachedLookupDepartures(int stationID, boolean arrival) throws Exception {          public DepartureBean cachedLookupDepartures(int stationID, boolean arrival, FetchTrainType type) throws Exception {
54                  final String key = "" + stationID + ":" + arrival;                  
55                    final String key = "" + stationID + ":" + arrival + ":" + type.toString();
56                                    
57                  DepartureBean departureBean = cache.get(key);                  DepartureBean departureBean = cache.get(key);
58    
59                                    
60                  if (departureBean == null) {                  if (departureBean == null) {
61                          departureBean = lookupDepartures(stationID,arrival);                          departureBean = lookupDepartures(stationID, arrival, type);
62                          cache.put(key, departureBean);                          cache.put(key, departureBean);
63                  } else {                  } else {
64                          Statistics.getInstance().incrementDepartureCacheHits();                          Statistics.getInstance().incrementDepartureCacheHits();
# Line 61  public class DepartureFetcher { Line 68  public class DepartureFetcher {
68          }          }
69                                    
70    
71          public DepartureBean lookupDepartures(int stationID, boolean arrival) throws Exception {          public DepartureBean lookupDepartures(int stationID, boolean arrival, FetchTrainType type) throws Exception {
72                                    
73                  DepartureBean departureBean = new DepartureBean();                  DepartureBean departureBean = new DepartureBean();
74                                    
# Line 69  public class DepartureFetcher { Line 76  public class DepartureFetcher {
76                                    
77                  departureBean.stationName = station.getName();                  departureBean.stationName = station.getName();
78                                    
79                  if (station.getRegional() != null) {                  if (station.getRegional() != null && (type == FetchTrainType.REGIONAL||type == FetchTrainType.BOTH) ) {
80                          DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival);                          DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival);
81                          departureBean.entries.addAll( tempBean.entries );                          departureBean.entries.addAll( tempBean.entries );
82                          departureBean.notifications.addAll(tempBean.notifications);                          departureBean.notifications.addAll(tempBean.notifications);
83                  }                  }
84                                    
85                  if (station.getStrain() != null) {                  if (station.getStrain() != null && (type == FetchTrainType.STOG||type == FetchTrainType.BOTH)) {
86                          DepartureBean tempBean = lookupDepartures(station.getStrain(), TrainType.STOG, arrival);                          DepartureBean tempBean = lookupDepartures(station.getStrain(), TrainType.STOG, arrival);
87                          departureBean.entries.addAll( tempBean.entries );                          departureBean.entries.addAll( tempBean.entries );
88                          departureBean.notifications.addAll(tempBean.notifications);                          departureBean.notifications.addAll(tempBean.notifications);

Legend:
Removed from v.1247  
changed lines
  Added in v.1248

  ViewVC Help
Powered by ViewVC 1.1.20