Some inner classes were renamed.

This commit is contained in:
Prominence 2018-07-18 22:25:26 +03:00
parent b0cbf1135d
commit 2ecda85e14
4 changed files with 56 additions and 56 deletions

View File

@ -92,7 +92,7 @@ Data calculation time: Mon Jul 16 00:00:00 MSK 2018
``` ```
#### 5 day / 3 hour forecast #### 5 day / 3 hour forecast
First step is retrieving `ForecastRequester` instance: First step is retrieving `HourlyForecastRequester` instance:
```java ```java
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN); OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
ForecastRequester forecastRequester = openWeatherManager.getForecastRequester(); ForecastRequester forecastRequester = openWeatherManager.getForecastRequester();
@ -124,17 +124,17 @@ Available requests:
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. | | `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. | | `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. | | `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.ForecastInfo>` collection with all forecast information. | | `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
| `getAverageTemperature()` | Returns average temperature from forecasts. | | `getAverageTemperature()` | Returns average temperature from forecasts. |
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. | | `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. | | `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
| `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. | | `getByMinimumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is minimal. |
| `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. | | `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
| `getAveragePressure()` | Returns average pressure from forecasts. | | `getAveragePressure()` | Returns average pressure from forecasts. |
| `getMinimumPressure()` | Returns minimum pressure from forecasts. | | `getMinimumPressure()` | Returns minimum pressure from forecasts. |
| `getMaximumPressure()` | Returns maximum pressure from forecasts. | | `getMaximumPressure()` | Returns maximum pressure from forecasts. |
| `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. | | `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is minimal. |
| `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. | | `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where pressure is maximal. |
| `toString()` | Returns pretty string for the whole available forecast information. | | `toString()` | Returns pretty string for the whole available forecast information. |
`toString()` output example: `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 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 | | Method | Description |
|-----------------------------|------------------------------------------------------------------------------------------------------------------| |-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. | | `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. | | `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. | | `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. | | `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. | | `getWind()` | Returns `Wind` instance that contains information about speed and degree. |

View File

@ -32,23 +32,23 @@ import by.prominence.openweathermap.api.utils.RequestUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class ForecastRequester extends BasicRequester<HourlyForecast> { public class HourlyForecastRequester extends BasicRequester<HourlyForecast> {
ForecastRequester(String authToken) { HourlyForecastRequester(String authToken) {
super(authToken); super(authToken);
} }
public ForecastRequester setLanguage(String language) { public HourlyForecastRequester setLanguage(String language) {
this.language = language; this.language = language;
return this; return this;
} }
public ForecastRequester setUnitSystem(String unitSystem) { public HourlyForecastRequester setUnitSystem(String unitSystem) {
this.unitSystem = unitSystem; this.unitSystem = unitSystem;
return this; return this;
} }
public ForecastRequester setAccuracy(String accuracy) { public HourlyForecastRequester setAccuracy(String accuracy) {
this.accuracy = accuracy; this.accuracy = accuracy;
return this; return this;
} }
@ -70,7 +70,7 @@ public class ForecastRequester extends BasicRequester<HourlyForecast> {
forecastResponse.getForecasts().forEach(forecastInfo -> { forecastResponse.getForecasts().forEach(forecastInfo -> {
forecastInfo.getWind().setUnit(windUnit); forecastInfo.getWind().setUnit(windUnit);
forecastInfo.getMainInfo().setTemperatureUnit(temperatureUnit); forecastInfo.getWeatherInfo().setTemperatureUnit(temperatureUnit);
}); });
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();

View File

@ -34,7 +34,7 @@ public class OpenWeatherMapManager {
return new WeatherRequester(authToken); return new WeatherRequester(authToken);
} }
public ForecastRequester getForecastRequester() { public HourlyForecastRequester getForecastRequester() {
return new ForecastRequester(authToken); return new HourlyForecastRequester(authToken);
} }
} }

View File

