@Test public void pastWeatherNumberOfRainnnyDaysInFeb2019() { List<WeatherInfo> infos = new WeatherWebApi(new MockRequest()) .pastWeather(37.017,-7.933, parse("2019-02-01"), parse("2019-02-28")); assertEquals(2, filterWeather(infos, wi -> wi.getDesc().equals("Light rain shower")).size()); }
public List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to) { String path = HOST + String.format(PATH_PAST_WEATHER, lat, log, from, to, WEATHER_KEY); Iterator<String> reader = request.getLines(path).iterator(); List<WeatherInfo> infos = new ArrayList<>(); while (reader.next().startsWith("#")) { } reader.next(); while (reader.hasNext()) { infos.add(WeatherInfo.valueOf(reader.next())); if(reader.hasNext()) reader.next(); } return infos; }
WeatherWebApi { public List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to) { String path = HOST + String.format(PATH_PAST_WEATHER, lat, log, from, to, WEATHER_KEY); Iterator<String> reader = request.getLines(path).iterator(); List<WeatherInfo> infos = new ArrayList<>(); while (reader.next().startsWith("#")) { } reader.next(); while (reader.hasNext()) { infos.add(WeatherInfo.valueOf(reader.next())); if(reader.hasNext()) reader.next(); } return infos; } }
WeatherWebApi { public List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to) { String path = HOST + String.format(PATH_PAST_WEATHER, lat, log, from, to, WEATHER_KEY); Iterator<String> reader = request.getLines(path).iterator(); List<WeatherInfo> infos = new ArrayList<>(); while (reader.next().startsWith("#")) { } reader.next(); while (reader.hasNext()) { infos.add(WeatherInfo.valueOf(reader.next())); if(reader.hasNext()) reader.next(); } return infos; } WeatherWebApi(Request request); }
WeatherWebApi { public List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to) { String path = HOST + String.format(PATH_PAST_WEATHER, lat, log, from, to, WEATHER_KEY); Iterator<String> reader = request.getLines(path).iterator(); List<WeatherInfo> infos = new ArrayList<>(); while (reader.next().startsWith("#")) { } reader.next(); while (reader.hasNext()) { infos.add(WeatherInfo.valueOf(reader.next())); if(reader.hasNext()) reader.next(); } return infos; } WeatherWebApi(Request request); List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to); List<LocationInfo> search(String query); }
WeatherWebApi { public List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to) { String path = HOST + String.format(PATH_PAST_WEATHER, lat, log, from, to, WEATHER_KEY); Iterator<String> reader = request.getLines(path).iterator(); List<WeatherInfo> infos = new ArrayList<>(); while (reader.next().startsWith("#")) { } reader.next(); while (reader.hasNext()) { infos.add(WeatherInfo.valueOf(reader.next())); if(reader.hasNext()) reader.next(); } return infos; } WeatherWebApi(Request request); List<WeatherInfo> pastWeather(double lat, double log, LocalDate from, LocalDate to); List<LocationInfo> search(String query);  }