mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 03:06:45 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4998663298 | |||
| f5d202aee3 |
@@ -26,14 +26,14 @@ Paid:
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.0.0')
|
compile('com.github.prominence:openweathermap-api:2.0.1')
|
||||||
```
|
```
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
@@ -41,6 +41,7 @@ compile('com.github.prominence:openweathermap-api:2.0.0')
|
|||||||
* [OpenWeatherMap Java API - 1.1](docs/Release_1.1.md)
|
* [OpenWeatherMap Java API - 1.1](docs/Release_1.1.md)
|
||||||
* [OpenWeatherMap Java API - 1.2](docs/Release_1.2.md)
|
* [OpenWeatherMap Java API - 1.2](docs/Release_1.2.md)
|
||||||
* [OpenWeatherMap Java API - 2.0.0](docs/Release_2.0.0.md)
|
* [OpenWeatherMap Java API - 2.0.0](docs/Release_2.0.0.md)
|
||||||
|
* [OpenWeatherMap Java API - 2.0.1](docs/Release_2.0.1.md)
|
||||||
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
|
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|||||||
@@ -0,0 +1,253 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3-hour forecast
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
compile('com.github.prominence:openweathermap-api:2.0.1')
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently, available APIs are:
|
||||||
|
* `currentWeather()`
|
||||||
|
* `forecast5Day3HourStep()`
|
||||||
|
|
||||||
|
Default(more or less) customization points:
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
// response language
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
...
|
||||||
|
// response units of measure
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Available output forms:
|
||||||
|
* `asJava()`
|
||||||
|
* `asJSON()`
|
||||||
|
|
||||||
|
Additional output forms, available for several APIs:
|
||||||
|
* `asXML()`
|
||||||
|
* `asHTML()`
|
||||||
|
|
||||||
|
_All response forms can be in **sync** and **async** variants._
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final String weatherJson = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Weather weather = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final List<Weather> weatherList = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.multiple()
|
||||||
|
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
|
||||||
|
.language(Language.GERMAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byZipCodeAndCountry("220015", "by")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||||
|
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||||
|
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||||
|
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||||
|
| `toString()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3-hour forecast
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final Forecast forecast = openWeatherClient
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastJson = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("New York", "NY", "US")
|
||||||
|
.language(Language.SPANISH)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
CompletableFuture<String> forecastFuture = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityId(350001514)
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastXml = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byZipCodeInUSA("10005")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.request.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||||
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
A forecast for Minsk with 15 timestamps.
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||||
|
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||||
|
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||||
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Language
|
||||||
|
| Constant | Description |
|
||||||
|
|-----------------------------------|-------------------------------|
|
||||||
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
|
| Language.CATALAN | Catalan language. |
|
||||||
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.GERMAN | German language. |
|
||||||
|
| Language.GREEK | Greek language. |
|
||||||
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
|
| Language.FINNISH | Finnish language. |
|
||||||
|
| Language.FRENCH | French language. |
|
||||||
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.CROATIAN | Croatian language. |
|
||||||
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.ITALIAN | Italian language. |
|
||||||
|
| Language.JAPANESE | Japanese language. |
|
||||||
|
| Language.KOREAN | Korean language. |
|
||||||
|
| Language.LATVIAN | Latvian language. |
|
||||||
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.DUTCH | Dutch language. |
|
||||||
|
| Language.POLISH | Polish language. |
|
||||||
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.ROMANIAN | Romanian language. |
|
||||||
|
| Language.RUSSIAN | Russian language. |
|
||||||
|
| Language.SWEDISH | Swedish language. |
|
||||||
|
| Language.SLOVAK | Slovak language. |
|
||||||
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.TURKISH | Turkish language. |
|
||||||
|
| Language.UKRANIAN | Ukrainian language. |
|
||||||
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
|
||||||
|
#### Unit
|
||||||
|
| Constant | Description |
|
||||||
|
|----------------------|------------------------------------------------|
|
||||||
|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||||
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
||||||
|
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||||
|
* junit:junit:4.13.1 (*test*)
|
||||||
+4
-2
@@ -8,14 +8,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.0.0-SNAPSHOT')
|
compile('com.github.prominence:openweathermap-api:2.0.1-SNAPSHOT')
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
@@ -105,6 +105,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
|||||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||||
|
| `getWeatherIconId()` | Returns a weather state ID. Examples: `01d`, `01n`, `11n`, etc. |
|
||||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||||
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
@@ -188,6 +189,7 @@ A forecast for Minsk with 15 timestamps.
|
|||||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||||
|
| `getWeatherIconId()` | Returns a weather state ID. Examples: `01d`, `01n`, `11n`, etc. |
|
||||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Java OpenWeatherMap API</name>
|
<name>Java OpenWeatherMap API</name>
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ public enum UnitSystem {
|
|||||||
public String getTemperatureUnit() {
|
public String getTemperatureUnit() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case METRIC:
|
case METRIC:
|
||||||
return "℃";
|
return "°C";
|
||||||
case IMPERIAL:
|
case IMPERIAL:
|
||||||
return "℉";
|
return "°F";
|
||||||
case STANDARD:
|
case STANDARD:
|
||||||
default:
|
default:
|
||||||
return "K";
|
return "K";
|
||||||
|
|||||||
+25
-13
@@ -33,7 +33,7 @@ import java.util.Objects;
|
|||||||
public class WeatherForecast {
|
public class WeatherForecast {
|
||||||
private String state;
|
private String state;
|
||||||
private String description;
|
private String description;
|
||||||
private String weatherIconUrl;
|
private String weatherIconId;
|
||||||
|
|
||||||
private LocalDateTime forecastTime;
|
private LocalDateTime forecastTime;
|
||||||
|
|
||||||
@@ -113,22 +113,34 @@ public class WeatherForecast {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets weather icon ID.
|
||||||
|
*
|
||||||
|
* @return the weather icon ID
|
||||||
|
*/
|
||||||
|
public String getWeatherIconId() {
|
||||||
|
return weatherIconId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets weather icon ID.
|
||||||
|
*
|
||||||
|
* @param weatherIconId the weather icon ID
|
||||||
|
*/
|
||||||
|
public void setWeatherIconId(String weatherIconId) {
|
||||||
|
this.weatherIconId = weatherIconId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets weather icon url.
|
* Gets weather icon url.
|
||||||
*
|
*
|
||||||
* @return the weather icon url
|
* @return the weather icon url
|
||||||
*/
|
*/
|
||||||
public String getWeatherIconUrl() {
|
public String getWeatherIconUrl() {
|
||||||
return weatherIconUrl;
|
if (weatherIconId != null) {
|
||||||
}
|
return "https://openweathermap.org/img/w/" + weatherIconId + ".png";
|
||||||
|
}
|
||||||
/**
|
return null;
|
||||||
* Sets weather icon url.
|
|
||||||
*
|
|
||||||
* @param weatherIconUrl the weather icon url
|
|
||||||
*/
|
|
||||||
public void setWeatherIconUrl(String weatherIconUrl) {
|
|
||||||
this.weatherIconUrl = weatherIconUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -318,7 +330,7 @@ public class WeatherForecast {
|
|||||||
WeatherForecast that = (WeatherForecast) o;
|
WeatherForecast that = (WeatherForecast) o;
|
||||||
return Objects.equals(state, that.state) &&
|
return Objects.equals(state, that.state) &&
|
||||||
Objects.equals(description, that.description) &&
|
Objects.equals(description, that.description) &&
|
||||||
Objects.equals(weatherIconUrl, that.weatherIconUrl) &&
|
Objects.equals(weatherIconId, that.weatherIconId) &&
|
||||||
Objects.equals(forecastTime, that.forecastTime) &&
|
Objects.equals(forecastTime, that.forecastTime) &&
|
||||||
Objects.equals(temperature, that.temperature) &&
|
Objects.equals(temperature, that.temperature) &&
|
||||||
Objects.equals(atmosphericPressure, that.atmosphericPressure) &&
|
Objects.equals(atmosphericPressure, that.atmosphericPressure) &&
|
||||||
@@ -333,7 +345,7 @@ public class WeatherForecast {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(state, description, weatherIconUrl, forecastTime, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
return Objects.hash(state, description, weatherIconId, forecastTime, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import java.util.Objects;
|
|||||||
public class Weather {
|
public class Weather {
|
||||||
private String state;
|
private String state;
|
||||||
private String description;
|
private String description;
|
||||||
private String weatherIconUrl;
|
private String weatherIconId;
|
||||||
|
|
||||||
private LocalDateTime calculatedOn;
|
private LocalDateTime calculatedOn;
|
||||||
|
|
||||||
@@ -112,22 +112,34 @@ public class Weather {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets weather icon ID.
|
||||||
|
*
|
||||||
|
* @return the weather icon ID
|
||||||
|
*/
|
||||||
|
public String getWeatherIconId() {
|
||||||
|
return weatherIconId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets weather icon ID.
|
||||||
|
*
|
||||||
|
* @param weatherIconId the weather icon ID
|
||||||
|
*/
|
||||||
|
public void setWeatherIconId(String weatherIconId) {
|
||||||
|
this.weatherIconId = weatherIconId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets weather icon url.
|
* Gets weather icon url.
|
||||||
*
|
*
|
||||||
* @return the weather icon url
|
* @return the weather icon url
|
||||||
*/
|
*/
|
||||||
public String getWeatherIconUrl() {
|
public String getWeatherIconUrl() {
|
||||||
return weatherIconUrl;
|
if (weatherIconId != null) {
|
||||||
}
|
return "http://openweathermap.org/img/w/" + weatherIconId + ".png";
|
||||||
|
}
|
||||||
/**
|
return null;
|
||||||
* Sets weather icon url.
|
|
||||||
*
|
|
||||||
* @param weatherIconUrl the weather icon url
|
|
||||||
*/
|
|
||||||
public void setWeatherIconUrl(String weatherIconUrl) {
|
|
||||||
this.weatherIconUrl = weatherIconUrl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -299,7 +311,7 @@ public class Weather {
|
|||||||
Weather weather = (Weather) o;
|
Weather weather = (Weather) o;
|
||||||
return Objects.equals(state, weather.state) &&
|
return Objects.equals(state, weather.state) &&
|
||||||
Objects.equals(description, weather.description) &&
|
Objects.equals(description, weather.description) &&
|
||||||
Objects.equals(weatherIconUrl, weather.weatherIconUrl) &&
|
Objects.equals(weatherIconId, weather.weatherIconId) &&
|
||||||
Objects.equals(calculatedOn, weather.calculatedOn) &&
|
Objects.equals(calculatedOn, weather.calculatedOn) &&
|
||||||
Objects.equals(temperature, weather.temperature) &&
|
Objects.equals(temperature, weather.temperature) &&
|
||||||
Objects.equals(atmosphericPressure, weather.atmosphericPressure) &&
|
Objects.equals(atmosphericPressure, weather.atmosphericPressure) &&
|
||||||
@@ -313,7 +325,7 @@ public class Weather {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(state, description, weatherIconUrl, calculatedOn, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, location);
|
return Objects.hash(state, description, weatherIconId, calculatedOn, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+1
-1
@@ -138,7 +138,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
|||||||
weatherNode.get("main").asText(),
|
weatherNode.get("main").asText(),
|
||||||
weatherNode.get("description").asText()
|
weatherNode.get("description").asText()
|
||||||
);
|
);
|
||||||
weatherForecast.setWeatherIconUrl("https://openweathermap.org/img/w/" + weatherNode.get("icon").asText() + ".png");
|
weatherForecast.setWeatherIconId(weatherNode.get("icon").asText());
|
||||||
|
|
||||||
JsonNode mainNode = rootNode.get("main");
|
JsonNode mainNode = rootNode.get("main");
|
||||||
weatherForecast.setTemperature(parseTemperature(mainNode));
|
weatherForecast.setTemperature(parseTemperature(mainNode));
|
||||||
|
|||||||
+1
-1
@@ -117,7 +117,7 @@ public class CurrentWeatherResponseMapper {
|
|||||||
private Weather getSingle(JsonNode rootNode) {
|
private Weather getSingle(JsonNode rootNode) {
|
||||||
JsonNode weatherState = rootNode.get("weather").get(0);
|
JsonNode weatherState = rootNode.get("weather").get(0);
|
||||||
Weather weather = Weather.forValue(weatherState.get("main").asText(), weatherState.get("description").asText());
|
Weather weather = Weather.forValue(weatherState.get("main").asText(), weatherState.get("description").asText());
|
||||||
weather.setWeatherIconUrl("http://openweathermap.org/img/w/" + weatherState.get("icon").asText() + ".png");
|
weather.setWeatherIconId(weatherState.get("icon").asText());
|
||||||
|
|
||||||
weather.setTemperature(parseTemperature(rootNode));
|
weather.setTemperature(parseTemperature(rootNode));
|
||||||
weather.setAtmosphericPressure(parsePressure(rootNode));
|
weather.setAtmosphericPressure(parsePressure(rootNode));
|
||||||
|
|||||||
+9
-5
@@ -73,11 +73,15 @@ public class WeatherForecastUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSetIconUrl_thenValueIsSet() {
|
public void whenSetIconId_thenValueIsSet() {
|
||||||
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
weatherForecast.setWeatherIconUrl("test");
|
Assert.assertNull(weatherForecast.getWeatherIconId());
|
||||||
|
Assert.assertNull(weatherForecast.getWeatherIconUrl());
|
||||||
|
|
||||||
Assert.assertEquals("test", weatherForecast.getWeatherIconUrl());
|
weatherForecast.setWeatherIconId("02n");
|
||||||
|
|
||||||
|
Assert.assertEquals("02n", weatherForecast.getWeatherIconId());
|
||||||
|
Assert.assertNotNull(weatherForecast.getWeatherIconUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -258,11 +262,11 @@ public class WeatherForecastUnitTest {
|
|||||||
|
|
||||||
Assert.assertTrue(one.equals(two));
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
one.setWeatherIconUrl("1");
|
one.setWeatherIconId("1");
|
||||||
|
|
||||||
Assert.assertFalse(one.equals(two));
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
two.setWeatherIconUrl("1");
|
two.setWeatherIconId("1");
|
||||||
|
|
||||||
Assert.assertTrue(one.equals(two));
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
|||||||
+9
-5
@@ -76,11 +76,15 @@ public class WeatherUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSetIconUrl_thenValueIsSet() {
|
public void whenSetIconId_thenValueIsSet() {
|
||||||
final Weather weather = Weather.forValue("state", "desc");
|
final Weather weather = Weather.forValue("state", "desc");
|
||||||
weather.setWeatherIconUrl("test");
|
Assert.assertNull(weather.getWeatherIconId());
|
||||||
|
Assert.assertNull(weather.getWeatherIconUrl());
|
||||||
|
|
||||||
Assert.assertEquals("test", weather.getWeatherIconUrl());
|
weather.setWeatherIconId("11d");
|
||||||
|
|
||||||
|
Assert.assertEquals("11d", weather.getWeatherIconId());
|
||||||
|
Assert.assertNotNull(weather.getWeatherIconUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -235,11 +239,11 @@ public class WeatherUnitTest {
|
|||||||
|
|
||||||
Assert.assertTrue(one.equals(two));
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
one.setWeatherIconUrl("1");
|
one.setWeatherIconId("1");
|
||||||
|
|
||||||
Assert.assertFalse(one.equals(two));
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
two.setWeatherIconUrl("1");
|
two.setWeatherIconId("1");
|
||||||
|
|
||||||
Assert.assertTrue(one.equals(two));
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user