/[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 1061 by torben, Thu Sep 16 14:04:28 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.departureEntries.addAll( tempBean.departureEntries );                          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.departureEntries.addAll( tempBean.departureEntries );                          departureBean.entries.addAll( tempBean.entries );
88                          departureBean.notifications.addAll(tempBean.notifications);                          departureBean.notifications.addAll(tempBean.notifications);
89                  }                                }              
90                                    
91                  if (departureBean.departureEntries.size() == 0) {                  if (departureBean.entries.size() == 0) {
92                          logger.info("No departures found for station " + stationID);                          logger.info("No departures found for station " + stationID);
93                  }                  }
94                                    
95                  Collections.sort( departureBean.departureEntries );                  Collections.sort( departureBean.entries );
96    
97                                    
98                  return departureBean;                  return departureBean;
# Line 145  public class DepartureFetcher { Line 152  public class DepartureFetcher {
152              if (table != null) {              if (table != null) {
153                      Elements tableRows =  table.getElementsByTag("tr");                      Elements tableRows =  table.getElementsByTag("tr");
154                                            
155                      boolean tidsstregExists = (table.getElementsByAttributeValue("class", "Tidsstreg").size() > 0);                      //boolean tidsstregExists = (table.getElementsByAttributeValue("class", "Tidsstreg").size() > 0);
156                      boolean passedTidsstreg = false;                      //boolean passedTidsstreg = false;
157                                            
158                      for (Element currentRow : tableRows) {                      for (Element currentRow : tableRows) {
159                          String rowClass = currentRow.attr("class");                          String rowClass = currentRow.attr("class");
160                                                    /*
161                          if (tidsstregExists == true && passedTidsstreg == false) {                          if (tidsstregExists == true && passedTidsstreg == false) {
162                                  if (currentRow.getElementsByAttributeValue("class", "Tidsstreg").size() > 0) {                                  if (currentRow.getElementsByAttributeValue("class", "Tidsstreg").size() > 0) {
163                                          passedTidsstreg = true;                                          passedTidsstreg = true;
164                                  } else {                                  } else {
165                                          continue;                                          continue;
166                                  }                                  }
167                          }                          }*/
168                                                    
169                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {
170                                                                    
# Line 195  public class DepartureFetcher { Line 202  public class DepartureFetcher {
202                                                                    
203                                  departure.setType(typeString);                                  departure.setType(typeString);
204                                                                    
205                                  departureBean.departureEntries.add( departure );                                  departureBean.entries.add( departure );
206                          }                          }
207                      }                      }
208              } else {              } else {
# Line 253  public class DepartureFetcher { Line 260  public class DepartureFetcher {
260              if (table != null) {              if (table != null) {
261                      Elements tableRows =  table.getElementsByTag("tr");                      Elements tableRows =  table.getElementsByTag("tr");
262                                            
263                      boolean passedTidsstreg = false;                      //boolean passedTidsstreg = false;
264                      boolean tidsstregExists = (table.getElementsByAttributeValue("class", "Tidsstreg").size() > 0);                      //boolean tidsstregExists = (table.getElementsByAttributeValue("class", "Tidsstreg").size() > 0);
265                                            
266                      for (Element currentRow : tableRows) {                      for (Element currentRow : tableRows) {
267                          String rowClass = currentRow.attr("class");                          String rowClass = currentRow.attr("class");
268                                                    /*
269                          if (tidsstregExists == true && passedTidsstreg == false) {                          if (tidsstregExists == true && passedTidsstreg == false) {
270                                  if (currentRow.getElementsByAttributeValue("class", "Tidsstreg").size() > 0) {                                  if (currentRow.getElementsByAttributeValue("class", "Tidsstreg").size() > 0) {
271                                          passedTidsstreg = true;                                          passedTidsstreg = true;
272                                  } else {                                  } else {
273                                          continue;                                          continue;
274                                  }                                  }
275                          }                          }*/
276                                                    
277                                                    
278                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {
# Line 305  public class DepartureFetcher { Line 312  public class DepartureFetcher {
312                                                                    
313                                  departure.setType(type);                                  departure.setType(type);
314                                                                    
315                                  departureBean.departureEntries.add(departure);                                  departureBean.entries.add(departure);
316                                                                    
317                                                                    
318                          }                          }

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

  ViewVC Help
Powered by ViewVC 1.1.20