From 2ecda85e1444f6a44870a380978ea24317dc4b1e Mon Sep 17 00:00:00 2001 From: Prominence Date: Wed, 18 Jul 2018 22:25:26 +0300 Subject: [PATCH] Some inner classes were renamed. --- README.md | 16 ++-- ...ster.java => HourlyForecastRequester.java} | 12 +-- .../api/OpenWeatherMapManager.java | 4 +- .../api/model/response/HourlyForecast.java | 80 +++++++++---------- 4 files changed, 56 insertions(+), 56 deletions(-) rename src/main/java/by/prominence/openweathermap/api/{ForecastRequester.java => HourlyForecastRequester.java} (86%) diff --git a/README.md b/README.md index 779a3d0..eb9a1ba 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Data calculation time: Mon Jul 16 00:00:00 MSK 2018 ``` #### 5 day / 3 hour forecast -First step is retrieving `ForecastRequester` instance: +First step is retrieving `HourlyForecastRequester` instance: ```java OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN); ForecastRequester forecastRequester = openWeatherManager.getForecastRequester(); @@ -124,17 +124,17 @@ Available requests: | `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. | | `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. | | `getCountry()` | An alias for `getCityInfo().getCountry()`. | -| `getForecasts()` | Returns `List` collection with all forecast information. | +| `getForecasts()` | Returns `List` collection with all forecast information. | | `getAverageTemperature()` | Returns average temperature from forecasts. | | `getMinimumTemperature()` | Returns minimum temperature from forecasts. | | `getMaximumTemperature()` | Returns maximum temperature from forecasts. | -| `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. | -| `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. | +| `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. | +| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. | | `getAveragePressure()` | Returns average pressure from forecasts. | | `getMinimumPressure()` | Returns minimum pressure from forecasts. | | `getMaximumPressure()` | Returns maximum pressure from forecasts. | -| `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. | -| `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. | +| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. | +| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. | | `toString()` | Returns pretty string for the whole available forecast information. | `toString()` output example: @@ -184,13 +184,13 @@ Forecasts: Time: Sat Jul 21 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.56 ℃. Minimum temperature: 22.56 ℃. Maximum temperature: 22.56 ℃. Pressure: 1001.72 hPa. Sea-level pressure: 1022.7 hPa. Ground-level pressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm ``` -`ForecastInfo`'s useful public methods(setters are not listed): +`Forecast`'s useful public methods(setters are not listed): | Method | Description | |-----------------------------|------------------------------------------------------------------------------------------------------------------| | `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. | | `getDataCalculationDate()` | Returns data calculation time in `Date` representation. | -| `getMainInfo()` | Returns `HourlyForecast.MainInfo` instance that contains information about temperature, pressure and humidity. | +| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, pressure and humidity.| | `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. | | `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. | | `getWind()` | Returns `Wind` instance that contains information about speed and degree. | diff --git a/src/main/java/by/prominence/openweathermap/api/ForecastRequester.java b/src/main/java/by/prominence/openweathermap/api/HourlyForecastRequester.java similarity index 86% rename from src/main/java/by/prominence/openweathermap/api/ForecastRequester.java rename to src/main/java/by/prominence/openweathermap/api/HourlyForecastRequester.java index a89727d..dbfd8ff 100644 --- a/src/main/java/by/prominence/openweathermap/api/ForecastRequester.java +++ b/src/main/java/by/prominence/openweathermap/api/HourlyForecastRequester.java @@ -32,23 +32,23 @@ import by.prominence.openweathermap.api.utils.RequestUtils; import java.io.IOException; import java.io.InputStream; -public class ForecastRequester extends BasicRequester { +public class HourlyForecastRequester extends BasicRequester { - ForecastRequester(String authToken) { + HourlyForecastRequester(String authToken) { super(authToken); } - public ForecastRequester setLanguage(String language) { + public HourlyForecastRequester setLanguage(String language) { this.language = language; return this; } - public ForecastRequester setUnitSystem(String unitSystem) { + public HourlyForecastRequester setUnitSystem(String unitSystem) { this.unitSystem = unitSystem; return this; } - public ForecastRequester setAccuracy(String accuracy) { + public HourlyForecastRequester setAccuracy(String accuracy) { this.accuracy = accuracy; return this; } @@ -70,7 +70,7 @@ public class ForecastRequester extends BasicRequester { forecastResponse.getForecasts().forEach(forecastInfo -> { forecastInfo.getWind().setUnit(windUnit); - forecastInfo.getMainInfo().setTemperatureUnit(temperatureUnit); + forecastInfo.getWeatherInfo().setTemperatureUnit(temperatureUnit); }); } catch (IOException ex) { ex.printStackTrace(); diff --git a/src/main/java/by/prominence/openweathermap/api/OpenWeatherMapManager.java b/src/main/java/by/prominence/openweathermap/api/OpenWeatherMapManager.java index 8456249..ac5c6cf 100644 --- a/src/main/java/by/prominence/openweathermap/api/OpenWeatherMapManager.java +++ b/src/main/java/by/prominence/openweathermap/api/OpenWeatherMapManager.java @@ -34,7 +34,7 @@ public class OpenWeatherMapManager { return new WeatherRequester(authToken); } - public ForecastRequester getForecastRequester() { - return new ForecastRequester(authToken); + public HourlyForecastRequester getForecastRequester() { + return new HourlyForecastRequester(authToken); } } diff --git a/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java b/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java index 43c3032..c3af464 100644 --- a/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java +++ b/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java @@ -41,7 +41,7 @@ public class HourlyForecast implements OpenWeatherResponse { private short cnt; @JSONField(name = "list") - private List forecasts; + private List forecasts; @JSONField(name = "city") private CityInfo cityInfo; @@ -70,11 +70,11 @@ public class HourlyForecast implements OpenWeatherResponse { this.cnt = cnt; } - public List getForecasts() { + public List getForecasts() { return forecasts; } - public void setForecasts(List forecasts) { + public void setForecasts(List forecasts) { this.forecasts = forecasts; } @@ -103,43 +103,43 @@ public class HourlyForecast implements OpenWeatherResponse { } public float getAverageTemperature() { - return (float)forecasts.stream().mapToDouble(forecast -> forecast.mainInfo.temperature).average().orElse(0f); + return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.temperature).average().orElse(0f); } public float getMinimumTemperature() { - return (float)forecasts.stream().mapToDouble(forecast -> forecast.mainInfo.temperature).min().orElse(0f); + return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.temperature).min().orElse(0f); } public float getMaximumTemperature() { - return (float)forecasts.stream().mapToDouble(forecast -> forecast.mainInfo.temperature).max().orElse(0f); + return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.temperature).max().orElse(0f); } - public ForecastInfo getByMinimumTemperature() { - return forecasts.stream().min(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.minimumTemperature)).orElse(null); + public Forecast getByMinimumTemperature() { + return forecasts.stream().min(Comparator.comparing(forecast -> forecast.weatherInfo.minimumTemperature)).orElse(null); } - public ForecastInfo getByMaximumTemperature() { - return forecasts.stream().max(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.maximumTemperature)).orElse(null); + public Forecast getByMaximumTemperature() { + return forecasts.stream().max(Comparator.comparing(forecast -> forecast.weatherInfo.maximumTemperature)).orElse(null); } public float getAveragePressure() { - return (float)forecasts.stream().mapToDouble(forecast -> forecast.mainInfo.pressure).average().orElse(0f); + return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.pressure).average().orElse(0f); } public float getMinimumPressure() { - return (float)forecasts.stream().mapToDouble(forecast -> forecast.mainInfo.pressure).min().orElse(0f); + return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.pressure).min().orElse(0f); } public float getMaximumPressure() { - return (float)forecasts.stream().mapToDouble(forecast -> forecast.mainInfo.pressure).max().orElse(0f); + return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.pressure).max().orElse(0f); } - public ForecastInfo getByMinimumPressure() { - return forecasts.stream().min(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.pressure)).orElse(null); + public Forecast getByMinimumPressure() { + return forecasts.stream().min(Comparator.comparing(forecast -> forecast.weatherInfo.pressure)).orElse(null); } - public ForecastInfo getByMaximumPressure() { - return forecasts.stream().max(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.pressure)).orElse(null); + public Forecast getByMaximumPressure() { + return forecasts.stream().max(Comparator.comparing(forecast -> forecast.weatherInfo.pressure)).orElse(null); } @Override @@ -147,9 +147,9 @@ public class HourlyForecast implements OpenWeatherResponse { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(cityInfo); stringBuilder.append("\nForecasts: "); - forecasts.forEach(forecastInfo -> { + forecasts.forEach(forecast -> { stringBuilder.append("\n\t"); - stringBuilder.append(forecastInfo); + stringBuilder.append(forecast); }); return stringBuilder.toString(); } @@ -242,14 +242,14 @@ public class HourlyForecast implements OpenWeatherResponse { } - public static class ForecastInfo { + public static class Forecast { @JSONField(name = "dt") - // Time of data forecasted, unix, UTC + // Time of data calculation, unix, UTC private long dataCalculationTime; @JSONField(name = "main") - private MainInfo mainInfo; + private WeatherInfo weatherInfo; @JSONField(name = "weather") private List weatherStates; @@ -280,12 +280,12 @@ public class HourlyForecast implements OpenWeatherResponse { return new Date(dataCalculationTime * 1000); } - public MainInfo getMainInfo() { - return mainInfo; + public WeatherInfo getWeatherInfo() { + return weatherInfo; } - public void setMainInfo(MainInfo mainInfo) { - this.mainInfo = mainInfo; + public void setWeatherInfo(WeatherInfo weatherInfo) { + this.weatherInfo = weatherInfo; } public List getWeatherStates() { @@ -356,7 +356,7 @@ public class HourlyForecast implements OpenWeatherResponse { stringBuilder.append(weatherStates); } stringBuilder.append(". "); - stringBuilder.append(mainInfo); + stringBuilder.append(weatherInfo); if (clouds != null) { stringBuilder.append(". "); stringBuilder.append(clouds); @@ -381,9 +381,9 @@ public class HourlyForecast implements OpenWeatherResponse { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ForecastInfo that = (ForecastInfo) o; + Forecast that = (Forecast) o; return dataCalculationTime == that.dataCalculationTime && - Objects.equals(mainInfo, that.mainInfo) && + Objects.equals(weatherInfo, that.weatherInfo) && Objects.equals(weatherStates, that.weatherStates) && Objects.equals(clouds, that.clouds) && Objects.equals(wind, that.wind) && @@ -396,7 +396,7 @@ public class HourlyForecast implements OpenWeatherResponse { @Override public int hashCode() { - return Objects.hash(dataCalculationTime, mainInfo, weatherStates, clouds, wind, snow, rain, systemInfo, dt_txt); + return Objects.hash(dataCalculationTime, weatherInfo, weatherStates, clouds, wind, snow, rain, systemInfo, dt_txt); } public static class ForecastSystemInfo { @@ -433,7 +433,7 @@ public class HourlyForecast implements OpenWeatherResponse { } } - public static class MainInfo { + public static class WeatherInfo { @JSONField(name = "temp") // Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit. @@ -587,15 +587,15 @@ public class HourlyForecast implements OpenWeatherResponse { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - MainInfo mainInfo = (MainInfo) o; - return Float.compare(mainInfo.temperature, temperature) == 0 && - Float.compare(mainInfo.minimumTemperature, minimumTemperature) == 0 && - Float.compare(mainInfo.maximumTemperature, maximumTemperature) == 0 && - Float.compare(mainInfo.pressure, pressure) == 0 && - Float.compare(mainInfo.seaLevelPressure, seaLevelPressure) == 0 && - Float.compare(mainInfo.groundLevelPressure, groundLevelPressure) == 0 && - humidity == mainInfo.humidity && - Float.compare(mainInfo.temperatureCoefficient, temperatureCoefficient) == 0; + WeatherInfo weatherInfo = (WeatherInfo) o; + return Float.compare(weatherInfo.temperature, temperature) == 0 && + Float.compare(weatherInfo.minimumTemperature, minimumTemperature) == 0 && + Float.compare(weatherInfo.maximumTemperature, maximumTemperature) == 0 && + Float.compare(weatherInfo.pressure, pressure) == 0 && + Float.compare(weatherInfo.seaLevelPressure, seaLevelPressure) == 0 && + Float.compare(weatherInfo.groundLevelPressure, groundLevelPressure) == 0 && + humidity == weatherInfo.humidity && + Float.compare(weatherInfo.temperatureCoefficient, temperatureCoefficient) == 0; } @Override