@ -41,7 +41,7 @@ public class HourlyForecast implements OpenWeatherResponse {
private short cnt; private short cnt;
@JSONField(name = "list") @JSONField(name = "list")
private List<ForecastInfo> forecasts; private List<Forecast> forecasts;
@JSONField(name = "city") @JSONField(name = "city")
private CityInfo cityInfo; private CityInfo cityInfo;
@ -70,11 +70,11 @@ public class HourlyForecast implements OpenWeatherResponse {
this.cnt = cnt; this.cnt = cnt;
} }
public List<ForecastInfo> getForecasts() { public List<Forecast> getForecasts() {
return forecasts; return forecasts;
} }
public void setForecasts(List<ForecastInfo> forecasts) { public void setForecasts(List<Forecast> forecasts) {
this.forecasts = forecasts; this.forecasts = forecasts;
} }
@ -103,43 +103,43 @@ public class HourlyForecast implements OpenWeatherResponse {
} }
public float getAverageTemperature() { 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() { 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() { 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() { public Forecast getByMinimumTemperature() {
return forecasts.stream().min(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.minimumTemperature)).orElse(null); return forecasts.stream().min(Comparator.comparing(forecast -> forecast.weatherInfo.minimumTemperature)).orElse(null);
} }
public ForecastInfo getByMaximumTemperature() { public Forecast getByMaximumTemperature() {
return forecasts.stream().max(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.maximumTemperature)).orElse(null); return forecasts.stream().max(Comparator.comparing(forecast -> forecast.weatherInfo.maximumTemperature)).orElse(null);
} }
public float getAveragePressure() { 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() { 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() { 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() { public Forecast getByMinimumPressure() {
return forecasts.stream().min(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.pressure)).orElse(null); return forecasts.stream().min(Comparator.comparing(forecast -> forecast.weatherInfo.pressure)).orElse(null);
} }
public ForecastInfo getByMaximumPressure() { public Forecast getByMaximumPressure() {
return forecasts.stream().max(Comparator.comparing(forecastInfo -> forecastInfo.mainInfo.pressure)).orElse(null); return forecasts.stream().max(Comparator.comparing(forecast -> forecast.weatherInfo.pressure)).orElse(null);
} }
@Override @Override
@ -147,9 +147,9 @@ public class HourlyForecast implements OpenWeatherResponse {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(cityInfo); stringBuilder.append(cityInfo);
stringBuilder.append("\nForecasts: "); stringBuilder.append("\nForecasts: ");
forecasts.forEach(forecastInfo -> { forecasts.forEach(forecast -> {
stringBuilder.append("\n\t"); stringBuilder.append("\n\t");
stringBuilder.append(forecastInfo); stringBuilder.append(forecast);
}); });
return stringBuilder.toString(); return stringBuilder.toString();
} }
@ -242,14 +242,14 @@ public class HourlyForecast implements OpenWeatherResponse {
} }
public static class ForecastInfo { public static class Forecast {
@JSONField(name = "dt") @JSONField(name = "dt")
// Time of data forecasted, unix, UTC // Time of data calculation, unix, UTC
private long dataCalculationTime; private long dataCalculationTime;
@JSONField(name = "main") @JSONField(name = "main")
private MainInfo mainInfo; private WeatherInfo weatherInfo;
@JSONField(name = "weather") @JSONField(name = "weather")
private List<WeatherState> weatherStates; private List<WeatherState> weatherStates;
@ -280,12 +280,12 @@ public class HourlyForecast implements OpenWeatherResponse {
return new Date(dataCalculationTime * 1000); return new Date(dataCalculationTime * 1000);
} }
public MainInfo getMainInfo() { public WeatherInfo getWeatherInfo() {
return mainInfo; return weatherInfo;
} }
public void setMainInfo(MainInfo mainInfo) { public void setWeatherInfo(WeatherInfo weatherInfo) {
this.mainInfo = mainInfo; this.weatherInfo = weatherInfo;
} }
public List<WeatherState> getWeatherStates() { public List<WeatherState> getWeatherStates() {
@ -356,7 +356,7 @@ public class HourlyForecast implements OpenWeatherResponse {
stringBuilder.append(weatherStates); stringBuilder.append(weatherStates);
} }
stringBuilder.append(". "); stringBuilder.append(". ");
stringBuilder.append(mainInfo); stringBuilder.append(weatherInfo);
if (clouds != null) { if (clouds != null) {
stringBuilder.append(". "); stringBuilder.append(". ");
stringBuilder.append(clouds); stringBuilder.append(clouds);
@ -381,9 +381,9 @@ public class HourlyForecast implements OpenWeatherResponse {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
ForecastInfo that = (ForecastInfo) o; Forecast that = (Forecast) o;
return dataCalculationTime == that.dataCalculationTime && return dataCalculationTime == that.dataCalculationTime &&
Objects.equals(mainInfo, that.mainInfo) && Objects.equals(weatherInfo, that.weatherInfo) &&
Objects.equals(weatherStates, that.weatherStates) && Objects.equals(weatherStates, that.weatherStates) &&
Objects.equals(clouds, that.clouds) && Objects.equals(clouds, that.clouds) &&
Objects.equals(wind, that.wind) && Objects.equals(wind, that.wind) &&
@ -396,7 +396,7 @@ public class HourlyForecast implements OpenWeatherResponse {
@Override @Override
public int hashCode() { 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 { public static class ForecastSystemInfo {
@ -433,7 +433,7 @@ public class HourlyForecast implements OpenWeatherResponse {
} }
} }
public static class MainInfo { public static class WeatherInfo {
@JSONField(name = "temp") @JSONField(name = "temp")
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit. // Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@ -587,15 +587,15 @@ public class HourlyForecast implements OpenWeatherResponse {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
MainInfo mainInfo = (MainInfo) o; WeatherInfo weatherInfo = (WeatherInfo) o;
return Float.compare(mainInfo.temperature, temperature) == 0 && return Float.compare(weatherInfo.temperature, temperature) == 0 &&
Float.compare(mainInfo.minimumTemperature, minimumTemperature) == 0 && Float.compare(weatherInfo.minimumTemperature, minimumTemperature) == 0 &&
Float.compare(mainInfo.maximumTemperature, maximumTemperature) == 0 && Float.compare(weatherInfo.maximumTemperature, maximumTemperature) == 0 &&
Float.compare(mainInfo.pressure, pressure) == 0 && Float.compare(weatherInfo.pressure, pressure) == 0 &&
Float.compare(mainInfo.seaLevelPressure, seaLevelPressure) == 0 && Float.compare(weatherInfo.seaLevelPressure, seaLevelPressure) == 0 &&
Float.compare(mainInfo.groundLevelPressure, groundLevelPressure) == 0 && Float.compare(weatherInfo.groundLevelPressure, groundLevelPressure) == 0 &&
humidity == mainInfo.humidity && humidity == weatherInfo.humidity &&
Float.compare(mainInfo.temperatureCoefficient, temperatureCoefficient) == 0; Float.compare(weatherInfo.temperatureCoefficient, temperatureCoefficient) == 0;
} }
@Override @Override