--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2010/09/16 09:11:23 1059 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2010/09/16 13:32:10 1060 @@ -4,8 +4,6 @@ import java.net.URL; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -22,7 +20,7 @@ public class TimetableFetcher { - Map> cache; + Map cache; Map stationCache; StationDAO stationDao = new StationDAO(); @@ -37,14 +35,14 @@ useAzureSite = azureSite; this.replyTimeout = replyTimeout; - cache = new TimeoutMap>(cacheTimeout); + cache = new TimeoutMap(cacheTimeout); stationCache = new TimeoutMap( 3*60*60*1000 ); } - List cachedLookupTimetable(String trainID, String type) throws Exception { + TimetableBean cachedLookupTimetable(String trainID, String type) throws Exception { String key = trainID+type; - List list = cache.get(key); + TimetableBean list = cache.get(key); if (list == null) { list = lookupTimetable(trainID,type); @@ -56,7 +54,7 @@ return list; } - List lookupTimetable(String trainID, String type) throws Exception { + TimetableBean lookupTimetable(String trainID, String type) throws Exception { if (useAzureSite == true ){ return lookupTimetableAzureSite(trainID, type); @@ -81,8 +79,8 @@ return id; } - List lookupTimetableAzureSite(String trainID, String type) throws Exception { - List timetableList = new ArrayList(); + TimetableBean lookupTimetableAzureSite(String trainID, String type) throws Exception { + TimetableBean timetableBean = new TimetableBean(); String url = "http://trafikinfo.bane.dk/TrafikInformation/Ruteplan/" + trainID; @@ -117,43 +115,43 @@ continue; } - TimetableBean bean = new TimetableBean(); + TimetableEntry entry = new TimetableEntry(); String station = fields.get(0).text() ; if (station.equals("København")) station = "København H"; //correct inconsistency in naming - bean.setStation( station ); - bean.setArrival( fields.get(1).text() ); - bean.setDeparture( fields.get(2).text() ); + entry.setStation( station ); + entry.setArrival( fields.get(1).text() ); + entry.setDeparture( fields.get(2).text() ); boolean cancelled = fields.get(3).text().equalsIgnoreCase("aflyst"); - bean.setCancelled(cancelled); + entry.setCancelled(cancelled); if (currentStation == true && currentStationSaved == false ) { - bean.setCurrent(currentStation); + entry.setCurrent(currentStation); currentStationSaved = true; } - bean.setStationId( getStationId( station )); + entry.setStationId( getStationId( station )); - timetableList.add(bean); + timetableBean.entries.add(entry); } //TODO: There is an off-by-one error in this cancelled parser thingie final String cancelledString = "Aflyst"; - for (int i=0;i0 && i lookupTimetableWwwSite(String trainID, String type) throws Exception { - List timetableList = new ArrayList(); + TimetableBean lookupTimetableWwwSite(String trainID, String type) throws Exception { + TimetableBean timetableBean = new TimetableBean(); String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276"; logger.fine("URL:" + url); @@ -207,7 +205,7 @@ continue; } - TimetableBean bean = new TimetableBean(); + TimetableEntry entry = new TimetableEntry(); String station = DepartureFetcher.cleanText( fields.get(0).text() ) ; if (station.equals("København")) @@ -216,19 +214,19 @@ String arrival = DepartureFetcher.cleanText( fields.get(1).text() ); String departure = DepartureFetcher.cleanText( fields.get(2).text() ); - bean.setStation( station ); - bean.setArrival( arrival ); - bean.setDeparture( departure ); + entry.setStation( station ); + entry.setArrival( arrival ); + entry.setDeparture( departure ); if (currentStation == true && currentStationSaved == false ) { - bean.setCurrent(currentStation); + entry.setCurrent(currentStation); currentStationSaved = true; } - bean.setStationId( getStationId( station )); + entry.setStationId( getStationId( station )); - timetableList.add(bean); + timetableBean.entries.add(entry); } } else { @@ -236,7 +234,7 @@ } - return timetableList; + return timetableBean; } }