mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 11:16:44 +03:00
Compare commits
83 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c1b079e05 | |||
| 7ad0f9d415 | |||
| e9a5011c5c | |||
| cba15e6420 | |||
| cd8209e677 | |||
| 64e02cd7a8 | |||
| b301d93b39 | |||
| c68c6fd2b6 | |||
| cd263234bc | |||
| bcee4135fc | |||
| 9b67c57d7e | |||
| 848b5397ac | |||
| fd3ff3f133 | |||
| d555eeaf32 | |||
| cdc5a4b380 | |||
| 48d0c9479d | |||
| 53af39f598 | |||
| 02d42c0cd0 | |||
| c650ba2387 | |||
| c2138a4503 | |||
| 7d3c9ba358 | |||
| ba1a5a1016 | |||
| 48d631b747 | |||
| e9b8f00c5a | |||
| 4ce9548e7a | |||
| a0e289cc2c | |||
| ef138d3bfe | |||
| ae082d41c1 | |||
| 6d44b2adec | |||
| 4c7b553b81 | |||
| 7003935869 | |||
| 764b1b7189 | |||
| 599faf60cc | |||
| 930776f5c2 | |||
| 5d6b8c4d97 | |||
| f7741e1df6 | |||
| ea39441e83 | |||
| d63de824b3 | |||
| 10ba59652b | |||
| 83f3a8e63b | |||
| 4d844a3f0a | |||
| 2c54375cfe | |||
| 3820409ce8 | |||
| 3845e41bcd | |||
| babc48bf6c | |||
| d3ca16472b | |||
| dbc5b08f43 | |||
| 1101ec03db | |||
| a9fd20b494 | |||
| ba241cdd82 | |||
| 42574d1111 | |||
| 1e9a335240 | |||
| f53dee6953 | |||
| 9c4da76b8f | |||
| d083a5a07b | |||
| 3cb26b7d20 | |||
| 6e0ddc2a83 | |||
| c44e97745f | |||
| 134424c21f | |||
| f7ffe3683b | |||
| ef2ac57f32 | |||
| 6fb08153f4 | |||
| 3195c32f97 | |||
| 1812a39108 | |||
| aed72a5ab5 | |||
| 44da350e3c | |||
| 39ee5aa38c | |||
| c6bbf7be90 | |||
| 340383afc8 | |||
| 6ffa524ce7 | |||
| 87fb040169 | |||
| d4db442b63 | |||
| 39d56b6782 | |||
| 0487e0f2d0 | |||
| c288f71826 | |||
| 157959e537 | |||
| 126bfc2d56 | |||
| e5dee248b6 | |||
| 20adced4d7 | |||
| 86b0d52586 | |||
| d86b228c6e | |||
| 61eea0b8f6 | |||
| d1ee732f91 |
@@ -0,0 +1,67 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '27 20 * * 1'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'java' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
|
# Learn more:
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
||||||
+1
-2
@@ -21,5 +21,4 @@ hs_err_pid*
|
|||||||
|
|
||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
target/
|
target/
|
||||||
**/ApplicationTest.java
|
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
language: java
|
||||||
|
|
||||||
|
jdk:
|
||||||
|
- openjdk8
|
||||||
|
- openjdk11
|
||||||
|
|
||||||
|
install: mvn install -DskipTests -Dgpg.skip -B
|
||||||
|
script: mvn test -Dmaven.skip.deploy=true -B
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2018 Alexey Zinchenko
|
Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,266 +1,54 @@
|
|||||||
# OpenWeatherMap Java API
|
# OpenWeatherMap Java API [![Build Status][ci-shield]][ci-link] [![codecov][codecov-shield]][codecov-link]
|
||||||
Java API for OpenWeatherMap services.
|
Java API for OpenWeatherMap services.
|
||||||
|
|
||||||
### Implemented features:
|
### Implemented features:
|
||||||
|
Free:
|
||||||
* Current weather data
|
* Current weather data
|
||||||
* 5 day / 3 hour forecast
|
* 5 day / 3-hour forecast
|
||||||
|
|
||||||
### Will be implemented later:
|
### Will be implemented later:
|
||||||
* 16 day / daily forecast
|
|
||||||
* UV Index(beta)
|
Free:
|
||||||
* Air pollution(beta)
|
* One Call API
|
||||||
|
* Air pollution
|
||||||
|
* Geocoding API
|
||||||
|
* Weather Stations
|
||||||
|
* Weather Triggers
|
||||||
|
|
||||||
|
Paid:
|
||||||
|
* Daily Forecast 16 days
|
||||||
|
* Hourly Forecast 4 days
|
||||||
|
* probably others...
|
||||||
|
|
||||||
### Maven coordinates:
|
### Maven coordinates:
|
||||||
|
|
||||||
_Not available yet._
|
```xml
|
||||||
|
<dependency>
|
||||||
### How to use:
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
<version>2.0.0</version>
|
||||||
```java
|
</dependency>
|
||||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
|
||||||
```
|
|
||||||
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
|
||||||
|
|
||||||
Currently available methods:
|
|
||||||
* `getWeatherRequester()`
|
|
||||||
* `getForecastRequester()`
|
|
||||||
|
|
||||||
#### Current weather data
|
|
||||||
First step is retrieving `WeatherRequester` instance:
|
|
||||||
```java
|
|
||||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
|
||||||
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
|
||||||
```
|
|
||||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
|
||||||
```
|
|
||||||
Weather weatherResponse = weatherRequester
|
|
||||||
.setLanguage(Language.ENGLISH)
|
|
||||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
|
||||||
.setAccuracy(Accuracy.ACCURATE)
|
|
||||||
.getByCityName("Minsk");
|
|
||||||
```
|
|
||||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
|
||||||
|
|
||||||
Available requests:
|
|
||||||
* `getByCityId(String cityId)`
|
|
||||||
* `getByCityName(String cityName)`
|
|
||||||
* `getByCoordinates(double latitude, double longitude)`
|
|
||||||
* `getByCoordinates(Coordinates coordinates)`
|
|
||||||
* `getByZIPCode(String zipCode, String countryCode)`
|
|
||||||
|
|
||||||
`Weather`'s useful public methods(setters are not listed):
|
|
||||||
|
|
||||||
| Method | Description |
|
|
||||||
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
||||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
|
||||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
|
||||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
|
||||||
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
|
||||||
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
|
||||||
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. |
|
|
||||||
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
|
||||||
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
|
||||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
|
||||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
|
||||||
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
|
||||||
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
|
||||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
|
||||||
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
|
||||||
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
|
||||||
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
|
||||||
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
|
||||||
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
|
||||||
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
|
||||||
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
|
||||||
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
|
||||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
|
||||||
|
|
||||||
`toString()` output example:
|
|
||||||
```
|
|
||||||
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
|
||||||
Country: BY
|
|
||||||
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
|
||||||
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
|
||||||
Weather: light intensity shower rain
|
|
||||||
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
|
||||||
Humidity: 93%
|
|
||||||
Pressure: 1008 hPa
|
|
||||||
Wind: 2.0 meter/sec, 20 degrees
|
|
||||||
Cloudiness: 75%
|
|
||||||
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 5 day / 3 hour forecast
|
### Gradle coordinates:
|
||||||
First step is retrieving `HourlyForecastRequester` instance:
|
|
||||||
```java
|
|
||||||
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
|
||||||
ForecastRequester forecastRequester = openWeatherManager.getForecastRequester();
|
|
||||||
```
|
|
||||||
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
|
||||||
```
|
|
||||||
HourlyForecast forecastResponse = forecastRequester
|
|
||||||
.setLanguage(Language.ENGLISH)
|
|
||||||
.setUnitSystem(Unit.METRIC_SYSTEM)
|
|
||||||
.setAccuracy(Accuracy.ACCURATE)
|
|
||||||
.getByCityName("Pruzhany");
|
|
||||||
```
|
|
||||||
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
|
||||||
|
|
||||||
Available requests:
|
```groovy
|
||||||
* `getByCityId(String cityId)`
|
compile('com.github.prominence:openweathermap-api:2.0.0')
|
||||||
* `getByCityName(String cityName)`
|
|
||||||
* `getByCoordinates(double latitude, double longitude)`
|
|
||||||
* `getByCoordinates(Coordinates coordinates)`
|
|
||||||
* `getByZIPCode(String zipCode, String countryCode)`
|
|
||||||
|
|
||||||
`HourlyForecast`'s useful public methods(setters are not listed):
|
|
||||||
|
|
||||||
| Method | Description |
|
|
||||||
|-----------------------------|--------------------------------------------------------------------------------------------|
|
|
||||||
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
|
||||||
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
|
||||||
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
|
||||||
| `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<HourlyForecast.Forecast>` 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.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.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:
|
|
||||||
```
|
|
||||||
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
|
||||||
Country: BY
|
|
||||||
Forecasts:
|
|
||||||
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level pressure: 1018.59 hPa. Ground-level pressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level pressure: 1017.86 hPa. Ground-level pressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
|
||||||
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level pressure: 1017.72 hPa. Ground-level pressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level pressure: 1018.18 hPa. Ground-level pressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level pressure: 1018.5 hPa. Ground-level pressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level pressure: 1018.55 hPa. Ground-level pressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level pressure: 1017.99 hPa. Ground-level pressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level pressure: 1018.34 hPa. Ground-level pressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
|
||||||
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level pressure: 1017.87 hPa. Ground-level pressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level pressure: 1018.06 hPa. Ground-level pressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level pressure: 1018.66 hPa. Ground-level pressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level pressure: 1019.05 hPa. Ground-level pressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level pressure: 1019.33 hPa. Ground-level pressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level pressure: 1019.64 hPa. Ground-level pressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level pressure: 1020.04 hPa. Ground-level pressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level pressure: 1020.68 hPa. Ground-level pressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level pressure: 1021.02 hPa. Ground-level pressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level pressure: 1021.62 hPa. Ground-level pressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level pressure: 1022.01 hPa. Ground-level pressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level pressure: 1022.43 hPa. Ground-level pressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level pressure: 1022.72 hPa. Ground-level pressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level pressure: 1022.59 hPa. Ground-level pressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level pressure: 1022.93 hPa. Ground-level pressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level pressure: 1023.13 hPa. Ground-level pressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level pressure: 1022.99 hPa. Ground-level pressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level pressure: 1022.41 hPa. Ground-level pressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level pressure: 1021.99 hPa. Ground-level pressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level pressure: 1021.51 hPa. Ground-level pressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level pressure: 1021.58 hPa. Ground-level pressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level pressure: 1021.67 hPa. Ground-level pressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level pressure: 1022.14 hPa. Ground-level pressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level pressure: 1022.13 hPa. Ground-level pressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level pressure: 1022.28 hPa. Ground-level pressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.62 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level pressure: 1022.65 hPa. Ground-level pressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
|
||||||
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level pressure: 1022.53 hPa. Ground-level pressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`Forecast`'s useful public methods(setters are not listed):
|
### Documentation
|
||||||
|
* [OpenWeatherMap Java API - 1.0](docs/Release_1.0.md)
|
||||||
| Method | Description |
|
* [OpenWeatherMap Java API - 1.1](docs/Release_1.1.md)
|
||||||
|-----------------------------|------------------------------------------------------------------------------------------------------------------|
|
* [OpenWeatherMap Java API - 1.2](docs/Release_1.2.md)
|
||||||
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
|
* [OpenWeatherMap Java API - 2.0.0](docs/Release_2.0.0.md)
|
||||||
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
|
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
|
||||||
| `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. |
|
|
||||||
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
|
||||||
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
|
||||||
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
|
||||||
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
|
||||||
| `toString()` | Returns pretty string for the whole available weather information. |
|
|
||||||
|
|
||||||
|
|
||||||
### Constants and options
|
|
||||||
|
|
||||||
#### Accuracy
|
|
||||||
| Constant | Description |
|
|
||||||
|--------------------|------------------|
|
|
||||||
| Accuracy.LIKE | Close result. |
|
|
||||||
| Accuracy.ACCURATE | Accurate result. |
|
|
||||||
|
|
||||||
#### 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. |
|
|
||||||
|
|
||||||
#### System
|
|
||||||
| Constant | Description |
|
|
||||||
|-------------------------------|-----------------------|
|
|
||||||
|System.OPEN_WEATHER_API_URL | Basic API url. |
|
|
||||||
|System.OPEN_WEATHER_API_VERSION| Current API version. |
|
|
||||||
|
|
||||||
#### 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.alibaba:fastjson:1.2.44
|
|
||||||
|
|
||||||
### License
|
### License
|
||||||
MIT
|
MIT
|
||||||
|
|
||||||
|
[ci-shield]: https://travis-ci.org/Prominence/openweathermap-java-api.svg?branch=dev
|
||||||
|
[ci-link]: https://travis-ci.org/Prominence/openweathermap-java-api
|
||||||
|
|
||||||
|
|
||||||
|
[codecov-shield]: https://codecov.io/gh/Prominence/openweathermap-java-api/branch/dev/graph/badge.svg
|
||||||
|
[codecov-link]: https://codecov.io/gh/Prominence/openweathermap-java-api
|
||||||
@@ -0,0 +1,267 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3 hour forecast
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
compile('com.github.prominence:openweathermap-api:1.0')
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently available methods:
|
||||||
|
* `getWeatherRequester()`
|
||||||
|
* `getForecastRequester()`
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
First step is retrieving `WeatherRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
Weather weatherResponse = weatherRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Minsk");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||||
|
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||||
|
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||||
|
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||||
|
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||||
|
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||||
|
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||||
|
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||||
|
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||||
|
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||||
|
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||||
|
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
||||||
|
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
||||||
|
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
||||||
|
Country: BY
|
||||||
|
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
||||||
|
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
||||||
|
Weather: light intensity shower rain
|
||||||
|
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
||||||
|
Humidity: 93%
|
||||||
|
Pressure: 1008 hPa
|
||||||
|
Wind: 2.0 meter/sec, 20 degrees
|
||||||
|
Cloudiness: 75%
|
||||||
|
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3 hour forecast
|
||||||
|
First step is retrieving `HourlyForecastRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
ForecastRequester forecastRequester = openWeatherManager.getForecastRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
HourlyForecast forecastResponse = forecastRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Pruzhany");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`HourlyForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `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<HourlyForecast.Forecast>` 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.Forecast` for the time where temperature is minimal. |
|
||||||
|
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
|
||||||
|
| `getAveragePressure()` | Returns average atmosphericPressure from forecasts. |
|
||||||
|
| `getMinimumPressure()` | Returns minimum atmosphericPressure from forecasts. |
|
||||||
|
| `getMaximumPressure()` | Returns maximum atmosphericPressure from forecasts. |
|
||||||
|
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is minimal. |
|
||||||
|
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is maximal. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
||||||
|
Country: BY
|
||||||
|
Forecasts:
|
||||||
|
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level atmosphericPressure: 1018.59 hPa. Ground-level atmosphericPressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level atmosphericPressure: 1017.86 hPa. Ground-level atmosphericPressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
||||||
|
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level atmosphericPressure: 1017.72 hPa. Ground-level atmosphericPressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level atmosphericPressure: 1018.18 hPa. Ground-level atmosphericPressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level atmosphericPressure: 1018.5 hPa. Ground-level atmosphericPressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level atmosphericPressure: 1018.55 hPa. Ground-level atmosphericPressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level atmosphericPressure: 1017.99 hPa. Ground-level atmosphericPressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level atmosphericPressure: 1018.34 hPa. Ground-level atmosphericPressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
||||||
|
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level atmosphericPressure: 1017.87 hPa. Ground-level atmosphericPressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level atmosphericPressure: 1018.06 hPa. Ground-level atmosphericPressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level atmosphericPressure: 1019.05 hPa. Ground-level atmosphericPressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level atmosphericPressure: 1019.33 hPa. Ground-level atmosphericPressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level atmosphericPressure: 1019.64 hPa. Ground-level atmosphericPressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level atmosphericPressure: 1020.04 hPa. Ground-level atmosphericPressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level atmosphericPressure: 1020.68 hPa. Ground-level atmosphericPressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level atmosphericPressure: 1021.02 hPa. Ground-level atmosphericPressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level atmosphericPressure: 1021.62 hPa. Ground-level atmosphericPressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level atmosphericPressure: 1022.01 hPa. Ground-level atmosphericPressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level atmosphericPressure: 1022.43 hPa. Ground-level atmosphericPressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level atmosphericPressure: 1022.72 hPa. Ground-level atmosphericPressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level atmosphericPressure: 1022.59 hPa. Ground-level atmosphericPressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level atmosphericPressure: 1022.93 hPa. Ground-level atmosphericPressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level atmosphericPressure: 1022.99 hPa. Ground-level atmosphericPressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level atmosphericPressure: 1022.41 hPa. Ground-level atmosphericPressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level atmosphericPressure: 1021.99 hPa. Ground-level atmosphericPressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level atmosphericPressure: 1021.51 hPa. Ground-level atmosphericPressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level atmosphericPressure: 1021.58 hPa. Ground-level atmosphericPressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level atmosphericPressure: 1021.67 hPa. Ground-level atmosphericPressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level atmosphericPressure: 1022.14 hPa. Ground-level atmosphericPressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level atmosphericPressure: 1022.13 hPa. Ground-level atmosphericPressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level atmosphericPressure: 1022.28 hPa. Ground-level atmosphericPressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level atmosphericPressure: 1022.65 hPa. Ground-level atmosphericPressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.53 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 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 atmosphericPressure: 1022.7 hPa. Ground-level atmosphericPressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
```
|
||||||
|
|
||||||
|
`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. |
|
||||||
|
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, atmosphericPressure 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. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||||
|
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||||
|
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||||
|
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Accuracy
|
||||||
|
| Constant | Description |
|
||||||
|
|--------------------|------------------|
|
||||||
|
| Accuracy.LIKE | Close result. |
|
||||||
|
| Accuracy.ACCURATE | Accurate result. |
|
||||||
|
|
||||||
|
#### 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. |
|
||||||
|
|
||||||
|
#### System
|
||||||
|
| Constant | Description |
|
||||||
|
|-------------------------------|-----------------------|
|
||||||
|
|System.OPEN_WEATHER_API_URL | Basic API url. |
|
||||||
|
|System.OPEN_WEATHER_API_VERSION| Current API version. |
|
||||||
|
|
||||||
|
#### 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.alibaba:fastjson:1.2.44
|
||||||
@@ -0,0 +1,390 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3 hour forecast
|
||||||
|
* 16 day / daily forecast
|
||||||
|
* UV Index
|
||||||
|
* Air Pollution
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
compile('com.github.prominence:openweathermap-api:1.1')
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently available methods:
|
||||||
|
* `getWeatherRequester()`
|
||||||
|
* `getHourlyForecastRequester()`
|
||||||
|
* `getDailyForecastRequester()`
|
||||||
|
* `getUltravioletIndexRequester()`
|
||||||
|
* `getAirPollutionRequester()`
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
First step is retrieving `WeatherRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
Weather weatherResponse = weatherRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Minsk");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||||
|
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||||
|
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||||
|
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||||
|
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||||
|
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||||
|
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||||
|
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||||
|
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||||
|
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||||
|
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||||
|
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
||||||
|
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
||||||
|
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
||||||
|
Country: BY
|
||||||
|
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
||||||
|
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
||||||
|
Weather: light intensity shower rain
|
||||||
|
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
||||||
|
Humidity: 93%
|
||||||
|
Pressure: 1008 hPa
|
||||||
|
Wind: 2.0 meter/sec, 20 degrees
|
||||||
|
Cloudiness: 75%
|
||||||
|
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3 hour forecast
|
||||||
|
First step is retrieving `HourlyForecastRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
HourlyForecastRequester forecastRequester = openWeatherManager.getHourlyForecastRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
HourlyForecast forecastResponse = forecastRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Pruzhany");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`HourlyForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||||
|
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||||
|
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||||
|
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` 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.Forecast` for the time where temperature is minimal. |
|
||||||
|
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
|
||||||
|
| `getAveragePressure()` | Returns average atmosphericPressure from forecasts. |
|
||||||
|
| `getMinimumPressure()` | Returns minimum atmosphericPressure from forecasts. |
|
||||||
|
| `getMaximumPressure()` | Returns maximum atmosphericPressure from forecasts. |
|
||||||
|
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is minimal. |
|
||||||
|
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is maximal. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
||||||
|
Country: BY
|
||||||
|
Forecasts:
|
||||||
|
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level atmosphericPressure: 1018.59 hPa. Ground-level atmosphericPressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level atmosphericPressure: 1017.86 hPa. Ground-level atmosphericPressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
||||||
|
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level atmosphericPressure: 1017.72 hPa. Ground-level atmosphericPressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level atmosphericPressure: 1018.18 hPa. Ground-level atmosphericPressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level atmosphericPressure: 1018.5 hPa. Ground-level atmosphericPressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level atmosphericPressure: 1018.55 hPa. Ground-level atmosphericPressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level atmosphericPressure: 1017.99 hPa. Ground-level atmosphericPressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level atmosphericPressure: 1018.34 hPa. Ground-level atmosphericPressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
||||||
|
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level atmosphericPressure: 1017.87 hPa. Ground-level atmosphericPressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level atmosphericPressure: 1018.06 hPa. Ground-level atmosphericPressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level atmosphericPressure: 1019.05 hPa. Ground-level atmosphericPressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level atmosphericPressure: 1019.33 hPa. Ground-level atmosphericPressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level atmosphericPressure: 1019.64 hPa. Ground-level atmosphericPressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level atmosphericPressure: 1020.04 hPa. Ground-level atmosphericPressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level atmosphericPressure: 1020.68 hPa. Ground-level atmosphericPressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level atmosphericPressure: 1021.02 hPa. Ground-level atmosphericPressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level atmosphericPressure: 1021.62 hPa. Ground-level atmosphericPressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level atmosphericPressure: 1022.01 hPa. Ground-level atmosphericPressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level atmosphericPressure: 1022.43 hPa. Ground-level atmosphericPressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level atmosphericPressure: 1022.72 hPa. Ground-level atmosphericPressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level atmosphericPressure: 1022.59 hPa. Ground-level atmosphericPressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level atmosphericPressure: 1022.93 hPa. Ground-level atmosphericPressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level atmosphericPressure: 1022.99 hPa. Ground-level atmosphericPressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level atmosphericPressure: 1022.41 hPa. Ground-level atmosphericPressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level atmosphericPressure: 1021.99 hPa. Ground-level atmosphericPressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level atmosphericPressure: 1021.51 hPa. Ground-level atmosphericPressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level atmosphericPressure: 1021.58 hPa. Ground-level atmosphericPressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level atmosphericPressure: 1021.67 hPa. Ground-level atmosphericPressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level atmosphericPressure: 1022.14 hPa. Ground-level atmosphericPressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level atmosphericPressure: 1022.13 hPa. Ground-level atmosphericPressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level atmosphericPressure: 1022.28 hPa. Ground-level atmosphericPressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level atmosphericPressure: 1022.65 hPa. Ground-level atmosphericPressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.53 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 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 atmosphericPressure: 1022.7 hPa. Ground-level atmosphericPressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
```
|
||||||
|
|
||||||
|
`HourlyForecast.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. |
|
||||||
|
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, atmosphericPressure 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. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||||
|
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||||
|
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
#### 16 day / daily forecast
|
||||||
|
First step is retrieving `DailyForecastRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
DailyForecastRequester forecastRequester = openWeatherManager.getDailyForecastRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
DailyForecast forecastResponse = forecastRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Pruzhany");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`DailyForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||||
|
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||||
|
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||||
|
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`DailyForecast.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. |
|
||||||
|
| `getTemperature()` | Returns `DailyForecast.Forecast.Temperature` instance that contains information about temperature(avg, min, max).|
|
||||||
|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||||
|
| `getCloudiness()` | Returns *cloudiness* percentage information. |
|
||||||
|
| `getHumidity()` | Returns *humidity* percentage information. |
|
||||||
|
| `getWindSpeed()` | Returns wind's speed. |
|
||||||
|
| `getWindDegrees()` | Returns wind's degree. |
|
||||||
|
| `getWindUnit()` | Returns wind's unit. |
|
||||||
|
| `getPressure()` | Returns atmosphericPressure value. |
|
||||||
|
| `getPressureUnit()` | Returns atmosphericPressure's unit. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
#### UV Index
|
||||||
|
|
||||||
|
First step is retrieving `UltravioletIndexRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester();
|
||||||
|
```
|
||||||
|
after you need to set coordinates and execute appropriate request:
|
||||||
|
```
|
||||||
|
UltravioletIndex uvResponse = requester
|
||||||
|
.setCoodrinates(55.33f, 24.27f)
|
||||||
|
.getCurrentUVIndex();
|
||||||
|
```
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getCurrentUVIndex()`
|
||||||
|
* `getUVIndexForecast(int amountOfDays)`
|
||||||
|
* `getUVIndexByPeriod(Date from, Date to)`
|
||||||
|
|
||||||
|
`UltravioletIndex`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------|
|
||||||
|
| `getLatitude()` | Returns latitude. |
|
||||||
|
| `getLongitude()` | Returns longitude. |
|
||||||
|
| `getDateISO()` | Returns ISO date in String representation. |
|
||||||
|
| `getDateTimestamp()` | Returns date timestamp. |
|
||||||
|
| `getValue()` | Returns UV value. |
|
||||||
|
| `getCalculationDate()` | Returns date in Date representation`. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available UV information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Date: Tue Jul 31 15:00:00 MSK 2018, Ultraviolet value: 6.230000
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Air pollution
|
||||||
|
|
||||||
|
First step is retrieving `AirPollutionRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
AirPollutionRequester requester = openWeatherMapManager.getAirPollutionRequester();
|
||||||
|
```
|
||||||
|
after you need to set coordinates, time frame, date and execute appropriate request:
|
||||||
|
```
|
||||||
|
AirPollution airPollutionResponse = forecastRequester
|
||||||
|
.setCoordinates(0.0f, 10.0f)
|
||||||
|
.setTimeFrame(TimeFrame.YEAR)
|
||||||
|
.setDate(new Date())
|
||||||
|
.retrieve();
|
||||||
|
```
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `retrieve()`
|
||||||
|
|
||||||
|
`AirPollution`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance. |
|
||||||
|
| `getLongitude()` | Returns longitude. |
|
||||||
|
| `airPollutionInfo()` | Returns list of `AirPollution.AirPollutionInfo` instances. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available air pollution information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
AirPollution[Date: Tue Jul 24 01:04:40 MSK 2018; Coordinates: latitude=0.0, longitude=9.9955]
|
||||||
|
[Value: 8.0347114E-8, Value: 9.5041536E-8, Value: 7.7667146E-8, Value: 7.251491E-8, Value: 5.899763E-8, Value: 1.9186361E-8, Value: 1.729535E-8, Value: 1.25645805E-8, Value: 3.0852514E-9]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Accuracy
|
||||||
|
| Constant | Description |
|
||||||
|
|--------------------|------------------|
|
||||||
|
| Accuracy.LIKE | Close result. |
|
||||||
|
| Accuracy.ACCURATE | Accurate result. |
|
||||||
|
|
||||||
|
#### 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.alibaba:fastjson:1.2.44
|
||||||
|
* org.projectlombok:lombok:1.18.0 (*provided*)
|
||||||
@@ -0,0 +1,402 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3 hour forecast
|
||||||
|
* 16 day / daily forecast
|
||||||
|
* UV Index
|
||||||
|
* Air Pollution
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
compile('com.github.prominence:openweathermap-api:1.2')
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapManager` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently available methods:
|
||||||
|
* `getWeatherRequester()`
|
||||||
|
* `getHourlyForecastRequester()`
|
||||||
|
* `getDailyForecastRequester()`
|
||||||
|
* `getUltravioletIndexRequester(...)`
|
||||||
|
* `getAirPollutionRequester(...)`
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
First step is retrieving `WeatherRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
WeatherRequester weatherRequester = openWeatherManager.getWeatherRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
Weather weatherResponse = weatherRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Minsk");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||||
|
| `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. |
|
||||||
|
| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, atmosphericPressure and humidity. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||||
|
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. |
|
||||||
|
| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. |
|
||||||
|
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||||
|
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. |
|
||||||
|
| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. |
|
||||||
|
| `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
|
||||||
|
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
|
||||||
|
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
|
||||||
|
| `getPressure()` | An alias for `getWeatherInfo().getPressure()`. |
|
||||||
|
| `getPressureUnit()` | An alias for `getWeatherInfo().getPressureUnit()`. |
|
||||||
|
| `getHumidityPercentage()` | An alias for `getWeatherInfo().getHumidity()`. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
City: Minsk(625144). Coordinates: latitude=53.9, longitude=27.56
|
||||||
|
Country: BY
|
||||||
|
Sunrise: Sun Jul 15 04:58:27 MSK 2018
|
||||||
|
Sunset: Sun Jul 15 21:32:19 MSK 2018
|
||||||
|
Weather: light intensity shower rain
|
||||||
|
Temperature: 17.0 ℃. Minimum temparature: 17.0 ℃. Maximum temperature: 17.0 ℃
|
||||||
|
Humidity: 93%
|
||||||
|
Pressure: 1008 hPa
|
||||||
|
Wind: 2.0 meter/sec, 20 degrees
|
||||||
|
Cloudiness: 75%
|
||||||
|
Data calculation time: Mon Jul 16 00:00:00 MSK 2018
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3 hour forecast
|
||||||
|
First step is retrieving `HourlyForecastRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
HourlyForecastRequester forecastRequester = openWeatherManager.getHourlyForecastRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
HourlyForecast forecastResponse = forecastRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Pruzhany");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`HourlyForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||||
|
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||||
|
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||||
|
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` 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.Forecast` for the time where temperature is minimal. |
|
||||||
|
| `getByMaximumTemperature()` | Returns `HourlyForecast.Forecast` for the time where temperature is maximal. |
|
||||||
|
| `getAveragePressure()` | Returns average atmosphericPressure from forecasts. |
|
||||||
|
| `getMinimumPressure()` | Returns minimum atmosphericPressure from forecasts. |
|
||||||
|
| `getMaximumPressure()` | Returns maximum atmosphericPressure from forecasts. |
|
||||||
|
| `getByMinimumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is minimal. |
|
||||||
|
| `getByMaximumPressure()` | Returns `HourlyForecast.Forecast` for the time where atmosphericPressure is maximal. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
City: Pruzhany(622997). Coordinates: latitude=52.5582, longitude=24.4567
|
||||||
|
Country: BY
|
||||||
|
Forecasts:
|
||||||
|
Time: Tue Jul 17 00:00:00 MSK 2018. Weather: light rain. Temperature: 16.24 ℃. Minimum temperature: 16.24 ℃. Maximum temperature: 17.36 ℃. Pressure: 997.38 hPa. Sea-level atmosphericPressure: 1018.59 hPa. Ground-level atmosphericPressure: 997.38 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 2.85 meter/sec, 324 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 03:00:00 MSK 2018. Weather: moderate rain. Temperature: 16.0 ℃. Minimum temperature: 16.0 ℃. Maximum temperature: 16.83 ℃. Pressure: 996.88 hPa. Sea-level atmosphericPressure: 1017.86 hPa. Ground-level atmosphericPressure: 996.88 hPa. Humidity: 99%. Cloudiness: 80%. Wind: 1.86 meter/sec, 349 degrees. Rain(last 3 hrs): 3 mm
|
||||||
|
Time: Tue Jul 17 06:00:00 MSK 2018. Weather: light rain. Temperature: 15.76 ℃. Minimum temperature: 15.76 ℃. Maximum temperature: 16.31 ℃. Pressure: 996.7 hPa. Sea-level atmosphericPressure: 1017.72 hPa. Ground-level atmosphericPressure: 996.7 hPa. Humidity: 94%. Cloudiness: 76%. Wind: 1.62 meter/sec, 113 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 09:00:00 MSK 2018. Weather: light rain. Temperature: 18.23 ℃. Minimum temperature: 18.23 ℃. Maximum temperature: 18.51 ℃. Pressure: 997.17 hPa. Sea-level atmosphericPressure: 1018.18 hPa. Ground-level atmosphericPressure: 997.17 hPa. Humidity: 100%. Cloudiness: 76%. Wind: 2.11 meter/sec, 107 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 12:00:00 MSK 2018. Weather: light rain. Temperature: 21.0 ℃. Minimum temperature: 21.0 ℃. Maximum temperature: 21.0 ℃. Pressure: 997.6 hPa. Sea-level atmosphericPressure: 1018.5 hPa. Ground-level atmosphericPressure: 997.6 hPa. Humidity: 100%. Cloudiness: 68%. Wind: 2.51 meter/sec, 82 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 15:00:00 MSK 2018. Weather: light rain. Temperature: 21.78 ℃. Minimum temperature: 21.78 ℃. Maximum temperature: 21.78 ℃. Pressure: 997.73 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.73 hPa. Humidity: 92%. Cloudiness: 88%. Wind: 4.05 meter/sec, 78 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 18:00:00 MSK 2018. Weather: light rain. Temperature: 22.9 ℃. Minimum temperature: 22.9 ℃. Maximum temperature: 22.9 ℃. Pressure: 997.66 hPa. Sea-level atmosphericPressure: 1018.55 hPa. Ground-level atmosphericPressure: 997.66 hPa. Humidity: 93%. Cloudiness: 68%. Wind: 3.06 meter/sec, 67 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Tue Jul 17 21:00:00 MSK 2018. Weather: light rain. Temperature: 23.04 ℃. Minimum temperature: 23.04 ℃. Maximum temperature: 23.04 ℃. Pressure: 996.89 hPa. Sea-level atmosphericPressure: 1017.99 hPa. Ground-level atmosphericPressure: 996.89 hPa. Humidity: 83%. Cloudiness: 88%. Wind: 3.17 meter/sec, 16 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 00:00:00 MSK 2018. Weather: moderate rain. Temperature: 18.5 ℃. Minimum temperature: 18.5 ℃. Maximum temperature: 18.5 ℃. Pressure: 997.33 hPa. Sea-level atmosphericPressure: 1018.34 hPa. Ground-level atmosphericPressure: 997.33 hPa. Humidity: 97%. Cloudiness: 44%. Wind: 3.56 meter/sec, 31 degrees. Rain(last 3 hrs): 7 mm
|
||||||
|
Time: Wed Jul 18 03:00:00 MSK 2018. Weather: few clouds. Temperature: 18.57 ℃. Minimum temperature: 18.57 ℃. Maximum temperature: 18.57 ℃. Pressure: 996.91 hPa. Sea-level atmosphericPressure: 1017.87 hPa. Ground-level atmosphericPressure: 996.91 hPa. Humidity: 95%. Cloudiness: 24%. Wind: 5.26 meter/sec, 44 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 06:00:00 MSK 2018. Weather: few clouds. Temperature: 18.94 ℃. Minimum temperature: 18.94 ℃. Maximum temperature: 18.94 ℃. Pressure: 997.07 hPa. Sea-level atmosphericPressure: 1018.06 hPa. Ground-level atmosphericPressure: 997.07 hPa. Humidity: 95%. Cloudiness: 20%. Wind: 4.8 meter/sec, 45 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 09:00:00 MSK 2018. Weather: light rain. Temperature: 20.6 ℃. Minimum temperature: 20.6 ℃. Maximum temperature: 20.6 ℃. Pressure: 997.8 hPa. Sea-level atmosphericPressure: 1018.66 hPa. Ground-level atmosphericPressure: 997.8 hPa. Humidity: 97%. Cloudiness: 48%. Wind: 5.56 meter/sec, 54 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 12:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.87 ℃. Minimum temperature: 23.87 ℃. Maximum temperature: 23.87 ℃. Pressure: 998.06 hPa. Sea-level atmosphericPressure: 1019.05 hPa. Ground-level atmosphericPressure: 998.06 hPa. Humidity: 88%. Cloudiness: 32%. Wind: 5.86 meter/sec, 52 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 24.67 ℃. Minimum temperature: 24.67 ℃. Maximum temperature: 24.67 ℃. Pressure: 998.51 hPa. Sea-level atmosphericPressure: 1019.33 hPa. Ground-level atmosphericPressure: 998.51 hPa. Humidity: 84%. Cloudiness: 36%. Wind: 5.63 meter/sec, 51 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.15 ℃. Minimum temperature: 25.15 ℃. Maximum temperature: 25.15 ℃. Pressure: 998.79 hPa. Sea-level atmosphericPressure: 1019.64 hPa. Ground-level atmosphericPressure: 998.79 hPa. Humidity: 78%. Cloudiness: 44%. Wind: 5.47 meter/sec, 38 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Wed Jul 18 21:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.23 ℃. Minimum temperature: 23.23 ℃. Maximum temperature: 23.23 ℃. Pressure: 999.08 hPa. Sea-level atmosphericPressure: 1020.04 hPa. Ground-level atmosphericPressure: 999.08 hPa. Humidity: 75%. Cloudiness: 48%. Wind: 4.62 meter/sec, 25 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 20.79 ℃. Minimum temperature: 20.79 ℃. Maximum temperature: 20.79 ℃. Pressure: 999.67 hPa. Sea-level atmosphericPressure: 1020.68 hPa. Ground-level atmosphericPressure: 999.67 hPa. Humidity: 76%. Cloudiness: 48%. Wind: 4.29 meter/sec, 13 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 03:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.45 ℃. Minimum temperature: 19.45 ℃. Maximum temperature: 19.45 ℃. Pressure: 999.95 hPa. Sea-level atmosphericPressure: 1021.02 hPa. Ground-level atmosphericPressure: 999.95 hPa. Humidity: 80%. Cloudiness: 48%. Wind: 4.22 meter/sec, 17 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 06:00:00 MSK 2018. Weather: light rain. Temperature: 18.9 ℃. Minimum temperature: 18.9 ℃. Maximum temperature: 18.9 ℃. Pressure: 1000.6 hPa. Sea-level atmosphericPressure: 1021.62 hPa. Ground-level atmosphericPressure: 1000.6 hPa. Humidity: 83%. Cloudiness: 92%. Wind: 4.43 meter/sec, 10 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 09:00:00 MSK 2018. Weather: light rain. Temperature: 21.37 ℃. Minimum temperature: 21.37 ℃. Maximum temperature: 21.37 ℃. Pressure: 1000.95 hPa. Sea-level atmosphericPressure: 1022.01 hPa. Ground-level atmosphericPressure: 1000.95 hPa. Humidity: 87%. Cloudiness: 0%. Wind: 4.36 meter/sec, 6 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.92 ℃. Minimum temperature: 23.92 ℃. Maximum temperature: 23.92 ℃. Pressure: 1001.5 hPa. Sea-level atmosphericPressure: 1022.43 hPa. Ground-level atmosphericPressure: 1001.5 hPa. Humidity: 77%. Cloudiness: 0%. Wind: 5.66 meter/sec, 12 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 15:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.7 ℃. Minimum temperature: 23.7 ℃. Maximum temperature: 23.7 ℃. Pressure: 1001.75 hPa. Sea-level atmosphericPressure: 1022.72 hPa. Ground-level atmosphericPressure: 1001.75 hPa. Humidity: 72%. Cloudiness: 56%. Wind: 5.87 meter/sec, 349 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 18:00:00 MSK 2018. Weather: broken clouds. Temperature: 23.82 ℃. Minimum temperature: 23.82 ℃. Maximum temperature: 23.82 ℃. Pressure: 1001.55 hPa. Sea-level atmosphericPressure: 1022.59 hPa. Ground-level atmosphericPressure: 1001.55 hPa. Humidity: 72%. Cloudiness: 68%. Wind: 5.47 meter/sec, 340 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Thu Jul 19 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.22 ℃. Minimum temperature: 22.22 ℃. Maximum temperature: 22.22 ℃. Pressure: 1001.82 hPa. Sea-level atmosphericPressure: 1022.93 hPa. Ground-level atmosphericPressure: 1001.82 hPa. Humidity: 67%. Cloudiness: 76%. Wind: 4.12 meter/sec, 333 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 00:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.76 ℃. Minimum temperature: 19.76 ℃. Maximum temperature: 19.76 ℃. Pressure: 1001.98 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.98 hPa. Humidity: 76%. Cloudiness: 32%. Wind: 4.11 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 03:00:00 MSK 2018. Weather: clear sky. Temperature: 17.53 ℃. Minimum temperature: 17.53 ℃. Maximum temperature: 17.53 ℃. Pressure: 1001.93 hPa. Sea-level atmosphericPressure: 1023.13 hPa. Ground-level atmosphericPressure: 1001.93 hPa. Humidity: 87%. Cloudiness: 8%. Wind: 4.21 meter/sec, 309 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 16.83 ℃. Minimum temperature: 16.83 ℃. Maximum temperature: 16.83 ℃. Pressure: 1001.79 hPa. Sea-level atmosphericPressure: 1022.99 hPa. Ground-level atmosphericPressure: 1001.79 hPa. Humidity: 91%. Cloudiness: 44%. Wind: 3.65 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 09:00:00 MSK 2018. Weather: light rain. Temperature: 19.57 ℃. Minimum temperature: 19.57 ℃. Maximum temperature: 19.57 ℃. Pressure: 1001.34 hPa. Sea-level atmosphericPressure: 1022.41 hPa. Ground-level atmosphericPressure: 1001.34 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 4.38 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 12:00:00 MSK 2018. Weather: clear sky. Temperature: 23.5 ℃. Minimum temperature: 23.5 ℃. Maximum temperature: 23.5 ℃. Pressure: 1001.0 hPa. Sea-level atmosphericPressure: 1021.99 hPa. Ground-level atmosphericPressure: 1001.0 hPa. Humidity: 85%. Cloudiness: 8%. Wind: 5.36 meter/sec, 299 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 25.14 ℃. Minimum temperature: 25.14 ℃. Maximum temperature: 25.14 ℃. Pressure: 1000.5 hPa. Sea-level atmosphericPressure: 1021.51 hPa. Ground-level atmosphericPressure: 1000.5 hPa. Humidity: 73%. Cloudiness: 32%. Wind: 6.72 meter/sec, 305 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 18:00:00 MSK 2018. Weather: overcast clouds. Temperature: 23.56 ℃. Minimum temperature: 23.56 ℃. Maximum temperature: 23.56 ℃. Pressure: 1000.7 hPa. Sea-level atmosphericPressure: 1021.58 hPa. Ground-level atmosphericPressure: 1000.7 hPa. Humidity: 66%. Cloudiness: 88%. Wind: 6.57 meter/sec, 317 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Fri Jul 20 21:00:00 MSK 2018. Weather: broken clouds. Temperature: 22.41 ℃. Minimum temperature: 22.41 ℃. Maximum temperature: 22.41 ℃. Pressure: 1000.64 hPa. Sea-level atmosphericPressure: 1021.67 hPa. Ground-level atmosphericPressure: 1000.64 hPa. Humidity: 68%. Cloudiness: 64%. Wind: 4.31 meter/sec, 326 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 00:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.92 ℃. Minimum temperature: 20.92 ℃. Maximum temperature: 20.92 ℃. Pressure: 1001.06 hPa. Sea-level atmosphericPressure: 1022.14 hPa. Ground-level atmosphericPressure: 1001.06 hPa. Humidity: 78%. Cloudiness: 68%. Wind: 3.42 meter/sec, 327 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 03:00:00 MSK 2018. Weather: broken clouds. Temperature: 20.28 ℃. Minimum temperature: 20.28 ℃. Maximum temperature: 20.28 ℃. Pressure: 1001.04 hPa. Sea-level atmosphericPressure: 1022.13 hPa. Ground-level atmosphericPressure: 1001.04 hPa. Humidity: 78%. Cloudiness: 76%. Wind: 4.27 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 06:00:00 MSK 2018. Weather: scattered clouds. Temperature: 19.11 ℃. Minimum temperature: 19.11 ℃. Maximum temperature: 19.11 ℃. Pressure: 1001.13 hPa. Sea-level atmosphericPressure: 1022.28 hPa. Ground-level atmosphericPressure: 1001.13 hPa. Humidity: 74%. Cloudiness: 32%. Wind: 4.96 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 09:00:00 MSK 2018. Weather: few clouds. Temperature: 20.16 ℃. Minimum temperature: 20.16 ℃. Maximum temperature: 20.16 ℃. Pressure: 1001.43 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.43 hPa. Humidity: 86%. Cloudiness: 20%. Wind: 5.16 meter/sec, 308 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 12:00:00 MSK 2018. Weather: few clouds. Temperature: 22.37 ℃. Minimum temperature: 22.37 ℃. Maximum temperature: 22.37 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.62 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 88%. Cloudiness: 20%. Wind: 5.56 meter/sec, 307 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 15:00:00 MSK 2018. Weather: scattered clouds. Temperature: 22.85 ℃. Minimum temperature: 22.85 ℃. Maximum temperature: 22.85 ℃. Pressure: 1001.63 hPa. Sea-level atmosphericPressure: 1022.65 hPa. Ground-level atmosphericPressure: 1001.63 hPa. Humidity: 81%. Cloudiness: 44%. Wind: 5.46 meter/sec, 314 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
Time: Sat Jul 21 18:00:00 MSK 2018. Weather: scattered clouds. Temperature: 23.79 ℃. Minimum temperature: 23.79 ℃. Maximum temperature: 23.79 ℃. Pressure: 1001.53 hPa. Sea-level atmosphericPressure: 1022.53 hPa. Ground-level atmosphericPressure: 1001.53 hPa. Humidity: 72%. Cloudiness: 32%. Wind: 5.56 meter/sec, 313 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 atmosphericPressure: 1022.7 hPa. Ground-level atmosphericPressure: 1001.72 hPa. Humidity: 66%. Cloudiness: 48%. Wind: 3.96 meter/sec, 312 degrees. Rain(last 3 hrs): 0 mm
|
||||||
|
```
|
||||||
|
|
||||||
|
`HourlyForecast.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. |
|
||||||
|
| `getWeatherInfo()` | Returns `HourlyForecast.WeatherInfo` instance that contains information about temperature, atmosphericPressure 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. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. |
|
||||||
|
| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. |
|
||||||
|
| `getDt_txt()` | Returns `String` value that represents data calculation time. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
#### 16 day / daily forecast
|
||||||
|
First step is retrieving `DailyForecastRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
DailyForecastRequester forecastRequester = openWeatherManager.getDailyForecastRequester();
|
||||||
|
```
|
||||||
|
after you are able to set preferable options(via chain methods) and execute appropriate request:
|
||||||
|
```
|
||||||
|
DailyForecast forecastResponse = forecastRequester
|
||||||
|
.setLanguage(Language.ENGLISH)
|
||||||
|
.setUnitSystem(Unit.METRIC_SYSTEM)
|
||||||
|
.setAccuracy(Accuracy.ACCURATE)
|
||||||
|
.getByCityName("Pruzhany");
|
||||||
|
```
|
||||||
|
*Language*, *UnitSystem* and *Accuracy* settings will be described below.
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getByCityId(String cityId)`
|
||||||
|
* `getByCityName(String cityName)`
|
||||||
|
* `getByCoordinates(double latitude, double longitude)`
|
||||||
|
* `getByCoordinates(Coordinates coordinates)`
|
||||||
|
* `getByZIPCode(String zipCode, String countryCode)`
|
||||||
|
|
||||||
|
`DailyForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------|--------------------------------------------------------------------------------------------|
|
||||||
|
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
|
||||||
|
| `getCityName()` | Returns city name. Example: `Minsk`. |
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
|
||||||
|
| `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
|
||||||
|
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||||
|
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||||
|
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`DailyForecast.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. |
|
||||||
|
| `getTemperature()` | Returns `DailyForecast.Forecast.Temperature` instance that contains information about temperature(avg, min, max).|
|
||||||
|
| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
|
||||||
|
| `getCloudiness()` | Returns *cloudiness* percentage information. |
|
||||||
|
| `getHumidity()` | Returns *humidity* percentage information. |
|
||||||
|
| `getWindSpeed()` | Returns wind's speed. |
|
||||||
|
| `getWindDegrees()` | Returns wind's degree. |
|
||||||
|
| `getWindUnit()` | Returns wind's unit. |
|
||||||
|
| `getPressure()` | Returns atmosphericPressure value. |
|
||||||
|
| `getPressureUnit()` | Returns atmosphericPressure's unit. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available forecast information. |
|
||||||
|
|
||||||
|
#### UV Index
|
||||||
|
|
||||||
|
First step is retrieving `UltravioletIndexRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester(34.23f, -22.45f);
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
Coordinates coordinates = new Coordinates(34.23f, -22.45f);
|
||||||
|
UltravioletIndexRequester requester = openWeatherMapManager.getUltravioletIndexRequester(coordinates);
|
||||||
|
```
|
||||||
|
|
||||||
|
after you need to execute appropriate request:
|
||||||
|
```
|
||||||
|
UltravioletIndex uvResponse = requester.getCurrentUVIndex();
|
||||||
|
```
|
||||||
|
|
||||||
|
You can change required coordinates via: `requester.setCoordinates(Coordinates coordinates);` or `requester.setCoordinates(float latitude, float longitude);`
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `getCurrentUVIndex()`
|
||||||
|
* `getUVIndexForecast(int amountOfDays)`
|
||||||
|
* `getUVIndexByPeriod(Date from, Date to)`
|
||||||
|
|
||||||
|
`UltravioletIndex`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------|
|
||||||
|
| `getLatitude()` | Returns latitude. |
|
||||||
|
| `getLongitude()` | Returns longitude. |
|
||||||
|
| `getDateISO()` | Returns ISO date in String representation. |
|
||||||
|
| `getDateTimestamp()` | Returns date timestamp. |
|
||||||
|
| `getValue()` | Returns UV value. |
|
||||||
|
| `getCalculationDate()` | Returns date in Date representation`. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available UV information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Date: Tue Jul 31 15:00:00 MSK 2018, Ultraviolet value: 6.230000
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Air pollution
|
||||||
|
|
||||||
|
First step is retrieving `AirPollutionRequester` instance:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapManager openWeatherMapManager = new OpenWeatherMapManager(API_TOKEN);
|
||||||
|
AirPollutionRequester requester = openWeatherMapManager.getAirPollutionRequester(0f, 10f, new Date(), TimeFrame.DAY);
|
||||||
|
```
|
||||||
|
after you need to execute appropriate request:
|
||||||
|
```
|
||||||
|
AirPollution airPolutionResponse = requester.retrieve();
|
||||||
|
```
|
||||||
|
|
||||||
|
You can modify parameters anytime:
|
||||||
|
```java
|
||||||
|
requester.setCoordinates(Coordinates coordinates);
|
||||||
|
requester.setCoordinates(float latitude, float longitude);
|
||||||
|
requester.setTimeFrame(TimeFrame timeFrame);
|
||||||
|
requester.setDate(Date date);
|
||||||
|
```
|
||||||
|
|
||||||
|
Available requests:
|
||||||
|
* `retrieve()`
|
||||||
|
|
||||||
|
`AirPollution`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getCoordinates()` | Returns `Coordinates` instance. |
|
||||||
|
| `getLongitude()` | Returns longitude. |
|
||||||
|
| `airPollutionInfo()` | Returns list of `AirPollution.AirPollutionInfo` instances. |
|
||||||
|
| `toString()` | Returns pretty string for the whole available air pollution information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
AirPollution[Date: Tue Jul 24 01:04:40 MSK 2018; Coordinates: latitude=0.0, longitude=9.9955]
|
||||||
|
[Value: 8.0347114E-8, Value: 9.5041536E-8, Value: 7.7667146E-8, Value: 7.251491E-8, Value: 5.899763E-8, Value: 1.9186361E-8, Value: 1.729535E-8, Value: 1.25645805E-8, Value: 3.0852514E-9]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Accuracy
|
||||||
|
| Constant | Description |
|
||||||
|
|--------------------|------------------|
|
||||||
|
| Accuracy.LIKE | Close result. |
|
||||||
|
| Accuracy.ACCURATE | Accurate result. |
|
||||||
|
|
||||||
|
#### 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.alibaba:fastjson:1.2.44
|
||||||
|
* org.projectlombok:lombok:1.18.0 (*provided*)
|
||||||
|
* junit:junit:4.12 (*test*)
|
||||||
@@ -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.0</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
compile('com.github.prominence:openweathermap-api:2.0.0')
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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*)
|
||||||
@@ -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.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
compile('com.github.prominence:openweathermap-api:2.0.0-SNAPSHOT')
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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*)
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>1.0</version>
|
<version>2.0.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Java OpenWeatherMap API</name>
|
<name>Java OpenWeatherMap API</name>
|
||||||
@@ -61,6 +61,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>8</source>
|
<source>8</source>
|
||||||
<target>8</target>
|
<target>8</target>
|
||||||
@@ -69,17 +70,17 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.2.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>ApplicationTest.class</exclude>
|
<exclude>**/test/*</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||||
<version>1.6.7</version>
|
<version>1.6.8</version>
|
||||||
<extensions>true</extensions>
|
<extensions>true</extensions>
|
||||||
<configuration>
|
<configuration>
|
||||||
<serverId>ossrh</serverId>
|
<serverId>ossrh</serverId>
|
||||||
@@ -90,7 +91,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>3.2.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-sources</id>
|
<id>attach-sources</id>
|
||||||
@@ -103,7 +104,10 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>2.9.1</version>
|
<version>3.2.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>attach-javadocs</id>
|
<id>attach-javadocs</id>
|
||||||
@@ -116,7 +120,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
<version>1.5</version>
|
<version>1.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
@@ -127,15 +131,46 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>0.8.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>1.2.44</version>
|
<version>2.12.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.30</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.constants.System;
|
|
||||||
import com.github.prominence.openweathermap.api.constants.Unit;
|
|
||||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
|
||||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
|
||||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
|
||||||
|
|
||||||
protected String language;
|
|
||||||
protected String unitSystem = Unit.STANDARD_SYSTEM;
|
|
||||||
protected String accuracy;
|
|
||||||
|
|
||||||
protected BasicRequester(String authToken) {
|
|
||||||
super(authToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getByCityId(String id) throws InvalidAuthTokenException, DataNotFoundException {
|
|
||||||
return executeRequest("?id=" + id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getByCityName(String name) throws InvalidAuthTokenException, DataNotFoundException {
|
|
||||||
return executeRequest("?q=" + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getByCoordinates(double latitude, double longitude) throws InvalidAuthTokenException, DataNotFoundException {
|
|
||||||
return executeRequest("?lat=" + latitude + "&lon=" + longitude);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getByCoordinates(Coordinates coordinates) throws InvalidAuthTokenException, DataNotFoundException {
|
|
||||||
return getByCoordinates(coordinates.getLatitude(), coordinates.getLongitude());
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getByZIPCode(String zipCode, String countryCode) throws InvalidAuthTokenException, DataNotFoundException {
|
|
||||||
return executeRequest("?zip=" + zipCode + "," + countryCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URL buildURL(String requestSpecificParameters) throws MalformedURLException {
|
|
||||||
|
|
||||||
StringBuilder urlBuilder = new StringBuilder(System.OPEN_WEATHER_API_URL);
|
|
||||||
urlBuilder.append(getRequestType());
|
|
||||||
urlBuilder.append(requestSpecificParameters);
|
|
||||||
|
|
||||||
urlBuilder.append("&appid=");
|
|
||||||
urlBuilder.append(authToken);
|
|
||||||
|
|
||||||
|
|
||||||
if (language != null) {
|
|
||||||
urlBuilder.append("&lang=");
|
|
||||||
urlBuilder.append(language);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Unit.STANDARD_SYSTEM.equals(unitSystem)) {
|
|
||||||
urlBuilder.append("&units=");
|
|
||||||
urlBuilder.append(unitSystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accuracy != null) {
|
|
||||||
urlBuilder.append("&type=");
|
|
||||||
urlBuilder.append(accuracy);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new URL(urlBuilder.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract String getRequestType();
|
|
||||||
protected abstract T executeRequest(String requestSpecificParamsString) throws InvalidAuthTokenException, DataNotFoundException;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.constants.Unit;
|
|
||||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
|
||||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
|
||||||
import com.github.prominence.openweathermap.api.model.response.HourlyForecast;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.JsonUtils;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class HourlyForecastRequester extends BasicRequester<HourlyForecast> {
|
|
||||||
|
|
||||||
HourlyForecastRequester(String authToken) {
|
|
||||||
super(authToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HourlyForecastRequester setLanguage(String language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HourlyForecastRequester setUnitSystem(String unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HourlyForecastRequester setAccuracy(String accuracy) {
|
|
||||||
this.accuracy = accuracy;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getRequestType() {
|
|
||||||
return "forecast";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected HourlyForecast executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
|
||||||
|
|
||||||
HourlyForecast forecastResponse = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
|
||||||
forecastResponse = (HourlyForecast)JsonUtils.parseJson(requestResult, HourlyForecast.class);
|
|
||||||
|
|
||||||
char temperatureUnit = Unit.getTemperatureUnit(unitSystem);
|
|
||||||
String windUnit = Unit.getWindUnit(unitSystem);
|
|
||||||
|
|
||||||
forecastResponse.getForecasts().forEach(forecastInfo -> {
|
|
||||||
forecastInfo.getWind().setUnit(windUnit);
|
|
||||||
forecastInfo.getWeatherInfo().setTemperatureUnit(temperatureUnit);
|
|
||||||
});
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return forecastResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
||||||
|
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequesterImpl;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequesterImpl;
|
||||||
|
|
||||||
|
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main public API client to communicate with OpenWeatherMap services.
|
||||||
|
* Requires API key for usage. More info on the website <a href="https://openweathermap.org/api">https://openweathermap.org/api</a>.
|
||||||
|
*/
|
||||||
|
public class OpenWeatherMapClient {
|
||||||
|
private final String apiKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created OpenWeatherMap client object.
|
||||||
|
* @param apiKey API key obtained on <a href="https://home.openweathermap.org/api_keys">OpwnWeatherMap site</a>.
|
||||||
|
*/
|
||||||
|
public OpenWeatherMapClient(String apiKey) {
|
||||||
|
this.apiKey = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
||||||
|
* @return requester for retrieving current weather information.
|
||||||
|
*/
|
||||||
|
@SubscriptionAvailability(plans = ALL)
|
||||||
|
public CurrentWeatherRequester currentWeather() {
|
||||||
|
return new CurrentWeatherRequesterImpl(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5 Day / 3 Hour Forecast <a href="https://openweathermap.org/forecast5">API</a>.
|
||||||
|
* @return requester for retrieving 5 day/3-hour weather forecast information.
|
||||||
|
*/
|
||||||
|
@SubscriptionAvailability(plans = ALL)
|
||||||
|
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
||||||
|
return new FiveDayThreeHourStepForecastRequesterImpl(apiKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api;
|
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.constants.Unit;
|
|
||||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
|
||||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
|
||||||
import com.github.prominence.openweathermap.api.model.response.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.JsonUtils;
|
|
||||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class WeatherRequester extends BasicRequester<Weather> {
|
|
||||||
|
|
||||||
WeatherRequester(String authToken) {
|
|
||||||
super(authToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeatherRequester setLanguage(String language) {
|
|
||||||
this.language = language;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeatherRequester setUnitSystem(String unitSystem) {
|
|
||||||
this.unitSystem = unitSystem;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeatherRequester setAccuracy(String accuracy) {
|
|
||||||
this.accuracy = accuracy;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getRequestType() {
|
|
||||||
return "weather";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Weather executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
|
||||||
|
|
||||||
Weather weather = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
|
||||||
weather = (Weather)JsonUtils.parseJson(requestResult, Weather.class);
|
|
||||||
|
|
||||||
weather.getWind().setUnit(Unit.getWindUnit(unitSystem));
|
|
||||||
weather.getWeatherInfo().setTemperatureUnit(Unit.getTemperatureUnit(unitSystem));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return weather;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.annotation;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.SubscriptionPlan;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marker-type annotation to specify what type of license it needs to have to use API method.
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.CLASS)
|
||||||
|
public @interface SubscriptionAvailability {
|
||||||
|
/**
|
||||||
|
* Marks method with subscription plan it needs to have to use the method.
|
||||||
|
* @return subscription plan.
|
||||||
|
*/
|
||||||
|
SubscriptionPlan[] plans();
|
||||||
|
}
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.constants;
|
|
||||||
|
|
||||||
public final class Language {
|
|
||||||
|
|
||||||
private Language() {}
|
|
||||||
|
|
||||||
public static final String ARABIC = "ar";
|
|
||||||
public static final String BULGARIAN = "bg";
|
|
||||||
public static final String CATALAN = "ca";
|
|
||||||
public static final String CZECH = "cz";
|
|
||||||
public static final String GERMAN = "de";
|
|
||||||
public static final String GREEK = "el";
|
|
||||||
public static final String ENGLISH = "en";
|
|
||||||
public static final String PERSIAN = "fa";
|
|
||||||
public static final String FINNISH = "fi";
|
|
||||||
public static final String FRENCH = "fr";
|
|
||||||
public static final String GALICIAN = "gl";
|
|
||||||
public static final String CROATIAN = "hr";
|
|
||||||
public static final String HUNGARIAN = "hu";
|
|
||||||
public static final String ITALIAN = "it";
|
|
||||||
public static final String JAPANESE = "ja";
|
|
||||||
public static final String KOREAN = "kr";
|
|
||||||
public static final String LATVIAN = "la";
|
|
||||||
public static final String LITHUANIAN = "lt";
|
|
||||||
public static final String MACEDONIAN = "mk";
|
|
||||||
public static final String DUTCH = "nl";
|
|
||||||
public static final String POLISH = "pl";
|
|
||||||
public static final String PORTUGUESE = "pt";
|
|
||||||
public static final String ROMANIAN ="ro";
|
|
||||||
public static final String RUSSIAN = "ru";
|
|
||||||
public static final String SWEDISH = "se";
|
|
||||||
public static final String SLOVAK = "sk";
|
|
||||||
public static final String SLOVENIAN = "sl";
|
|
||||||
public static final String SPANISH = "en";
|
|
||||||
public static final String TURKISH = "tr";
|
|
||||||
public static final String UKRANIAN = "uk";
|
|
||||||
public static final String VIETNAMESE = "vi";
|
|
||||||
public static final String CHINESE_SIMPLIFIED = "zh_cn";
|
|
||||||
public static final String CHINESE_TRADITIONAL = "zh_tw";
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,208 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enumeration which lists all available languages for API usage.
|
||||||
|
* Usually it could be specified to get response with some fields translated into desired language.
|
||||||
|
*/
|
||||||
|
public enum Language {
|
||||||
|
/**
|
||||||
|
* Arabic language.
|
||||||
|
*/
|
||||||
|
ARABIC("ar"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulgarian language.
|
||||||
|
*/
|
||||||
|
BULGARIAN("bg"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Catalan language.
|
||||||
|
*/
|
||||||
|
CATALAN("ca"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Czech language.
|
||||||
|
*/
|
||||||
|
CZECH("cz"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* German language.
|
||||||
|
*/
|
||||||
|
GERMAN("de"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Greek language.
|
||||||
|
*/
|
||||||
|
GREEK("el"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* English language.
|
||||||
|
*/
|
||||||
|
ENGLISH("en"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persian language.
|
||||||
|
*/
|
||||||
|
PERSIAN("fa"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finnish language.
|
||||||
|
*/
|
||||||
|
FINNISH("fi"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* French language.
|
||||||
|
*/
|
||||||
|
FRENCH("fr"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Galician language.
|
||||||
|
*/
|
||||||
|
GALICIAN("gl"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Croatian language.
|
||||||
|
*/
|
||||||
|
CROATIAN("hr"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hungarian language.
|
||||||
|
*/
|
||||||
|
HUNGARIAN("hu"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Italian language.
|
||||||
|
*/
|
||||||
|
ITALIAN("it"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Japanese language.
|
||||||
|
*/
|
||||||
|
JAPANESE("ja"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Korean language.
|
||||||
|
*/
|
||||||
|
KOREAN("kr"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Latvian language.
|
||||||
|
*/
|
||||||
|
LATVIAN("la"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lithuanian language.
|
||||||
|
*/
|
||||||
|
LITHUANIAN("lt"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Macedonian language.
|
||||||
|
*/
|
||||||
|
MACEDONIAN("mk"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dutch language.
|
||||||
|
*/
|
||||||
|
DUTCH("nl"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polish language.
|
||||||
|
*/
|
||||||
|
POLISH("pl"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Portuguese language.
|
||||||
|
*/
|
||||||
|
PORTUGUESE("pt"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Romanian language.
|
||||||
|
*/
|
||||||
|
ROMANIAN ("ro"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Russian language.
|
||||||
|
*/
|
||||||
|
RUSSIAN("ru"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swedish language.
|
||||||
|
*/
|
||||||
|
SWEDISH("se"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slovak language.
|
||||||
|
*/
|
||||||
|
SLOVAK("sk"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slovenian language.
|
||||||
|
*/
|
||||||
|
SLOVENIAN("sl"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spanish language.
|
||||||
|
*/
|
||||||
|
SPANISH("en"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turkish language.
|
||||||
|
*/
|
||||||
|
TURKISH("tr"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ukranian language.
|
||||||
|
*/
|
||||||
|
UKRANIAN("uk"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vietnamese language.
|
||||||
|
*/
|
||||||
|
VIETNAMESE("vi"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chinese simplified language.
|
||||||
|
*/
|
||||||
|
CHINESE_SIMPLIFIED("zh_cn"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chinese traditional language.
|
||||||
|
*/
|
||||||
|
CHINESE_TRADITIONAL("zh_tw");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
Language(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns language's value.
|
||||||
|
* @return value.
|
||||||
|
*/
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enumeration with all available subscription plans.
|
||||||
|
* More information <a href="https://openweathermap.org/price">at official website</a>.
|
||||||
|
*/
|
||||||
|
public enum SubscriptionPlan {
|
||||||
|
/**
|
||||||
|
* Free subscription plan.
|
||||||
|
*/
|
||||||
|
FREE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Startup subscription plan.
|
||||||
|
*/
|
||||||
|
STARTUP,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Developer subscription plan.
|
||||||
|
*/
|
||||||
|
DEVELOPER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Professional subscription plan.
|
||||||
|
*/
|
||||||
|
PROFESSIONAL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enterprise subscription plan.
|
||||||
|
*/
|
||||||
|
ENTERPRISE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All existing subscription plans.
|
||||||
|
*/
|
||||||
|
ALL,
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enumeration for supported unit systems with helper methods.
|
||||||
|
*/
|
||||||
|
public enum UnitSystem {
|
||||||
|
/**
|
||||||
|
* Metric units: Celsius, meter/sec, hPa, mm(rain, snow).
|
||||||
|
*/
|
||||||
|
METRIC("metric"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imperial units: Fahrenheit, miles/hour, hPa, mm(rain, snow).
|
||||||
|
*/
|
||||||
|
IMPERIAL("imperial"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OpenWeatherMap standard units: Kelvin, meter/sec, hPa, mm(rain, snow).
|
||||||
|
*/
|
||||||
|
STANDARD("standard");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
UnitSystem(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns wind unit for current unit system.
|
||||||
|
* @return wind unit.
|
||||||
|
*/
|
||||||
|
public String getWindUnit() {
|
||||||
|
switch (this) {
|
||||||
|
case IMPERIAL:
|
||||||
|
return "miles/hour";
|
||||||
|
case STANDARD:
|
||||||
|
case METRIC:
|
||||||
|
default:
|
||||||
|
return "meter/sec";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns temperature unit for current unit system.
|
||||||
|
* @return temperature unit.
|
||||||
|
*/
|
||||||
|
public String getTemperatureUnit() {
|
||||||
|
switch (this) {
|
||||||
|
case METRIC:
|
||||||
|
return "℃";
|
||||||
|
case IMPERIAL:
|
||||||
|
return "℉";
|
||||||
|
case STANDARD:
|
||||||
|
default:
|
||||||
|
return "K";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns unit system value.
|
||||||
|
* @return value unit system.
|
||||||
|
*/
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,10 +22,16 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.exception;
|
package com.github.prominence.openweathermap.api.exception;
|
||||||
|
|
||||||
public class InvalidAuthTokenException extends Exception {
|
/**
|
||||||
|
* An exception that could be thrown in case of your API key is invalid or your subscription plan does not cover requested functionality.
|
||||||
|
* Subscription plans information you can find <a href="https://openweathermap.org/price">here</a>.
|
||||||
|
* API Keys could be checked in <a href="https://home.openweathermap.org/api_keys/">your profile</a>.
|
||||||
|
*/
|
||||||
|
public class InvalidAuthTokenException extends RuntimeException {
|
||||||
|
/**
|
||||||
|
* Creates {@link InvalidAuthTokenException} exception with default message.
|
||||||
|
*/
|
||||||
public InvalidAuthTokenException() {
|
public InvalidAuthTokenException() {
|
||||||
super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
|
super("Authentication token wasn't set or requested functionality is not permitted for your subscription plan. Please, check https://home.openweathermap.org/api_keys/ and https://openweathermap.org/price.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-39
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,46 +20,29 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
package com.github.prominence.openweathermap.api.exception;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
/**
|
||||||
|
* An exception that could be thrown in several cases:
|
||||||
import java.util.Objects;
|
* <ul>
|
||||||
|
* <li>There is no data found for your query(wrong coordinates somewhere in the sea, some distant place, etc.);</li>
|
||||||
public class Rain {
|
* <li>Request is malformed. An occasion to report an <a href="https://github.com/Prominence/openweathermap-java-api/issues">issue</a>;</li>
|
||||||
|
* <li>Any other unpredictable problems.</li>
|
||||||
@JSONField(name = "3h")
|
* </ul>
|
||||||
// Rain volume for the last 3 hours
|
*/
|
||||||
private byte rainVolumeLast3Hrs;
|
public class NoDataFoundException extends RuntimeException {
|
||||||
|
/**
|
||||||
public byte getRainVolumeLast3Hrs() {
|
* Creates {@link NoDataFoundException} with default message.
|
||||||
return rainVolumeLast3Hrs;
|
*/
|
||||||
|
public NoDataFoundException() {
|
||||||
|
super("Data for provided parameters wasn't found. Please, check requested location.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRainVolumeLast3Hrs(byte rainVolumeLast3Hrs) {
|
/**
|
||||||
this.rainVolumeLast3Hrs = rainVolumeLast3Hrs;
|
* Creates {@link NoDataFoundException} with message from another throwable.
|
||||||
}
|
* @param throwable source throwable.
|
||||||
|
*/
|
||||||
public String getUnit() {
|
public NoDataFoundException(Throwable throwable) {
|
||||||
return "mm";
|
super(throwable.getMessage(), throwable.getCause());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Rain(last 3 hrs): " + rainVolumeLast3Hrs + ' ' + getUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Rain rain = (Rain) o;
|
|
||||||
return rainVolumeLast3Hrs == rain.rainVolumeLast3Hrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(rainVolumeLast3Hrs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+155
@@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The AtmosphericPressure type represents atmospheric pressure value.
|
||||||
|
* Its value can only be a double in [0, +∞) range.
|
||||||
|
*/
|
||||||
|
public class AtmosphericPressure {
|
||||||
|
private static final String DEFAULT_UNIT = "hPa";
|
||||||
|
|
||||||
|
private double value;
|
||||||
|
|
||||||
|
private Double seaLevelValue;
|
||||||
|
private Double groundLevelValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Pressure.
|
||||||
|
*
|
||||||
|
* @param value the value representing pressure value.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
private AtmosphericPressure(double value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method for {@link AtmosphericPressure} creation with value checking.
|
||||||
|
* @param value atmospheric pressure value.
|
||||||
|
* @return instantiated {@link AtmosphericPressure} object.
|
||||||
|
*/
|
||||||
|
public static AtmosphericPressure withValue(double value) {
|
||||||
|
if (value < 0) {
|
||||||
|
throw new IllegalArgumentException("Atmospheric pressure value must be in [0, +∞) range.");
|
||||||
|
}
|
||||||
|
return new AtmosphericPressure(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns pressure value.
|
||||||
|
*
|
||||||
|
* @return pressure value.
|
||||||
|
*/
|
||||||
|
public double getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets pressure value.
|
||||||
|
*
|
||||||
|
* @param value new pressure value.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
public void setValue(double value) {
|
||||||
|
if (value < 0) {
|
||||||
|
throw new IllegalArgumentException("Atmospheric pressure value must be in [0, +∞) range.");
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets sea level value.
|
||||||
|
*
|
||||||
|
* @return the sea level value.
|
||||||
|
*/
|
||||||
|
public Double getSeaLevelValue() {
|
||||||
|
return seaLevelValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets sea level value.
|
||||||
|
*
|
||||||
|
* @param seaLevelValue the sea level value.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
public void setSeaLevelValue(double seaLevelValue) {
|
||||||
|
if (seaLevelValue < 0) {
|
||||||
|
throw new IllegalArgumentException("Atmospheric pressure value must be in [0, +∞) range.");
|
||||||
|
}
|
||||||
|
this.seaLevelValue = seaLevelValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ground level value.
|
||||||
|
*
|
||||||
|
* @return the ground level value.
|
||||||
|
*/
|
||||||
|
public Double getGroundLevelValue() {
|
||||||
|
return groundLevelValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets ground level value.
|
||||||
|
*
|
||||||
|
* @param groundLevelValue the ground level value.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
public void setGroundLevelValue(double groundLevelValue) {
|
||||||
|
if (groundLevelValue < 0) {
|
||||||
|
throw new IllegalArgumentException("Atmospheric pressure value must be in [0, +∞) range.");
|
||||||
|
}
|
||||||
|
this.groundLevelValue = groundLevelValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns pressure unitSystem. Constantly equals to 'hPa'.
|
||||||
|
*
|
||||||
|
* @return the pressure unitSystem.
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return DEFAULT_UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof AtmosphericPressure)) return false;
|
||||||
|
AtmosphericPressure atmosphericPressure = (AtmosphericPressure) o;
|
||||||
|
return Double.compare(atmosphericPressure.value, value) == 0 &&
|
||||||
|
Objects.equals(seaLevelValue, atmosphericPressure.seaLevelValue) &&
|
||||||
|
Objects.equals(groundLevelValue, atmosphericPressure.groundLevelValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(value, seaLevelValue, groundLevelValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pressure: " + value + ' ' + getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,40 +22,85 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Clouds type represents cloudiness value percentage.
|
||||||
|
* Its value can only be an integer in [0, 100] range.
|
||||||
|
*/
|
||||||
public class Clouds {
|
public class Clouds {
|
||||||
|
private static final String DEFAULT_UNIT = "%";
|
||||||
|
|
||||||
@JSONField(name = "all")
|
private byte value;
|
||||||
// Cloudiness, %
|
|
||||||
private byte cloudiness;
|
|
||||||
|
|
||||||
public byte getCloudiness() {
|
/**
|
||||||
return cloudiness;
|
* Instantiates a new Clouds.
|
||||||
|
*
|
||||||
|
* @param value the value representing cloudiness percentage.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
private Clouds(byte value) {
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCloudiness(byte cloudiness) {
|
/**
|
||||||
this.cloudiness = cloudiness;
|
* Static method for {@link Clouds} creation with value checking.
|
||||||
|
* @param value clouds percentage value.
|
||||||
|
* @return instantiated {@link Clouds} object.
|
||||||
|
*/
|
||||||
|
public static Clouds withValue(byte value) {
|
||||||
|
if (value < 0 || value > 100) {
|
||||||
|
throw new IllegalArgumentException("Cloudiness value must be in [0, 100] range.");
|
||||||
|
}
|
||||||
|
return new Clouds(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public String toString() {
|
* Returns cloudiness percentage value.
|
||||||
return "Cloudiness: " + cloudiness + "%";
|
*
|
||||||
|
* @return cloudiness percentage.
|
||||||
|
*/
|
||||||
|
public byte getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets cloudiness percentage value.
|
||||||
|
*
|
||||||
|
* @param value new cloudiness value.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
public void setValue(byte value) {
|
||||||
|
if (value < 0 || value > 100) {
|
||||||
|
throw new IllegalArgumentException("Cloudiness value must be in [0, 100] range.");
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns cloudiness unitSystem. Constantly equals to '%'.
|
||||||
|
*
|
||||||
|
* @return the cloudiness unitSystem.
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return DEFAULT_UNIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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 instanceof Clouds)) return false;
|
||||||
Clouds clouds = (Clouds) o;
|
Clouds clouds = (Clouds) o;
|
||||||
return cloudiness == clouds.cloudiness;
|
return value == clouds.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
|
return Objects.hash(value);
|
||||||
|
}
|
||||||
|
|
||||||
return Objects.hash(cloudiness);
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Clouds: " + value + getUnit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents some location by its latitude and longitude.
|
||||||
|
*/
|
||||||
|
public class Coordinate {
|
||||||
|
private double latitude;
|
||||||
|
private double longitude;
|
||||||
|
|
||||||
|
private Coordinate(double latitude, double longitude) {
|
||||||
|
this.latitude = latitude;
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for {@link Coordinate} creation with correctness check.
|
||||||
|
* @param latitude latitude
|
||||||
|
* @param longitude longitude
|
||||||
|
* @return coordinate object.
|
||||||
|
*/
|
||||||
|
public static Coordinate withValues(double latitude, double longitude) {
|
||||||
|
if (latitude < -90 || latitude > 90) {
|
||||||
|
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||||
|
}
|
||||||
|
if (longitude < -180 || longitude > 180) {
|
||||||
|
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||||
|
}
|
||||||
|
return new Coordinate(latitude, longitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets latitude with checks.
|
||||||
|
* @param latitude latitude value
|
||||||
|
*/
|
||||||
|
public void setLatitude(double latitude) {
|
||||||
|
if (latitude < -90 || latitude > 90) {
|
||||||
|
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||||
|
}
|
||||||
|
this.latitude = latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets longitude with checks.
|
||||||
|
* @param longitude longitude value
|
||||||
|
*/
|
||||||
|
public void setLongitude(double longitude) {
|
||||||
|
if (longitude < -180 || longitude > 180) {
|
||||||
|
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||||
|
}
|
||||||
|
this.longitude = longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns latitude.
|
||||||
|
* @return latitude
|
||||||
|
*/
|
||||||
|
public double getLatitude() {
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns longitude.
|
||||||
|
* @return longitude
|
||||||
|
*/
|
||||||
|
public double getLongitude() {
|
||||||
|
return longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Coordinate)) return false;
|
||||||
|
Coordinate that = (Coordinate) o;
|
||||||
|
return Double.compare(that.latitude, latitude) == 0 &&
|
||||||
|
Double.compare(that.longitude, longitude) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(latitude, longitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return formatAsDegree(latitude) +
|
||||||
|
", " + formatAsDegree(longitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatAsDegree(double value) {
|
||||||
|
int degrees = (int) value;
|
||||||
|
double secondsDouble = value % 1 * 60;
|
||||||
|
int minutes = (int) secondsDouble;
|
||||||
|
int seconds = (int) (secondsDouble % 1 * 60);
|
||||||
|
|
||||||
|
return String.format("%s° %s′ %s″", degrees, minutes, seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
+200
@@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents coordinate rectangle by its bottom-left and top-right coordinates.
|
||||||
|
*/
|
||||||
|
public class CoordinateRectangle {
|
||||||
|
private final double longitudeLeft;
|
||||||
|
private final double latitudeBottom;
|
||||||
|
private final double longitudeRight;
|
||||||
|
private final double latitudeTop;
|
||||||
|
|
||||||
|
private CoordinateRectangle(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) {
|
||||||
|
this.longitudeLeft = longitudeLeft;
|
||||||
|
this.latitudeBottom = latitudeBottom;
|
||||||
|
this.longitudeRight = longitudeRight;
|
||||||
|
this.latitudeTop = latitudeTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for {@link CoordinateRectangle} creation with correctness check.
|
||||||
|
* @param longitudeLeft left longitude
|
||||||
|
* @param latitudeBottom bottom latitude
|
||||||
|
* @param longitudeRight right longitude
|
||||||
|
* @param latitudeTop tip latitude
|
||||||
|
* @return coordinate rectangle object.
|
||||||
|
*/
|
||||||
|
public static CoordinateRectangle withValues(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) {
|
||||||
|
if (latitudeBottom < -90 || latitudeTop < -90 || latitudeBottom > 90 || latitudeTop > 90) {
|
||||||
|
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||||
|
}
|
||||||
|
if (longitudeLeft < -180 || longitudeRight < -180 || longitudeLeft > 180 || longitudeRight > 180) {
|
||||||
|
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||||
|
}
|
||||||
|
return new CoordinateRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns left longitude value.
|
||||||
|
* @return left longitude
|
||||||
|
*/
|
||||||
|
public double getLongitudeLeft() {
|
||||||
|
return longitudeLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns bottom latitude value.
|
||||||
|
* @return bottom latitude
|
||||||
|
*/
|
||||||
|
public double getLatitudeBottom() {
|
||||||
|
return latitudeBottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns right longitude value.
|
||||||
|
* @return right longitude
|
||||||
|
*/
|
||||||
|
public double getLongitudeRight() {
|
||||||
|
return longitudeRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns top latitude value.
|
||||||
|
* @return top latitude
|
||||||
|
*/
|
||||||
|
public double getLatitudeTop() {
|
||||||
|
return latitudeTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formatted coordinate rectangle string.
|
||||||
|
* @return formatted string
|
||||||
|
*/
|
||||||
|
public String getFormattedRequestString() {
|
||||||
|
return longitudeLeft + "," + latitudeBottom + "," + longitudeRight + "," + latitudeTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof CoordinateRectangle)) return false;
|
||||||
|
CoordinateRectangle rectangle = (CoordinateRectangle) o;
|
||||||
|
return Double.compare(rectangle.longitudeLeft, longitudeLeft) == 0 &&
|
||||||
|
Double.compare(rectangle.latitudeBottom, latitudeBottom) == 0 &&
|
||||||
|
Double.compare(rectangle.longitudeRight, longitudeRight) == 0 &&
|
||||||
|
Double.compare(rectangle.latitudeTop, latitudeTop) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Rectangle: " + getFormattedRequestString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for CoordinateRectangle class.
|
||||||
|
*/
|
||||||
|
public static class Builder {
|
||||||
|
private Double longitudeLeft;
|
||||||
|
private Double latitudeBottom;
|
||||||
|
private Double longitudeRight;
|
||||||
|
private Double latitudeTop;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Builder object.
|
||||||
|
*/
|
||||||
|
public Builder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets left longitude with correctness check.
|
||||||
|
* @param longitudeLeft left longitude
|
||||||
|
* @return builder object
|
||||||
|
*/
|
||||||
|
public Builder setLongitudeLeft(double longitudeLeft) {
|
||||||
|
if (longitudeLeft < -180 || longitudeLeft > 180) {
|
||||||
|
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||||
|
}
|
||||||
|
this.longitudeLeft = longitudeLeft;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets bottom latitude with correctness check.
|
||||||
|
* @param latitudeBottom bottom latitude
|
||||||
|
* @return builder object
|
||||||
|
*/
|
||||||
|
public Builder setLatitudeBottom(double latitudeBottom) {
|
||||||
|
if (latitudeBottom < -90 || latitudeBottom > 90) {
|
||||||
|
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||||
|
}
|
||||||
|
this.latitudeBottom = latitudeBottom;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets right longitude with correctness check.
|
||||||
|
* @param longitudeRight right longitude
|
||||||
|
* @return builder object
|
||||||
|
*/
|
||||||
|
public Builder setLongitudeRight(double longitudeRight) {
|
||||||
|
if (longitudeRight < -180 || longitudeRight > 180) {
|
||||||
|
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
||||||
|
}
|
||||||
|
this.longitudeRight = longitudeRight;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets top latitude with correctness check.
|
||||||
|
* @param latitudeTop top latitude
|
||||||
|
* @return builder object
|
||||||
|
*/
|
||||||
|
public Builder setLatitudeTop(double latitudeTop) {
|
||||||
|
if (latitudeTop < -90 || latitudeTop > 90) {
|
||||||
|
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||||
|
}
|
||||||
|
this.latitudeTop = latitudeTop;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds {@link CoordinateRectangle} object with correctness check.
|
||||||
|
* @return {@link CoordinateRectangle} built object.
|
||||||
|
*/
|
||||||
|
public CoordinateRectangle build() {
|
||||||
|
if (longitudeLeft == null || latitudeBottom == null || longitudeRight == null || latitudeTop == null) {
|
||||||
|
throw new IllegalStateException("Not all fields were set.");
|
||||||
|
}
|
||||||
|
return new CoordinateRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Coordinates {
|
|
||||||
|
|
||||||
@JSONField(name = "lat")
|
|
||||||
// City geo location, latitude
|
|
||||||
private float latitude;
|
|
||||||
@JSONField(name = "lon")
|
|
||||||
// City geo location, longitude
|
|
||||||
private float longitude;
|
|
||||||
|
|
||||||
public Coordinates(float latitude, float longitude) {
|
|
||||||
this.latitude = latitude;
|
|
||||||
this.longitude = longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getLatitude() {
|
|
||||||
return latitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLatitude(float latitude) {
|
|
||||||
this.latitude = latitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getLongitude() {
|
|
||||||
return longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLongitude(float longitude) {
|
|
||||||
this.longitude = longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "latitude=" + latitude + ", longitude=" + longitude;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Coordinates that = (Coordinates) o;
|
|
||||||
return Double.compare(that.latitude, latitude) == 0 &&
|
|
||||||
Double.compare(that.longitude, longitude) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(latitude, longitude);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+26
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,12 +20,33 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.exception;
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
public class DataNotFoundException extends Exception {
|
/**
|
||||||
|
* Enumeration for time of a day representation.
|
||||||
|
*/
|
||||||
|
public enum DayTime {
|
||||||
|
/**
|
||||||
|
* Day value.
|
||||||
|
*/
|
||||||
|
DAY("d"),
|
||||||
|
|
||||||
public DataNotFoundException() {
|
/**
|
||||||
super("Data for provided parameters wasn't found. Please, check your request.");
|
* Night value.
|
||||||
|
*/
|
||||||
|
NIGHT("n");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
DayTime(String value) {
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns time of a day value.
|
||||||
|
* @return string value
|
||||||
|
*/
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Humidity type represents humidity value percentage.
|
||||||
|
* Its value can only be an integer in [0, 100] range.
|
||||||
|
*/
|
||||||
|
public class Humidity {
|
||||||
|
private static final String DEFAULT_UNIT = "%";
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Humidity.
|
||||||
|
*
|
||||||
|
* @param value the value representing humidity percentage.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
private Humidity(byte value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Humidity} object with correctness check.
|
||||||
|
* @param value humidity
|
||||||
|
* @return created {@link Humidity} object
|
||||||
|
*/
|
||||||
|
public static Humidity withValue(byte value) {
|
||||||
|
if (value < 0 || value > 100) {
|
||||||
|
throw new IllegalArgumentException("Humidity value must be in [0, 100] range.");
|
||||||
|
}
|
||||||
|
return new Humidity(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns humidity percentage value.
|
||||||
|
*
|
||||||
|
* @return humidity percentage.
|
||||||
|
*/
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets humidity percentage value.
|
||||||
|
*
|
||||||
|
* @param value new humidity value.
|
||||||
|
* @throws IllegalArgumentException in case if provided value isn't in allowed range.
|
||||||
|
*/
|
||||||
|
public void setValue(int value) {
|
||||||
|
if (value < 0 || value > 100) {
|
||||||
|
throw new IllegalArgumentException("Humidity value must be in [0, 100] range.");
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns humidity unitSystem. Constantly equals to '%'.
|
||||||
|
*
|
||||||
|
* @return the humidity unitSystem.
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return DEFAULT_UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Humidity)) return false;
|
||||||
|
Humidity humidity = (Humidity) o;
|
||||||
|
return value == humidity.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Humidity: " + value + getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Snow {
|
|
||||||
|
|
||||||
@JSONField(name = "all")
|
|
||||||
// Snow volume for the last 3 hours
|
|
||||||
private byte snowVolumeLast3Hrs;
|
|
||||||
|
|
||||||
public byte getSnowVolumeLast3Hrs() {
|
|
||||||
return snowVolumeLast3Hrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSnowVolumeLast3Hrs(byte snowVolumeLast3Hrs) {
|
|
||||||
this.snowVolumeLast3Hrs = snowVolumeLast3Hrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUnit() {
|
|
||||||
return "mm";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Snow(last 3 hrs): " + snowVolumeLast3Hrs + ' ' + getUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Snow snow = (Snow) o;
|
|
||||||
return snowVolumeLast3Hrs == snow.snowVolumeLast3Hrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(snowVolumeLast3Hrs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents temperature values and unit.
|
||||||
|
*/
|
||||||
|
public class Temperature {
|
||||||
|
private double value;
|
||||||
|
private Double maxTemperature;
|
||||||
|
private Double minTemperature;
|
||||||
|
private Double feelsLike;
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
private Temperature(double value, String unit) {
|
||||||
|
this.value = value;
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Temperature} object with correctness check.
|
||||||
|
* @param value temperature value
|
||||||
|
* @param unit temperature unit
|
||||||
|
* @return temperature object
|
||||||
|
*/
|
||||||
|
public static Temperature withValue(double value, String unit) {
|
||||||
|
if (unit == null) {
|
||||||
|
throw new IllegalArgumentException("Unit must be set.");
|
||||||
|
}
|
||||||
|
return new Temperature(value, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns temperature value.
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
public double getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets temperature value.
|
||||||
|
* @param value temperature
|
||||||
|
*/
|
||||||
|
public void setValue(double value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns maximal temperature value.
|
||||||
|
* @return maximal temperature value
|
||||||
|
*/
|
||||||
|
public Double getMaxTemperature() {
|
||||||
|
return maxTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets maximal temperature value.
|
||||||
|
* @param maxTemperature maximal temperature
|
||||||
|
*/
|
||||||
|
public void setMaxTemperature(Double maxTemperature) {
|
||||||
|
this.maxTemperature = maxTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns minimal temperature value.
|
||||||
|
* @return minimal temperature value
|
||||||
|
*/
|
||||||
|
public Double getMinTemperature() {
|
||||||
|
return minTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets minimal temperature value.
|
||||||
|
* @param minTemperature minimal temperature
|
||||||
|
*/
|
||||||
|
public void setMinTemperature(Double minTemperature) {
|
||||||
|
this.minTemperature = minTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns 'feels like' temperature value.
|
||||||
|
* @return 'feels like' temperature value
|
||||||
|
*/
|
||||||
|
public Double getFeelsLike() {
|
||||||
|
return feelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets 'feels like' temperature value.
|
||||||
|
* @param feelsLike 'feels like' temperature
|
||||||
|
*/
|
||||||
|
public void setFeelsLike(Double feelsLike) {
|
||||||
|
this.feelsLike = feelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns temperature unit.
|
||||||
|
* @return unit
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets temperature unit with correctness check.
|
||||||
|
* @param unit temperature unit
|
||||||
|
*/
|
||||||
|
public void setUnit(String unit) {
|
||||||
|
if (unit == null) {
|
||||||
|
throw new IllegalArgumentException("Unit must be set.");
|
||||||
|
}
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Temperature)) return false;
|
||||||
|
Temperature that = (Temperature) o;
|
||||||
|
return Double.compare(that.value, value) == 0 &&
|
||||||
|
Objects.equals(maxTemperature, that.maxTemperature) &&
|
||||||
|
Objects.equals(minTemperature, that.minTemperature) &&
|
||||||
|
Objects.equals(feelsLike, that.feelsLike) &&
|
||||||
|
Objects.equals(unit, that.unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(value, maxTemperature, minTemperature, feelsLike, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("Temperature: ");
|
||||||
|
stringBuilder.append(value);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(unit);
|
||||||
|
if (maxTemperature != null) {
|
||||||
|
stringBuilder.append(", Maximum value: ");
|
||||||
|
stringBuilder.append(maxTemperature);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(unit);
|
||||||
|
}
|
||||||
|
if (minTemperature != null) {
|
||||||
|
stringBuilder.append(", Minimum value: ");
|
||||||
|
stringBuilder.append(minTemperature);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(unit);
|
||||||
|
}
|
||||||
|
if (feelsLike != null) {
|
||||||
|
stringBuilder.append(", Feels like: ");
|
||||||
|
stringBuilder.append(feelsLike);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class WeatherState {
|
|
||||||
|
|
||||||
@JSONField(name = "id")
|
|
||||||
// Weather condition id
|
|
||||||
long conditionId;
|
|
||||||
|
|
||||||
@JSONField(name = "main")
|
|
||||||
// Group of weather parameters (Rain, Snow, Extreme etc.)
|
|
||||||
String weatherGroup;
|
|
||||||
|
|
||||||
@JSONField(name = "description")
|
|
||||||
// Weather condition within the group
|
|
||||||
String description;
|
|
||||||
|
|
||||||
@JSONField(name = "icon")
|
|
||||||
// Weather icon id
|
|
||||||
String iconId;
|
|
||||||
|
|
||||||
public long getConditionId() {
|
|
||||||
return conditionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConditionId(long conditionId) {
|
|
||||||
this.conditionId = conditionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWeatherGroup() {
|
|
||||||
return weatherGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeatherGroup(String weatherGroup) {
|
|
||||||
this.weatherGroup = weatherGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIconId() {
|
|
||||||
return iconId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIconId(String iconId) {
|
|
||||||
this.iconId = iconId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getWeatherIconUrl() {
|
|
||||||
URL iconUrl = null;
|
|
||||||
try {
|
|
||||||
iconUrl = new URL("http://openweathermap.org/img/w/" + iconId + ".png");
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return iconUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Weather: " + description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
WeatherState weatherState = (WeatherState) o;
|
|
||||||
return conditionId == weatherState.conditionId &&
|
|
||||||
Objects.equals(weatherGroup, weatherState.weatherGroup) &&
|
|
||||||
Objects.equals(description, weatherState.description) &&
|
|
||||||
Objects.equals(iconId, weatherState.iconId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(conditionId, weatherGroup, description, iconId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Wind {
|
|
||||||
|
|
||||||
@JSONField(name = "speed")
|
|
||||||
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
|
||||||
private float speed;
|
|
||||||
|
|
||||||
private String unit;
|
|
||||||
|
|
||||||
@JSONField(name = "deg")
|
|
||||||
// Wind direction, degrees (meteorological)
|
|
||||||
private short degrees;
|
|
||||||
|
|
||||||
public float getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpeed(float speed) {
|
|
||||||
this.speed = speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUnit() {
|
|
||||||
return unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUnit(String unit) {
|
|
||||||
this.unit = unit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getDegrees() {
|
|
||||||
return degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDegrees(short degrees) {
|
|
||||||
this.degrees = degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Wind: " + speed + ' ' + unit + ", " + degrees + " degrees";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Wind wind = (Wind) o;
|
|
||||||
return Float.compare(wind.speed, speed) == 0 &&
|
|
||||||
degrees == wind.degrees;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(speed, degrees);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents information about forecast for different timestamps.
|
||||||
|
*/
|
||||||
|
public class Forecast {
|
||||||
|
private Location location;
|
||||||
|
private List<WeatherForecast> weatherForecasts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location information.
|
||||||
|
* @return location
|
||||||
|
*/
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets forecast location.
|
||||||
|
* @param location forecast location
|
||||||
|
*/
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns list of weather forecasts for different timestamps.
|
||||||
|
* @return list of forecast-per-timestamp information.
|
||||||
|
*/
|
||||||
|
public List<WeatherForecast> getWeatherForecasts() {
|
||||||
|
return weatherForecasts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets list of weather forecasts for different timestamps.
|
||||||
|
* @param weatherForecasts list of forecast information
|
||||||
|
*/
|
||||||
|
public void setWeatherForecasts(List<WeatherForecast> weatherForecasts) {
|
||||||
|
this.weatherForecasts = weatherForecasts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Forecast forecast = (Forecast) o;
|
||||||
|
return Objects.equals(location, forecast.location) && Objects.equals(weatherForecasts, forecast.weatherForecasts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(location, weatherForecasts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "A forecast for " + location.getName() + " with " + weatherForecasts.size() + " timestamps.";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents location information.
|
||||||
|
*/
|
||||||
|
public class Location {
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String countryCode;
|
||||||
|
|
||||||
|
private LocalDateTime sunrise;
|
||||||
|
private LocalDateTime sunset;
|
||||||
|
private ZoneOffset zoneOffset;
|
||||||
|
|
||||||
|
private Coordinate coordinate;
|
||||||
|
|
||||||
|
private Long population;
|
||||||
|
|
||||||
|
private Location(int id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Location} object with correctness check.
|
||||||
|
* @param id location id
|
||||||
|
* @param name location name
|
||||||
|
* @return location object
|
||||||
|
*/
|
||||||
|
public static Location withValues(int id, String name) {
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("Name must be set.");
|
||||||
|
}
|
||||||
|
return new Location(id, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns ID.
|
||||||
|
* @return location ID
|
||||||
|
*/
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location ID.
|
||||||
|
* @param id location id
|
||||||
|
*/
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location name.
|
||||||
|
* @return location name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location name.
|
||||||
|
* @param name location name
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns country code.
|
||||||
|
* @return location country code
|
||||||
|
*/
|
||||||
|
public String getCountryCode() {
|
||||||
|
return countryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location country code.
|
||||||
|
* @param countryCode location country code
|
||||||
|
*/
|
||||||
|
public void setCountryCode(String countryCode) {
|
||||||
|
this.countryCode = countryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location sunrise time.
|
||||||
|
* @return sunrise time
|
||||||
|
*/
|
||||||
|
public LocalDateTime getSunrise() {
|
||||||
|
return sunrise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location sunrise time.
|
||||||
|
* @param sunrise sunrise time
|
||||||
|
*/
|
||||||
|
public void setSunrise(LocalDateTime sunrise) {
|
||||||
|
this.sunrise = sunrise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location sunset time.
|
||||||
|
* @return sunset time
|
||||||
|
*/
|
||||||
|
public LocalDateTime getSunset() {
|
||||||
|
return sunset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location sunset time.
|
||||||
|
* @param sunset sunset time
|
||||||
|
*/
|
||||||
|
public void setSunset(LocalDateTime sunset) {
|
||||||
|
this.sunset = sunset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location timezone offset.
|
||||||
|
* @return timezone offset
|
||||||
|
*/
|
||||||
|
public ZoneOffset getZoneOffset() {
|
||||||
|
return zoneOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location timezone offset.
|
||||||
|
* @param zoneOffset timezone offset
|
||||||
|
*/
|
||||||
|
public void setZoneOffset(ZoneOffset zoneOffset) {
|
||||||
|
this.zoneOffset = zoneOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location coordinates.
|
||||||
|
* @return location coordinates.
|
||||||
|
*/
|
||||||
|
public Coordinate getCoordinate() {
|
||||||
|
return coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location coordinates.
|
||||||
|
* @param coordinate location coordinates
|
||||||
|
*/
|
||||||
|
public void setCoordinate(Coordinate coordinate) {
|
||||||
|
this.coordinate = coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location population.
|
||||||
|
* @return location population
|
||||||
|
*/
|
||||||
|
public Long getPopulation() {
|
||||||
|
return population;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location population.
|
||||||
|
* @param population location population
|
||||||
|
*/
|
||||||
|
public void setPopulation(Long population) {
|
||||||
|
this.population = population;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Location)) return false;
|
||||||
|
Location location = (Location) o;
|
||||||
|
return id == location.id &&
|
||||||
|
Objects.equals(name, location.name) &&
|
||||||
|
Objects.equals(countryCode, location.countryCode) &&
|
||||||
|
Objects.equals(sunrise, location.sunrise) &&
|
||||||
|
Objects.equals(sunset, location.sunset) &&
|
||||||
|
Objects.equals(zoneOffset, location.zoneOffset) &&
|
||||||
|
Objects.equals(coordinate, location.coordinate) &&
|
||||||
|
Objects.equals(population, location.population);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, countryCode, sunrise, sunset, zoneOffset, coordinate, population);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (coordinate != null) {
|
||||||
|
stringBuilder.append(coordinate.toString());
|
||||||
|
stringBuilder.append(". ");
|
||||||
|
}
|
||||||
|
stringBuilder.append("ID: ");
|
||||||
|
stringBuilder.append(id);
|
||||||
|
stringBuilder.append(", Name: ");
|
||||||
|
stringBuilder.append(name);
|
||||||
|
if (countryCode != null) {
|
||||||
|
stringBuilder.append('(');
|
||||||
|
stringBuilder.append(countryCode);
|
||||||
|
stringBuilder.append(')');
|
||||||
|
}
|
||||||
|
if (population != null) {
|
||||||
|
stringBuilder.append(", Population: ");
|
||||||
|
stringBuilder.append(population);
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents rain information.
|
||||||
|
*/
|
||||||
|
public class Rain {
|
||||||
|
private static final String DEFAULT_UNIT = "mm";
|
||||||
|
|
||||||
|
private double threeHourRainLevel;
|
||||||
|
|
||||||
|
private Rain(double threeHourRainLevel) {
|
||||||
|
this.threeHourRainLevel = threeHourRainLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Rain} object with correctness check.
|
||||||
|
* @param threeHourRainLevel 3-hour rain level value
|
||||||
|
* @return rain object.
|
||||||
|
*/
|
||||||
|
public static Rain withThreeHourLevelValue(double threeHourRainLevel) {
|
||||||
|
if (threeHourRainLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
return new Rain(threeHourRainLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns 3-hour rain level value.
|
||||||
|
* @return 3-hour rain level value
|
||||||
|
*/
|
||||||
|
public double getThreeHourRainLevel() {
|
||||||
|
return threeHourRainLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets 3-hour rain level value with correctness check.
|
||||||
|
* @param threeHourRainLevel 3-hour rain level value
|
||||||
|
*/
|
||||||
|
public void setThreeHourRainLevel(double threeHourRainLevel) {
|
||||||
|
if (threeHourRainLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.threeHourRainLevel = threeHourRainLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns rain level unit of measure. Currently is constant.
|
||||||
|
* @return rain level unit of measure
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return DEFAULT_UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Rain rain = (Rain) o;
|
||||||
|
return Double.compare(rain.threeHourRainLevel, threeHourRainLevel) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(threeHourRainLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "3-hour rain level: " +
|
||||||
|
threeHourRainLevel + ' ' +
|
||||||
|
getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents snow information.
|
||||||
|
*/
|
||||||
|
public class Snow {
|
||||||
|
private static final String DEFAULT_UNIT = "mm";
|
||||||
|
|
||||||
|
private double threeHourSnowLevel;
|
||||||
|
|
||||||
|
private Snow(double threeHourSnowLevel) {
|
||||||
|
this.threeHourSnowLevel = threeHourSnowLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Snow} object with correctness check.
|
||||||
|
* @param threeHourSnowLevel 3-hour snow level value
|
||||||
|
* @return snow object.
|
||||||
|
*/
|
||||||
|
public static Snow withThreeHourLevelValue(double threeHourSnowLevel) {
|
||||||
|
if (threeHourSnowLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||||
|
}
|
||||||
|
return new Snow(threeHourSnowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns 3-hour snow level value.
|
||||||
|
* @return 3-hour snow level value
|
||||||
|
*/
|
||||||
|
public double getThreeHourSnowLevel() {
|
||||||
|
return threeHourSnowLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets 3-hour snow level value with correctness check.
|
||||||
|
* @param threeHourSnowLevel 3-hour snow level value
|
||||||
|
*/
|
||||||
|
public void setThreeHourSnowLevel(double threeHourSnowLevel) {
|
||||||
|
if (threeHourSnowLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.threeHourSnowLevel = threeHourSnowLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns snow level unit of measure. Currently is constant.
|
||||||
|
* @return snow level unit of measure
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return DEFAULT_UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Snow snow = (Snow) o;
|
||||||
|
return Double.compare(snow.threeHourSnowLevel, threeHourSnowLevel) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(threeHourSnowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "3-hour snow level: " +
|
||||||
|
threeHourSnowLevel + ' ' +
|
||||||
|
getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
+376
@@ -0,0 +1,376 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents weather forecast information for a particular timestamp.
|
||||||
|
*/
|
||||||
|
public class WeatherForecast {
|
||||||
|
private String state;
|
||||||
|
private String description;
|
||||||
|
private String weatherIconUrl;
|
||||||
|
|
||||||
|
private LocalDateTime forecastTime;
|
||||||
|
|
||||||
|
private Temperature temperature;
|
||||||
|
private AtmosphericPressure atmosphericPressure;
|
||||||
|
private Humidity humidity;
|
||||||
|
|
||||||
|
private Wind wind;
|
||||||
|
private Rain rain;
|
||||||
|
private Snow snow;
|
||||||
|
private Clouds clouds;
|
||||||
|
|
||||||
|
private String forecastTimeISO;
|
||||||
|
private DayTime dayTime;
|
||||||
|
|
||||||
|
private WeatherForecast(String state, String description) {
|
||||||
|
this.state = state;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For value weather forecast.
|
||||||
|
*
|
||||||
|
* @param state the state
|
||||||
|
* @param description the description
|
||||||
|
* @return the weather forecast
|
||||||
|
*/
|
||||||
|
public static WeatherForecast forValue(String state, String description) {
|
||||||
|
if (state == null) {
|
||||||
|
throw new IllegalArgumentException("State must be set.");
|
||||||
|
}
|
||||||
|
if (description == null) {
|
||||||
|
throw new IllegalArgumentException("Description must be set.");
|
||||||
|
}
|
||||||
|
return new WeatherForecast(state, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets state.
|
||||||
|
*
|
||||||
|
* @param state the state
|
||||||
|
*/
|
||||||
|
public void setState(String state) {
|
||||||
|
if (state == null) {
|
||||||
|
throw new IllegalArgumentException("State must be not null.");
|
||||||
|
}
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets description.
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets description.
|
||||||
|
*
|
||||||
|
* @param description the description
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) {
|
||||||
|
if (description == null) {
|
||||||
|
throw new IllegalArgumentException("Description must be not null.");
|
||||||
|
}
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets weather icon url.
|
||||||
|
*
|
||||||
|
* @return the weather icon url
|
||||||
|
*/
|
||||||
|
public String getWeatherIconUrl() {
|
||||||
|
return weatherIconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets weather icon url.
|
||||||
|
*
|
||||||
|
* @param weatherIconUrl the weather icon url
|
||||||
|
*/
|
||||||
|
public void setWeatherIconUrl(String weatherIconUrl) {
|
||||||
|
this.weatherIconUrl = weatherIconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets forecast time.
|
||||||
|
*
|
||||||
|
* @return the forecast time
|
||||||
|
*/
|
||||||
|
public LocalDateTime getForecastTime() {
|
||||||
|
return forecastTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets forecast time.
|
||||||
|
*
|
||||||
|
* @param forecastTime the forecast time
|
||||||
|
*/
|
||||||
|
public void setForecastTime(LocalDateTime forecastTime) {
|
||||||
|
this.forecastTime = forecastTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets temperature.
|
||||||
|
*
|
||||||
|
* @return the temperature
|
||||||
|
*/
|
||||||
|
public Temperature getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets temperature.
|
||||||
|
*
|
||||||
|
* @param temperature the temperature
|
||||||
|
*/
|
||||||
|
public void setTemperature(Temperature temperature) {
|
||||||
|
this.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets atmospheric pressure.
|
||||||
|
*
|
||||||
|
* @return the atmospheric pressure
|
||||||
|
*/
|
||||||
|
public AtmosphericPressure getAtmosphericPressure() {
|
||||||
|
return atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets atmospheric pressure.
|
||||||
|
*
|
||||||
|
* @param atmosphericPressure the atmospheric pressure
|
||||||
|
*/
|
||||||
|
public void setAtmosphericPressure(AtmosphericPressure atmosphericPressure) {
|
||||||
|
this.atmosphericPressure = atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets humidity.
|
||||||
|
*
|
||||||
|
* @return the humidity
|
||||||
|
*/
|
||||||
|
public Humidity getHumidity() {
|
||||||
|
return humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets humidity.
|
||||||
|
*
|
||||||
|
* @param humidity the humidity
|
||||||
|
*/
|
||||||
|
public void setHumidity(Humidity humidity) {
|
||||||
|
this.humidity = humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets wind.
|
||||||
|
*
|
||||||
|
* @return the wind
|
||||||
|
*/
|
||||||
|
public Wind getWind() {
|
||||||
|
return wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets wind.
|
||||||
|
*
|
||||||
|
* @param wind the wind
|
||||||
|
*/
|
||||||
|
public void setWind(Wind wind) {
|
||||||
|
this.wind = wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets rain.
|
||||||
|
*
|
||||||
|
* @return the rain
|
||||||
|
*/
|
||||||
|
public Rain getRain() {
|
||||||
|
return rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets rain.
|
||||||
|
*
|
||||||
|
* @param rain the rain
|
||||||
|
*/
|
||||||
|
public void setRain(Rain rain) {
|
||||||
|
this.rain = rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets snow.
|
||||||
|
*
|
||||||
|
* @return the snow
|
||||||
|
*/
|
||||||
|
public Snow getSnow() {
|
||||||
|
return snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets snow.
|
||||||
|
*
|
||||||
|
* @param snow the snow
|
||||||
|
*/
|
||||||
|
public void setSnow(Snow snow) {
|
||||||
|
this.snow = snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets clouds.
|
||||||
|
*
|
||||||
|
* @return the clouds
|
||||||
|
*/
|
||||||
|
public Clouds getClouds() {
|
||||||
|
return clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets clouds.
|
||||||
|
*
|
||||||
|
* @param clouds the clouds
|
||||||
|
*/
|
||||||
|
public void setClouds(Clouds clouds) {
|
||||||
|
this.clouds = clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets forecast time iso.
|
||||||
|
*
|
||||||
|
* @return the forecast time iso
|
||||||
|
*/
|
||||||
|
public String getForecastTimeISO() {
|
||||||
|
return forecastTimeISO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets forecast time iso.
|
||||||
|
*
|
||||||
|
* @param forecastTimeISO the forecast time iso
|
||||||
|
*/
|
||||||
|
public void setForecastTimeISO(String forecastTimeISO) {
|
||||||
|
this.forecastTimeISO = forecastTimeISO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets day time.
|
||||||
|
*
|
||||||
|
* @return the day time
|
||||||
|
*/
|
||||||
|
public DayTime getDayTime() {
|
||||||
|
return dayTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets day time.
|
||||||
|
*
|
||||||
|
* @param dayTime the day time
|
||||||
|
*/
|
||||||
|
public void setDayTime(DayTime dayTime) {
|
||||||
|
this.dayTime = dayTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
WeatherForecast that = (WeatherForecast) o;
|
||||||
|
return Objects.equals(state, that.state) &&
|
||||||
|
Objects.equals(description, that.description) &&
|
||||||
|
Objects.equals(weatherIconUrl, that.weatherIconUrl) &&
|
||||||
|
Objects.equals(forecastTime, that.forecastTime) &&
|
||||||
|
Objects.equals(temperature, that.temperature) &&
|
||||||
|
Objects.equals(atmosphericPressure, that.atmosphericPressure) &&
|
||||||
|
Objects.equals(humidity, that.humidity) &&
|
||||||
|
Objects.equals(wind, that.wind) &&
|
||||||
|
Objects.equals(rain, that.rain) &&
|
||||||
|
Objects.equals(snow, that.snow) &&
|
||||||
|
Objects.equals(clouds, that.clouds) &&
|
||||||
|
Objects.equals(forecastTimeISO, that.forecastTimeISO) &&
|
||||||
|
dayTime == that.dayTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(state, description, weatherIconUrl, forecastTime, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("Timestamp: ");
|
||||||
|
stringBuilder.append(forecastTimeISO);
|
||||||
|
stringBuilder.append(", Weather: ");
|
||||||
|
stringBuilder.append(description);
|
||||||
|
if (temperature != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(temperature.getValue());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(temperature.getUnit());
|
||||||
|
}
|
||||||
|
if (atmosphericPressure != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(atmosphericPressure.getValue());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(atmosphericPressure.getUnit());
|
||||||
|
}
|
||||||
|
if (clouds != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(clouds.toString());
|
||||||
|
}
|
||||||
|
if (rain != null) {
|
||||||
|
stringBuilder.append(", Rain: ");
|
||||||
|
stringBuilder.append(rain.getThreeHourRainLevel());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(rain.getUnit());
|
||||||
|
}
|
||||||
|
if (snow != null) {
|
||||||
|
stringBuilder.append(", Snow: ");
|
||||||
|
stringBuilder.append(snow.getThreeHourSnowLevel());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(snow.getUnit());
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents wind information.
|
||||||
|
*/
|
||||||
|
public class Wind {
|
||||||
|
private double speed;
|
||||||
|
private Double degrees;
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Wind.
|
||||||
|
*
|
||||||
|
* @param speed the speed
|
||||||
|
* @param unit the unitSystem
|
||||||
|
*/
|
||||||
|
private Wind(double speed, String unit) {
|
||||||
|
this.speed = speed;
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Wind} object with correctness check
|
||||||
|
* @param speed the wind
|
||||||
|
* @param unit the unitSystem
|
||||||
|
* @return created wind object
|
||||||
|
*/
|
||||||
|
public static Wind withValue(double speed, String unit) {
|
||||||
|
if (speed < 0) {
|
||||||
|
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
|
||||||
|
}
|
||||||
|
if (unit == null) {
|
||||||
|
throw new IllegalArgumentException("Unit must be set.");
|
||||||
|
}
|
||||||
|
return new Wind(speed, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets speed.
|
||||||
|
*
|
||||||
|
* @return the speed
|
||||||
|
*/
|
||||||
|
public double getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets speed.
|
||||||
|
*
|
||||||
|
* @param speed the speed
|
||||||
|
*/
|
||||||
|
public void setSpeed(double speed) {
|
||||||
|
if (speed < 0) {
|
||||||
|
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
|
||||||
|
}
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets degrees.
|
||||||
|
*
|
||||||
|
* @return the degrees
|
||||||
|
*/
|
||||||
|
public Double getDegrees() {
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets degrees.
|
||||||
|
*
|
||||||
|
* @param degrees the degrees
|
||||||
|
*/
|
||||||
|
public void setDegrees(double degrees) {
|
||||||
|
if (degrees < 0 || degrees > 360) {
|
||||||
|
throw new IllegalArgumentException("Wind direction value must be in [0, 360] range.");
|
||||||
|
}
|
||||||
|
this.degrees = degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets unitSystem.
|
||||||
|
*
|
||||||
|
* @return the unitSystem
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets unitSystem.
|
||||||
|
*
|
||||||
|
* @param unit the unitSystem
|
||||||
|
*/
|
||||||
|
public void setUnit(String unit) {
|
||||||
|
if (unit == null) {
|
||||||
|
throw new IllegalArgumentException("Unit must be set.");
|
||||||
|
}
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Wind)) return false;
|
||||||
|
Wind wind = (Wind) o;
|
||||||
|
return Double.compare(wind.speed, speed) == 0 &&
|
||||||
|
Objects.equals(degrees, wind.degrees) &&
|
||||||
|
Objects.equals(unit, wind.unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(speed, degrees, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Wind speed: " + speed + " " + unit +
|
||||||
|
", degrees: " + degrees;
|
||||||
|
}
|
||||||
|
}
|
||||||
-609
@@ -1,609 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model.response;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
import com.github.prominence.openweathermap.api.model.*;
|
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class HourlyForecast implements OpenWeatherResponse {
|
|
||||||
|
|
||||||
@JSONField(name = "cod")
|
|
||||||
private short responseCode;
|
|
||||||
|
|
||||||
private double message;
|
|
||||||
|
|
||||||
// Number of lines returned by this API call
|
|
||||||
private short cnt;
|
|
||||||
|
|
||||||
@JSONField(name = "list")
|
|
||||||
private List<Forecast> forecasts;
|
|
||||||
|
|
||||||
@JSONField(name = "city")
|
|
||||||
private CityInfo cityInfo;
|
|
||||||
|
|
||||||
public short getResponseCode() {
|
|
||||||
return responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseCode(short responseCode) {
|
|
||||||
this.responseCode = responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(double message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getCnt() {
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCnt(short cnt) {
|
|
||||||
this.cnt = cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Forecast> getForecasts() {
|
|
||||||
return forecasts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setForecasts(List<Forecast> forecasts) {
|
|
||||||
this.forecasts = forecasts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CityInfo getCityInfo() {
|
|
||||||
return cityInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCityInfo(CityInfo cityInfo) {
|
|
||||||
this.cityInfo = cityInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCityName() {
|
|
||||||
return cityInfo.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getCityId() {
|
|
||||||
return cityInfo.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCountry() {
|
|
||||||
return cityInfo.country;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Coordinates getCoordinates() {
|
|
||||||
return cityInfo.coordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getAverageTemperature() {
|
|
||||||
return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.temperature).average().orElse(0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMinimumTemperature() {
|
|
||||||
return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.temperature).min().orElse(0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMaximumTemperature() {
|
|
||||||
return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.temperature).max().orElse(0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Forecast getByMinimumTemperature() {
|
|
||||||
return forecasts.stream().min(Comparator.comparing(forecast -> forecast.weatherInfo.minimumTemperature)).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.weatherInfo.pressure).average().orElse(0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMinimumPressure() {
|
|
||||||
return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.pressure).min().orElse(0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMaximumPressure() {
|
|
||||||
return (float)forecasts.stream().mapToDouble(forecast -> forecast.weatherInfo.pressure).max().orElse(0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Forecast getByMinimumPressure() {
|
|
||||||
return forecasts.stream().min(Comparator.comparing(forecast -> forecast.weatherInfo.pressure)).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Forecast getByMaximumPressure() {
|
|
||||||
return forecasts.stream().max(Comparator.comparing(forecast -> forecast.weatherInfo.pressure)).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.append(cityInfo);
|
|
||||||
stringBuilder.append("\nForecasts: ");
|
|
||||||
forecasts.forEach(forecast -> {
|
|
||||||
stringBuilder.append("\n\t");
|
|
||||||
stringBuilder.append(forecast);
|
|
||||||
});
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
HourlyForecast that = (HourlyForecast) o;
|
|
||||||
return responseCode == that.responseCode &&
|
|
||||||
Double.compare(that.message, message) == 0 &&
|
|
||||||
cnt == that.cnt &&
|
|
||||||
Objects.equals(forecasts, that.forecasts) &&
|
|
||||||
Objects.equals(cityInfo, that.cityInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(responseCode, message, cnt, forecasts, cityInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class CityInfo {
|
|
||||||
|
|
||||||
// City ID
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
// City name
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@JSONField(name = "coord")
|
|
||||||
private Coordinates coordinates;
|
|
||||||
|
|
||||||
// Country code (GB, JP etc.)
|
|
||||||
private String country;
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Coordinates getCoordinates() {
|
|
||||||
return coordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCoordinates(Coordinates coordinates) {
|
|
||||||
this.coordinates = coordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCountry() {
|
|
||||||
return country;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCountry(String country) {
|
|
||||||
this.country = country;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "City: " + name + "(" + id + "). Coordinates: " + coordinates + '\n' + "Country: " + country;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
CityInfo cityInfo = (CityInfo) o;
|
|
||||||
return id == cityInfo.id &&
|
|
||||||
Objects.equals(name, cityInfo.name) &&
|
|
||||||
Objects.equals(coordinates, cityInfo.coordinates) &&
|
|
||||||
Objects.equals(country, cityInfo.country);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(id, name, coordinates, country);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Forecast {
|
|
||||||
|
|
||||||
@JSONField(name = "dt")
|
|
||||||
// Time of data calculation, unix, UTC
|
|
||||||
private long dataCalculationTime;
|
|
||||||
|
|
||||||
@JSONField(name = "main")
|
|
||||||
private WeatherInfo weatherInfo;
|
|
||||||
|
|
||||||
@JSONField(name = "weather")
|
|
||||||
private List<WeatherState> weatherStates;
|
|
||||||
|
|
||||||
private Clouds clouds;
|
|
||||||
|
|
||||||
private Wind wind;
|
|
||||||
|
|
||||||
private Snow snow;
|
|
||||||
|
|
||||||
private Rain rain;
|
|
||||||
|
|
||||||
@JSONField(name = "sys")
|
|
||||||
private ForecastSystemInfo systemInfo;
|
|
||||||
|
|
||||||
// Data/time of calculation, UTC
|
|
||||||
private String dt_txt;
|
|
||||||
|
|
||||||
public long getDataCalculationTime() {
|
|
||||||
return dataCalculationTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDataCalculationTime(long dataCalculationTime) {
|
|
||||||
this.dataCalculationTime = dataCalculationTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDataCalculationDate() {
|
|
||||||
return new Date(dataCalculationTime * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeatherInfo getWeatherInfo() {
|
|
||||||
return weatherInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeatherInfo(WeatherInfo weatherInfo) {
|
|
||||||
this.weatherInfo = weatherInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<WeatherState> getWeatherStates() {
|
|
||||||
return weatherStates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeatherStates(List<WeatherState> weatherStates) {
|
|
||||||
this.weatherStates = weatherStates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Clouds getClouds() {
|
|
||||||
return clouds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClouds(Clouds clouds) {
|
|
||||||
this.clouds = clouds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Wind getWind() {
|
|
||||||
return wind;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWind(Wind wind) {
|
|
||||||
this.wind = wind;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Snow getSnow() {
|
|
||||||
return snow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSnow(Snow snow) {
|
|
||||||
this.snow = snow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rain getRain() {
|
|
||||||
return rain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRain(Rain rain) {
|
|
||||||
this.rain = rain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ForecastSystemInfo getSystemInfo() {
|
|
||||||
return systemInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSystemInfo(ForecastSystemInfo systemInfo) {
|
|
||||||
this.systemInfo = systemInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDt_txt() {
|
|
||||||
return dt_txt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDt_txt(String dt_txt) {
|
|
||||||
this.dt_txt = dt_txt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.append("Time: ");
|
|
||||||
stringBuilder.append(new Date(dataCalculationTime * 1000));
|
|
||||||
stringBuilder.append(". ");
|
|
||||||
if (weatherStates.size() == 1) {
|
|
||||||
stringBuilder.append(weatherStates.get(0));
|
|
||||||
} else {
|
|
||||||
stringBuilder.append(weatherStates);
|
|
||||||
}
|
|
||||||
stringBuilder.append(". ");
|
|
||||||
stringBuilder.append(weatherInfo);
|
|
||||||
if (clouds != null) {
|
|
||||||
stringBuilder.append(". ");
|
|
||||||
stringBuilder.append(clouds);
|
|
||||||
}
|
|
||||||
if (wind != null) {
|
|
||||||
stringBuilder.append(". ");
|
|
||||||
stringBuilder.append(wind);
|
|
||||||
}
|
|
||||||
if (snow != null) {
|
|
||||||
stringBuilder.append(". ");
|
|
||||||
stringBuilder.append(snow);
|
|
||||||
}
|
|
||||||
if (rain != null) {
|
|
||||||
stringBuilder.append(". ");
|
|
||||||
stringBuilder.append(rain);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Forecast that = (Forecast) o;
|
|
||||||
return dataCalculationTime == that.dataCalculationTime &&
|
|
||||||
Objects.equals(weatherInfo, that.weatherInfo) &&
|
|
||||||
Objects.equals(weatherStates, that.weatherStates) &&
|
|
||||||
Objects.equals(clouds, that.clouds) &&
|
|
||||||
Objects.equals(wind, that.wind) &&
|
|
||||||
Objects.equals(snow, that.snow) &&
|
|
||||||
Objects.equals(rain, that.rain) &&
|
|
||||||
Objects.equals(systemInfo, that.systemInfo) &&
|
|
||||||
Objects.equals(dt_txt, that.dt_txt);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(dataCalculationTime, weatherInfo, weatherStates, clouds, wind, snow, rain, systemInfo, dt_txt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ForecastSystemInfo {
|
|
||||||
|
|
||||||
private String pod;
|
|
||||||
|
|
||||||
public String getPod() {
|
|
||||||
return pod;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPod(String pod) {
|
|
||||||
this.pod = pod;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ForecastSystemInfo{" +
|
|
||||||
"pod='" + pod + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
ForecastSystemInfo that = (ForecastSystemInfo) o;
|
|
||||||
return Objects.equals(pod, that.pod);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(pod);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class WeatherInfo {
|
|
||||||
|
|
||||||
@JSONField(name = "temp")
|
|
||||||
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
|
||||||
private float temperature;
|
|
||||||
|
|
||||||
@JSONField(name = "temp_min")
|
|
||||||
// Minimum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and
|
|
||||||
// megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
|
||||||
private float minimumTemperature;
|
|
||||||
|
|
||||||
@JSONField(name = "temp_max")
|
|
||||||
// Maximum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and
|
|
||||||
// megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
|
||||||
private float maximumTemperature;
|
|
||||||
|
|
||||||
// Atmospheric pressure on the sea level by default, hPa
|
|
||||||
private float pressure;
|
|
||||||
|
|
||||||
@JSONField(name = "sea_level")
|
|
||||||
// Atmospheric pressure on the sea level, hPa
|
|
||||||
private float seaLevelPressure;
|
|
||||||
|
|
||||||
@JSONField(name = "grnd_level")
|
|
||||||
// Atmospheric pressure on the ground level, hPa
|
|
||||||
private float groundLevelPressure;
|
|
||||||
|
|
||||||
// Humidity, %
|
|
||||||
private byte humidity;
|
|
||||||
|
|
||||||
@JSONField(name = "temp_kf")
|
|
||||||
// Internal parameter
|
|
||||||
private float temperatureCoefficient;
|
|
||||||
|
|
||||||
private char temperatureUnit;
|
|
||||||
|
|
||||||
public float getTemperature() {
|
|
||||||
return temperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemperature(float temperature) {
|
|
||||||
this.temperature = temperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMinimumTemperature() {
|
|
||||||
return minimumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMinimumTemperature(float minimumTemperature) {
|
|
||||||
this.minimumTemperature = minimumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMaximumTemperature() {
|
|
||||||
return maximumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaximumTemperature(float maximumTemperature) {
|
|
||||||
this.maximumTemperature = maximumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPressure() {
|
|
||||||
return pressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPressure(float pressure) {
|
|
||||||
this.pressure = pressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getSeaLevelPressure() {
|
|
||||||
return seaLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSeaLevelPressure(float seaLevelPressure) {
|
|
||||||
this.seaLevelPressure = seaLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getGroundLevelPressure() {
|
|
||||||
return groundLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroundLevelPressure(float groundLevelPressure) {
|
|
||||||
this.groundLevelPressure = groundLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getHumidity() {
|
|
||||||
return humidity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHumidity(byte humidity) {
|
|
||||||
this.humidity = humidity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTemperatureCoefficient() {
|
|
||||||
return temperatureCoefficient;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemperatureCoefficient(float temperatureCoefficient) {
|
|
||||||
this.temperatureCoefficient = temperatureCoefficient;
|
|
||||||
}
|
|
||||||
|
|
||||||
public char getTemperatureUnit() {
|
|
||||||
return temperatureUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemperatureUnit(char temperatureUnit) {
|
|
||||||
this.temperatureUnit = temperatureUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPressureUnit() {
|
|
||||||
return "hPa";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.append("Temperature: ");
|
|
||||||
stringBuilder.append(temperature);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(temperatureUnit);
|
|
||||||
stringBuilder.append(". Minimum temperature: ");
|
|
||||||
stringBuilder.append(minimumTemperature);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(temperatureUnit);
|
|
||||||
stringBuilder.append(". Maximum temperature: ");
|
|
||||||
stringBuilder.append(maximumTemperature);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(temperatureUnit);
|
|
||||||
stringBuilder.append(". Pressure: ");
|
|
||||||
stringBuilder.append(pressure);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(getPressureUnit());
|
|
||||||
if (seaLevelPressure > 0) {
|
|
||||||
stringBuilder.append(". Sea-level pressure: ");
|
|
||||||
stringBuilder.append(seaLevelPressure);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(getPressureUnit());
|
|
||||||
}
|
|
||||||
if (groundLevelPressure > 0) {
|
|
||||||
stringBuilder.append(". Ground-level pressure: ");
|
|
||||||
stringBuilder.append(groundLevelPressure);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(getPressureUnit());
|
|
||||||
}
|
|
||||||
stringBuilder.append(". Humidity: ");
|
|
||||||
stringBuilder.append(humidity);
|
|
||||||
stringBuilder.append('%');
|
|
||||||
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
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
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(temperature, minimumTemperature, maximumTemperature, pressure, seaLevelPressure, groundLevelPressure, humidity, temperatureCoefficient);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,530 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model.response;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
|
||||||
import com.github.prominence.openweathermap.api.model.*;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class Weather implements OpenWeatherResponse {
|
|
||||||
|
|
||||||
@JSONField(name = "id")
|
|
||||||
private long cityId;
|
|
||||||
|
|
||||||
@JSONField(name = "name")
|
|
||||||
private String cityName;
|
|
||||||
|
|
||||||
@JSONField(name = "coord")
|
|
||||||
private Coordinates coordinates;
|
|
||||||
|
|
||||||
@JSONField(name = "weather")
|
|
||||||
private List<WeatherState> weatherStates;
|
|
||||||
|
|
||||||
private String base;
|
|
||||||
|
|
||||||
@JSONField(name = "main")
|
|
||||||
private WeatherInfo weatherInfo;
|
|
||||||
|
|
||||||
private Wind wind;
|
|
||||||
|
|
||||||
private Clouds clouds;
|
|
||||||
|
|
||||||
private Rain rain;
|
|
||||||
|
|
||||||
private Snow snow;
|
|
||||||
|
|
||||||
@JSONField(name = "dt")
|
|
||||||
private long dataCalculationTime;
|
|
||||||
|
|
||||||
@JSONField(name = "sys")
|
|
||||||
private WeatherSystemInfo weatherSystemInfo;
|
|
||||||
|
|
||||||
@JSONField(name = "cod")
|
|
||||||
private short responseCode;
|
|
||||||
|
|
||||||
public long getCityId() {
|
|
||||||
return cityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCityId(long cityId) {
|
|
||||||
this.cityId = cityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCityName() {
|
|
||||||
return cityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCityName(String cityName) {
|
|
||||||
this.cityName = cityName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Coordinates getCoordinates() {
|
|
||||||
return coordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCoordinates(Coordinates coordinates) {
|
|
||||||
this.coordinates = coordinates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<WeatherState> getWeatherStates() {
|
|
||||||
return weatherStates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeatherStates(List<WeatherState> weatherStates) {
|
|
||||||
this.weatherStates = weatherStates;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBase() {
|
|
||||||
return base;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBase(String base) {
|
|
||||||
this.base = base;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeatherInfo getWeatherInfo() {
|
|
||||||
return weatherInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeatherInfo(WeatherInfo weatherInfo) {
|
|
||||||
this.weatherInfo = weatherInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Wind getWind() {
|
|
||||||
return wind;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWind(Wind wind) {
|
|
||||||
this.wind = wind;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Clouds getClouds() {
|
|
||||||
return clouds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClouds(Clouds clouds) {
|
|
||||||
this.clouds = clouds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rain getRain() {
|
|
||||||
return rain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRain(Rain rain) {
|
|
||||||
this.rain = rain;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Snow getSnow() {
|
|
||||||
return snow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSnow(Snow snow) {
|
|
||||||
this.snow = snow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDataCalculationTime() {
|
|
||||||
return dataCalculationTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDataCalculationTime(long dataCalculationTime) {
|
|
||||||
this.dataCalculationTime = dataCalculationTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WeatherSystemInfo getWeatherSystemInfo() {
|
|
||||||
return weatherSystemInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWeatherSystemInfo(WeatherSystemInfo weatherSystemInfo) {
|
|
||||||
this.weatherSystemInfo = weatherSystemInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getResponseCode() {
|
|
||||||
return responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseCode(short responseCode) {
|
|
||||||
this.responseCode = responseCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCountry() {
|
|
||||||
return weatherSystemInfo.country;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWeatherDescription() {
|
|
||||||
if (weatherStates != null && weatherStates.size() > 0) {
|
|
||||||
return weatherStates.get(0).getDescription();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDataCalculationDate() {
|
|
||||||
return new Date(dataCalculationTime * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getTemperature() {
|
|
||||||
return weatherInfo.temperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public char getTemperatureUnit() {
|
|
||||||
return weatherInfo.temperatureUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getPressure() {
|
|
||||||
return weatherInfo.pressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPressureUnit() {
|
|
||||||
return weatherInfo.getPressureUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getHumidityPercentage() {
|
|
||||||
return weatherInfo.humidity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.append("City: ");
|
|
||||||
stringBuilder.append(cityName);
|
|
||||||
stringBuilder.append('(');
|
|
||||||
stringBuilder.append(cityId);
|
|
||||||
stringBuilder.append("). ");
|
|
||||||
stringBuilder.append("Coordinates: ");
|
|
||||||
stringBuilder.append(coordinates);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
stringBuilder.append(weatherSystemInfo);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
if (weatherStates.size() == 1) {
|
|
||||||
stringBuilder.append(weatherStates.get(0));
|
|
||||||
} else {
|
|
||||||
stringBuilder.append(weatherStates);
|
|
||||||
}
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
stringBuilder.append(weatherInfo);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
stringBuilder.append(wind);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
stringBuilder.append(clouds);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
if (rain != null) {
|
|
||||||
stringBuilder.append(rain);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
}
|
|
||||||
if (snow != null) {
|
|
||||||
stringBuilder.append(snow);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
}
|
|
||||||
stringBuilder.append("Data calculation time: ");
|
|
||||||
stringBuilder.append(getDataCalculationDate());
|
|
||||||
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class WeatherInfo {
|
|
||||||
@JSONField(name = "temp")
|
|
||||||
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
|
||||||
private float temperature;
|
|
||||||
|
|
||||||
@JSONField(name = "pressure")
|
|
||||||
// Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
|
|
||||||
private short pressure;
|
|
||||||
|
|
||||||
@JSONField(name = "humidity")
|
|
||||||
// Humidity, %
|
|
||||||
private byte humidity;
|
|
||||||
|
|
||||||
@JSONField(name = "temp_min")
|
|
||||||
// Minimum temperature at the moment. This is deviation from current temp that is possible for large cities
|
|
||||||
// and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
|
||||||
private float minimumTemperature;
|
|
||||||
|
|
||||||
@JSONField(name = "temp_max")
|
|
||||||
// Maximum temperature at the moment. This is deviation from current temp that is possible for large cities
|
|
||||||
// and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
|
||||||
private float maximumTemperature;
|
|
||||||
|
|
||||||
@JSONField(name = "sea_level")
|
|
||||||
// Atmospheric pressure on the sea level, hPa
|
|
||||||
private short seaLevelPressure;
|
|
||||||
|
|
||||||
@JSONField(name = "grnd_level")
|
|
||||||
// Atmospheric pressure on the ground level, hPa
|
|
||||||
private short groundLevelPressure;
|
|
||||||
|
|
||||||
private char temperatureUnit;
|
|
||||||
|
|
||||||
public float getTemperature() {
|
|
||||||
return temperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemperature(float temperature) {
|
|
||||||
this.temperature = temperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getPressure() {
|
|
||||||
return pressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPressure(short pressure) {
|
|
||||||
this.pressure = pressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getHumidity() {
|
|
||||||
return humidity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHumidity(byte humidity) {
|
|
||||||
this.humidity = humidity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMinimumTemperature() {
|
|
||||||
return minimumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMinimumTemperature(float minimumTemperature) {
|
|
||||||
this.minimumTemperature = minimumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMaximumTemperature() {
|
|
||||||
return maximumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaximumTemperature(float maximumTemperature) {
|
|
||||||
this.maximumTemperature = maximumTemperature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getSeaLevelPressure() {
|
|
||||||
return seaLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSeaLevelPressure(short seaLevelPressure) {
|
|
||||||
this.seaLevelPressure = seaLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getGroundLevelPressure() {
|
|
||||||
return groundLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroundLevelPressure(short groundLevelPressure) {
|
|
||||||
this.groundLevelPressure = groundLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public char getTemperatureUnit() {
|
|
||||||
return temperatureUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTemperatureUnit(char temperatureUnit) {
|
|
||||||
this.temperatureUnit = temperatureUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPressureUnit() {
|
|
||||||
return "hPa";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.append("Temperature: ");
|
|
||||||
stringBuilder.append(temperature);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(temperatureUnit);
|
|
||||||
stringBuilder.append(". Minimum temparature: ");
|
|
||||||
stringBuilder.append(minimumTemperature);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(temperatureUnit);
|
|
||||||
stringBuilder.append(". Maximum temperature: ");
|
|
||||||
stringBuilder.append(maximumTemperature);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(temperatureUnit);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
stringBuilder.append("Humidity: ");
|
|
||||||
stringBuilder.append(humidity);
|
|
||||||
stringBuilder.append("%");
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
stringBuilder.append("Pressure: ");
|
|
||||||
stringBuilder.append(pressure);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(getPressureUnit());
|
|
||||||
if (seaLevelPressure > 0) {
|
|
||||||
stringBuilder.append(". Sea-level pressure: ");
|
|
||||||
stringBuilder.append(seaLevelPressure);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(getPressureUnit());
|
|
||||||
}
|
|
||||||
if (groundLevelPressure > 0) {
|
|
||||||
stringBuilder.append(". Ground-level pressure: ");
|
|
||||||
stringBuilder.append(groundLevelPressure);
|
|
||||||
stringBuilder.append(' ');
|
|
||||||
stringBuilder.append(getPressureUnit());
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
WeatherInfo that = (WeatherInfo) o;
|
|
||||||
return Float.compare(that.temperature, temperature) == 0 &&
|
|
||||||
pressure == that.pressure &&
|
|
||||||
humidity == that.humidity &&
|
|
||||||
Float.compare(that.minimumTemperature, minimumTemperature) == 0 &&
|
|
||||||
Float.compare(that.maximumTemperature, maximumTemperature) == 0 &&
|
|
||||||
seaLevelPressure == that.seaLevelPressure &&
|
|
||||||
groundLevelPressure == that.groundLevelPressure;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(temperature, pressure, humidity, minimumTemperature, maximumTemperature, seaLevelPressure, groundLevelPressure);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class WeatherSystemInfo {
|
|
||||||
@JSONField(name = "type")
|
|
||||||
// Internal parameter
|
|
||||||
private short type;
|
|
||||||
|
|
||||||
@JSONField(name = "id")
|
|
||||||
// Internal parameter
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
@JSONField(name = "message")
|
|
||||||
// Internal parameter
|
|
||||||
private double message;
|
|
||||||
|
|
||||||
@JSONField(name = "country")
|
|
||||||
// Country code (GB, JP etc.)
|
|
||||||
private String country;
|
|
||||||
|
|
||||||
@JSONField(name = "sunrise")
|
|
||||||
// Sunrise time, unix, UTC
|
|
||||||
private long sunriseTimestamp;
|
|
||||||
|
|
||||||
@JSONField(name = "sunset")
|
|
||||||
// Sunset time, unix, UTC
|
|
||||||
private long sunsetTimestamp;
|
|
||||||
|
|
||||||
public short getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(short type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(double message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCountry() {
|
|
||||||
return country;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCountry(String country) {
|
|
||||||
this.country = country;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSunriseTimestamp() {
|
|
||||||
return sunriseTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSunriseTimestamp(long sunriseTimestamp) {
|
|
||||||
this.sunriseTimestamp = sunriseTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getSunriseDate() {
|
|
||||||
return new Date(sunriseTimestamp * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSunsetTimestamp() {
|
|
||||||
return sunsetTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSunsetTimestamp(long sunsetTimestamp) {
|
|
||||||
this.sunsetTimestamp = sunsetTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getSunsetDate() {
|
|
||||||
return new Date(sunsetTimestamp * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
if (country != null) {
|
|
||||||
stringBuilder.append("Country: ");
|
|
||||||
stringBuilder.append(country);
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
}
|
|
||||||
if (sunriseTimestamp > 0) {
|
|
||||||
stringBuilder.append("Sunrise: ");
|
|
||||||
stringBuilder.append(getSunriseDate());
|
|
||||||
stringBuilder.append('\n');
|
|
||||||
}
|
|
||||||
if (sunsetTimestamp > 0) {
|
|
||||||
stringBuilder.append("Sunset: ");
|
|
||||||
stringBuilder.append(getSunsetDate());
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
WeatherSystemInfo that = (WeatherSystemInfo) o;
|
|
||||||
return type == that.type &&
|
|
||||||
id == that.id &&
|
|
||||||
Double.compare(that.message, message) == 0 &&
|
|
||||||
Objects.equals(country, that.country) &&
|
|
||||||
Objects.equals(sunriseTimestamp, that.sunriseTimestamp) &&
|
|
||||||
Objects.equals(sunsetTimestamp, that.sunsetTimestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
|
|
||||||
return Objects.hash(type, id, message, country, sunriseTimestamp, sunsetTimestamp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,212 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents location information.
|
||||||
|
*/
|
||||||
|
public class Location {
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String countryCode;
|
||||||
|
|
||||||
|
private LocalDateTime sunrise;
|
||||||
|
private LocalDateTime sunset;
|
||||||
|
private ZoneOffset zoneOffset;
|
||||||
|
|
||||||
|
private Coordinate coordinate;
|
||||||
|
|
||||||
|
private Location(int id, String name) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Location} object with correctness check.
|
||||||
|
* @param id location id
|
||||||
|
* @param name location name
|
||||||
|
* @return location object
|
||||||
|
*/
|
||||||
|
public static Location withValues(int id, String name) {
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("Name must be set.");
|
||||||
|
}
|
||||||
|
return new Location(id, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns ID.
|
||||||
|
* @return location ID
|
||||||
|
*/
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location ID.
|
||||||
|
* @param id location id
|
||||||
|
*/
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location name.
|
||||||
|
* @return location name
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location name.
|
||||||
|
* @param name location name
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns country code.
|
||||||
|
* @return location country code
|
||||||
|
*/
|
||||||
|
public String getCountryCode() {
|
||||||
|
return countryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location country code.
|
||||||
|
* @param countryCode location country code
|
||||||
|
*/
|
||||||
|
public void setCountryCode(String countryCode) {
|
||||||
|
this.countryCode = countryCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location sunrise time.
|
||||||
|
* @return sunrise time
|
||||||
|
*/
|
||||||
|
public LocalDateTime getSunrise() {
|
||||||
|
return sunrise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location sunrise time.
|
||||||
|
* @param sunrise sunrise time
|
||||||
|
*/
|
||||||
|
public void setSunrise(LocalDateTime sunrise) {
|
||||||
|
this.sunrise = sunrise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location sunset time.
|
||||||
|
* @return sunset time
|
||||||
|
*/
|
||||||
|
public LocalDateTime getSunset() {
|
||||||
|
return sunset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location sunset time.
|
||||||
|
* @param sunset sunset time
|
||||||
|
*/
|
||||||
|
public void setSunset(LocalDateTime sunset) {
|
||||||
|
this.sunset = sunset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location timezone offset.
|
||||||
|
* @return timezone offset
|
||||||
|
*/
|
||||||
|
public ZoneOffset getZoneOffset() {
|
||||||
|
return zoneOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location timezone offset.
|
||||||
|
* @param zoneOffset timezone offset
|
||||||
|
*/
|
||||||
|
public void setZoneOffset(ZoneOffset zoneOffset) {
|
||||||
|
this.zoneOffset = zoneOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns location coordinates.
|
||||||
|
* @return location coordinates.
|
||||||
|
*/
|
||||||
|
public Coordinate getCoordinate() {
|
||||||
|
return coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location coordinates.
|
||||||
|
* @param coordinate location coordinates
|
||||||
|
*/
|
||||||
|
public void setCoordinate(Coordinate coordinate) {
|
||||||
|
this.coordinate = coordinate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Location)) return false;
|
||||||
|
Location location = (Location) o;
|
||||||
|
return id == location.id &&
|
||||||
|
Objects.equals(name, location.name) &&
|
||||||
|
Objects.equals(countryCode, location.countryCode) &&
|
||||||
|
Objects.equals(sunrise, location.sunrise) &&
|
||||||
|
Objects.equals(sunset, location.sunset) &&
|
||||||
|
Objects.equals(zoneOffset, location.zoneOffset) &&
|
||||||
|
Objects.equals(coordinate, location.coordinate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, countryCode, sunrise, sunset, zoneOffset, coordinate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (coordinate != null) {
|
||||||
|
stringBuilder.append(coordinate.toString());
|
||||||
|
stringBuilder.append(". ");
|
||||||
|
}
|
||||||
|
stringBuilder.append("ID: ");
|
||||||
|
stringBuilder.append(id);
|
||||||
|
stringBuilder.append(", Name: ");
|
||||||
|
stringBuilder.append(name);
|
||||||
|
if (countryCode != null) {
|
||||||
|
stringBuilder.append('(');
|
||||||
|
stringBuilder.append(countryCode);
|
||||||
|
stringBuilder.append(')');
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents rain information.
|
||||||
|
*/
|
||||||
|
public class Rain {
|
||||||
|
private static final String DEFAULT_UNIT = "mm";
|
||||||
|
|
||||||
|
private Double oneHourRainLevel;
|
||||||
|
private Double threeHourRainLevel;
|
||||||
|
|
||||||
|
private Rain() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Rain} object with correctness check.
|
||||||
|
*
|
||||||
|
* @param oneHourRainLevel 1-hour rain level value
|
||||||
|
* @return rain object.
|
||||||
|
*/
|
||||||
|
public static Rain withOneHourLevelValue(double oneHourRainLevel) {
|
||||||
|
Rain rain = new Rain();
|
||||||
|
rain.setOneHourRainLevel(oneHourRainLevel);
|
||||||
|
return rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Rain} object with correctness check.
|
||||||
|
*
|
||||||
|
* @param threeHourRainLevel 3-hour rain level value
|
||||||
|
* @return rain object.
|
||||||
|
*/
|
||||||
|
public static Rain withThreeHourLevelValue(double threeHourRainLevel) {
|
||||||
|
Rain rain = new Rain();
|
||||||
|
rain.setThreeHourRainLevel(threeHourRainLevel);
|
||||||
|
return rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Rain} object with correctness check.
|
||||||
|
*
|
||||||
|
* @param oneHourRainLevel the one hour rain level
|
||||||
|
* @param threeHourRainLevel the three hour rain level
|
||||||
|
* @return the rain
|
||||||
|
*/
|
||||||
|
public static Rain withValues(double oneHourRainLevel, double threeHourRainLevel) {
|
||||||
|
Rain rain = new Rain();
|
||||||
|
rain.setOneHourRainLevel(oneHourRainLevel);
|
||||||
|
rain.setThreeHourRainLevel(threeHourRainLevel);
|
||||||
|
return rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets one hour rain level.
|
||||||
|
*
|
||||||
|
* @return the one hour rain level
|
||||||
|
*/
|
||||||
|
public Double getOneHourRainLevel() {
|
||||||
|
return oneHourRainLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets one hour rain level.
|
||||||
|
*
|
||||||
|
* @param oneHourRainLevel the one hour rain level
|
||||||
|
*/
|
||||||
|
public void setOneHourRainLevel(double oneHourRainLevel) {
|
||||||
|
if (oneHourRainLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.oneHourRainLevel = oneHourRainLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets three hour rain level.
|
||||||
|
*
|
||||||
|
* @return the three hour rain level
|
||||||
|
*/
|
||||||
|
public Double getThreeHourRainLevel() {
|
||||||
|
return threeHourRainLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets three hour rain level.
|
||||||
|
*
|
||||||
|
* @param threeHourRainLevel the three hour rain level
|
||||||
|
*/
|
||||||
|
public void setThreeHourRainLevel(double threeHourRainLevel) {
|
||||||
|
if (threeHourRainLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.threeHourRainLevel = threeHourRainLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets unit.
|
||||||
|
*
|
||||||
|
* @return the unit
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return DEFAULT_UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Rain)) return false;
|
||||||
|
Rain rain = (Rain) o;
|
||||||
|
return Objects.equals(oneHourRainLevel, rain.oneHourRainLevel) &&
|
||||||
|
Objects.equals(threeHourRainLevel, rain.threeHourRainLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(oneHourRainLevel, threeHourRainLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder snowString = new StringBuilder();
|
||||||
|
if (oneHourRainLevel != null) {
|
||||||
|
snowString.append("1-hour rain level: ");
|
||||||
|
snowString.append(oneHourRainLevel);
|
||||||
|
snowString.append(getUnit());
|
||||||
|
}
|
||||||
|
if (threeHourRainLevel != null) {
|
||||||
|
if (oneHourRainLevel != null) {
|
||||||
|
snowString.append(", ");
|
||||||
|
}
|
||||||
|
snowString.append("3-hours rain level: ");
|
||||||
|
snowString.append(threeHourRainLevel);
|
||||||
|
snowString.append(getUnit());
|
||||||
|
}
|
||||||
|
return snowString.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents snow information.
|
||||||
|
*/
|
||||||
|
public class Snow {
|
||||||
|
private static final String DEFAULT_UNIT = "mm";
|
||||||
|
|
||||||
|
private Double oneHourSnowLevel;
|
||||||
|
private Double threeHourSnowLevel;
|
||||||
|
|
||||||
|
private Snow() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Snow} object with correctness check.
|
||||||
|
*
|
||||||
|
* @param oneHourSnowLevel 1-hour snow level value
|
||||||
|
* @return snow object.
|
||||||
|
*/
|
||||||
|
public static Snow withOneHourLevelValue(double oneHourSnowLevel) {
|
||||||
|
Snow snow = new Snow();
|
||||||
|
snow.setOneHourSnowLevel(oneHourSnowLevel);
|
||||||
|
return snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Snow} object with correctness check.
|
||||||
|
*
|
||||||
|
* @param threeHourSnowLevel 3-hour snow level value
|
||||||
|
* @return snow object.
|
||||||
|
*/
|
||||||
|
public static Snow withThreeHourLevelValue(double threeHourSnowLevel) {
|
||||||
|
Snow snow = new Snow();
|
||||||
|
snow.setThreeHourSnowLevel(threeHourSnowLevel);
|
||||||
|
return snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Snow} object with correctness check.
|
||||||
|
*
|
||||||
|
* @param oneHourSnowLevel the one hour snow level
|
||||||
|
* @param threeHourSnowLevel the three hour snow level
|
||||||
|
* @return the snow
|
||||||
|
*/
|
||||||
|
public static Snow withValues(double oneHourSnowLevel, double threeHourSnowLevel) {
|
||||||
|
Snow snow = new Snow();
|
||||||
|
snow.setOneHourSnowLevel(oneHourSnowLevel);
|
||||||
|
snow.setThreeHourSnowLevel(threeHourSnowLevel);
|
||||||
|
return snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets one hour snow level.
|
||||||
|
*
|
||||||
|
* @return the one hour snow level
|
||||||
|
*/
|
||||||
|
public Double getOneHourSnowLevel() {
|
||||||
|
return oneHourSnowLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets one hour snow level.
|
||||||
|
*
|
||||||
|
* @param oneHourSnowLevel the one hour snow level
|
||||||
|
*/
|
||||||
|
public void setOneHourSnowLevel(double oneHourSnowLevel) {
|
||||||
|
if (oneHourSnowLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.oneHourSnowLevel = oneHourSnowLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets three hour snow level.
|
||||||
|
*
|
||||||
|
* @return the three hour snow level
|
||||||
|
*/
|
||||||
|
public Double getThreeHourSnowLevel() {
|
||||||
|
return threeHourSnowLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets three hour snow level.
|
||||||
|
*
|
||||||
|
* @param threeHourSnowLevel the three hour snow level
|
||||||
|
*/
|
||||||
|
public void setThreeHourSnowLevel(double threeHourSnowLevel) {
|
||||||
|
if (threeHourSnowLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.threeHourSnowLevel = threeHourSnowLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets unit.
|
||||||
|
*
|
||||||
|
* @return the unit
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return DEFAULT_UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Snow)) return false;
|
||||||
|
Snow snow = (Snow) o;
|
||||||
|
return Objects.equals(oneHourSnowLevel, snow.oneHourSnowLevel) &&
|
||||||
|
Objects.equals(threeHourSnowLevel, snow.threeHourSnowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(oneHourSnowLevel, threeHourSnowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder snowString = new StringBuilder();
|
||||||
|
if (oneHourSnowLevel != null) {
|
||||||
|
snowString.append("1-hour snow level: ");
|
||||||
|
snowString.append(oneHourSnowLevel);
|
||||||
|
snowString.append(getUnit());
|
||||||
|
}
|
||||||
|
if (threeHourSnowLevel != null) {
|
||||||
|
if (oneHourSnowLevel != null) {
|
||||||
|
snowString.append(", ");
|
||||||
|
}
|
||||||
|
snowString.append("3-hours snow level: ");
|
||||||
|
snowString.append(threeHourSnowLevel);
|
||||||
|
snowString.append(getUnit());
|
||||||
|
}
|
||||||
|
return snowString.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,365 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents weather information.
|
||||||
|
*/
|
||||||
|
public class Weather {
|
||||||
|
private String state;
|
||||||
|
private String description;
|
||||||
|
private String weatherIconUrl;
|
||||||
|
|
||||||
|
private LocalDateTime calculatedOn;
|
||||||
|
|
||||||
|
private Temperature temperature;
|
||||||
|
private AtmosphericPressure atmosphericPressure;
|
||||||
|
private Humidity humidity;
|
||||||
|
|
||||||
|
private Wind wind;
|
||||||
|
private Rain rain;
|
||||||
|
private Snow snow;
|
||||||
|
private Clouds clouds;
|
||||||
|
|
||||||
|
private Location location;
|
||||||
|
|
||||||
|
private Weather(String state, String description) {
|
||||||
|
this.state = state;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For value weather.
|
||||||
|
*
|
||||||
|
* @param state the state
|
||||||
|
* @param description the description
|
||||||
|
* @return the weather
|
||||||
|
*/
|
||||||
|
public static Weather forValue(String state, String description) {
|
||||||
|
if (state == null) {
|
||||||
|
throw new IllegalArgumentException("State must be set.");
|
||||||
|
}
|
||||||
|
if (description == null) {
|
||||||
|
throw new IllegalArgumentException("Description must be set.");
|
||||||
|
}
|
||||||
|
return new Weather(state, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets state.
|
||||||
|
*
|
||||||
|
* @return the state
|
||||||
|
*/
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets state.
|
||||||
|
*
|
||||||
|
* @param state the state
|
||||||
|
*/
|
||||||
|
public void setState(String state) {
|
||||||
|
if (state == null) {
|
||||||
|
throw new IllegalArgumentException("State must be set.");
|
||||||
|
}
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets description.
|
||||||
|
*
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets description.
|
||||||
|
*
|
||||||
|
* @param description the description
|
||||||
|
*/
|
||||||
|
public void setDescription(String description) {
|
||||||
|
if (description == null) {
|
||||||
|
throw new IllegalArgumentException("Description must be set.");
|
||||||
|
}
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets weather icon url.
|
||||||
|
*
|
||||||
|
* @return the weather icon url
|
||||||
|
*/
|
||||||
|
public String getWeatherIconUrl() {
|
||||||
|
return weatherIconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets weather icon url.
|
||||||
|
*
|
||||||
|
* @param weatherIconUrl the weather icon url
|
||||||
|
*/
|
||||||
|
public void setWeatherIconUrl(String weatherIconUrl) {
|
||||||
|
this.weatherIconUrl = weatherIconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets calculated on.
|
||||||
|
*
|
||||||
|
* @return the calculated on
|
||||||
|
*/
|
||||||
|
public LocalDateTime getCalculatedOn() {
|
||||||
|
return calculatedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets calculated on.
|
||||||
|
*
|
||||||
|
* @param calculatedOn the calculated on
|
||||||
|
*/
|
||||||
|
public void setCalculatedOn(LocalDateTime calculatedOn) {
|
||||||
|
this.calculatedOn = calculatedOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets temperature.
|
||||||
|
*
|
||||||
|
* @return the temperature
|
||||||
|
*/
|
||||||
|
public Temperature getTemperature() {
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets temperature.
|
||||||
|
*
|
||||||
|
* @param temperature the temperature
|
||||||
|
*/
|
||||||
|
public void setTemperature(Temperature temperature) {
|
||||||
|
this.temperature = temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets atmospheric pressure.
|
||||||
|
*
|
||||||
|
* @return the atmospheric pressure
|
||||||
|
*/
|
||||||
|
public AtmosphericPressure getAtmosphericPressure() {
|
||||||
|
return atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets atmospheric pressure.
|
||||||
|
*
|
||||||
|
* @param atmosphericPressure the atmospheric pressure
|
||||||
|
*/
|
||||||
|
public void setAtmosphericPressure(AtmosphericPressure atmosphericPressure) {
|
||||||
|
this.atmosphericPressure = atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets humidity.
|
||||||
|
*
|
||||||
|
* @return the humidity
|
||||||
|
*/
|
||||||
|
public Humidity getHumidity() {
|
||||||
|
return humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets humidity.
|
||||||
|
*
|
||||||
|
* @param humidity the humidity
|
||||||
|
*/
|
||||||
|
public void setHumidity(Humidity humidity) {
|
||||||
|
this.humidity = humidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets wind.
|
||||||
|
*
|
||||||
|
* @return the wind
|
||||||
|
*/
|
||||||
|
public Wind getWind() {
|
||||||
|
return wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets wind.
|
||||||
|
*
|
||||||
|
* @param wind the wind
|
||||||
|
*/
|
||||||
|
public void setWind(Wind wind) {
|
||||||
|
this.wind = wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets rain.
|
||||||
|
*
|
||||||
|
* @return the rain
|
||||||
|
*/
|
||||||
|
public Rain getRain() {
|
||||||
|
return rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets rain.
|
||||||
|
*
|
||||||
|
* @param rain the rain
|
||||||
|
*/
|
||||||
|
public void setRain(Rain rain) {
|
||||||
|
this.rain = rain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets snow.
|
||||||
|
*
|
||||||
|
* @return the snow
|
||||||
|
*/
|
||||||
|
public Snow getSnow() {
|
||||||
|
return snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets snow.
|
||||||
|
*
|
||||||
|
* @param snow the snow
|
||||||
|
*/
|
||||||
|
public void setSnow(Snow snow) {
|
||||||
|
this.snow = snow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets clouds.
|
||||||
|
*
|
||||||
|
* @return the clouds
|
||||||
|
*/
|
||||||
|
public Clouds getClouds() {
|
||||||
|
return clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets clouds.
|
||||||
|
*
|
||||||
|
* @param clouds the clouds
|
||||||
|
*/
|
||||||
|
public void setClouds(Clouds clouds) {
|
||||||
|
this.clouds = clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets location.
|
||||||
|
*
|
||||||
|
* @return the location
|
||||||
|
*/
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location.
|
||||||
|
*
|
||||||
|
* @param location the location
|
||||||
|
*/
|
||||||
|
public void setLocation(Location location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Weather)) return false;
|
||||||
|
Weather weather = (Weather) o;
|
||||||
|
return Objects.equals(state, weather.state) &&
|
||||||
|
Objects.equals(description, weather.description) &&
|
||||||
|
Objects.equals(weatherIconUrl, weather.weatherIconUrl) &&
|
||||||
|
Objects.equals(calculatedOn, weather.calculatedOn) &&
|
||||||
|
Objects.equals(temperature, weather.temperature) &&
|
||||||
|
Objects.equals(atmosphericPressure, weather.atmosphericPressure) &&
|
||||||
|
Objects.equals(humidity, weather.humidity) &&
|
||||||
|
Objects.equals(wind, weather.wind) &&
|
||||||
|
Objects.equals(rain, weather.rain) &&
|
||||||
|
Objects.equals(snow, weather.snow) &&
|
||||||
|
Objects.equals(clouds, weather.clouds) &&
|
||||||
|
Objects.equals(location, weather.location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(state, description, weatherIconUrl, calculatedOn, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (location != null) {
|
||||||
|
stringBuilder.append("Location: ");
|
||||||
|
stringBuilder.append(location.getName());
|
||||||
|
|
||||||
|
final String countryCode = location.getCountryCode();
|
||||||
|
if (countryCode != null) {
|
||||||
|
stringBuilder.append('(');
|
||||||
|
stringBuilder.append(countryCode);
|
||||||
|
stringBuilder.append(')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stringBuilder.append(", Weather: ");
|
||||||
|
stringBuilder.append(description);
|
||||||
|
if (temperature != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(temperature.getValue());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(temperature.getUnit());
|
||||||
|
}
|
||||||
|
if (atmosphericPressure != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(atmosphericPressure.getValue());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(atmosphericPressure.getUnit());
|
||||||
|
}
|
||||||
|
if (clouds != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(clouds.toString());
|
||||||
|
}
|
||||||
|
if (rain != null && rain.getOneHourRainLevel() != null) {
|
||||||
|
stringBuilder.append(", Rain: ");
|
||||||
|
stringBuilder.append(rain.getOneHourRainLevel());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(rain.getUnit());
|
||||||
|
}
|
||||||
|
if (snow != null && snow.getOneHourSnowLevel() != null) {
|
||||||
|
stringBuilder.append(", Snow: ");
|
||||||
|
stringBuilder.append(snow.getOneHourSnowLevel());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(snow.getUnit());
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Wind.
|
||||||
|
*/
|
||||||
|
public class Wind {
|
||||||
|
private double speed;
|
||||||
|
private Double degrees;
|
||||||
|
private Double gust;
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Wind.
|
||||||
|
*
|
||||||
|
* @param speed the speed
|
||||||
|
* @param unit the unitSystem
|
||||||
|
*/
|
||||||
|
private Wind(double speed, String unit) {
|
||||||
|
this.speed = speed;
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Wind} object with correctness check.
|
||||||
|
* @param speed the speed
|
||||||
|
* @param unit the unitSystem
|
||||||
|
* @return wind object
|
||||||
|
*/
|
||||||
|
public static Wind withValue(double speed, String unit) {
|
||||||
|
if (speed < 0) {
|
||||||
|
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
|
||||||
|
}
|
||||||
|
if (unit == null) {
|
||||||
|
throw new IllegalArgumentException("Unit must be set.");
|
||||||
|
}
|
||||||
|
return new Wind(speed, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets speed.
|
||||||
|
*
|
||||||
|
* @return the speed
|
||||||
|
*/
|
||||||
|
public double getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets speed.
|
||||||
|
*
|
||||||
|
* @param speed the speed
|
||||||
|
*/
|
||||||
|
public void setSpeed(double speed) {
|
||||||
|
if (speed < 0) {
|
||||||
|
throw new IllegalArgumentException("Wind speed value must be in positive or zero.");
|
||||||
|
}
|
||||||
|
this.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets gust value.
|
||||||
|
* @return the gust
|
||||||
|
*/
|
||||||
|
public Double getGust() {
|
||||||
|
return gust;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets gust value.
|
||||||
|
* @param gust the gust.
|
||||||
|
*/
|
||||||
|
public void setGust(double gust) {
|
||||||
|
if (gust < 0) {
|
||||||
|
throw new IllegalArgumentException("Gust value must be positive or zero.");
|
||||||
|
}
|
||||||
|
this.gust = gust;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets degrees.
|
||||||
|
*
|
||||||
|
* @return the degrees
|
||||||
|
*/
|
||||||
|
public Double getDegrees() {
|
||||||
|
return degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets degrees.
|
||||||
|
*
|
||||||
|
* @param degrees the degrees
|
||||||
|
*/
|
||||||
|
public void setDegrees(double degrees) {
|
||||||
|
if (degrees < 0 || degrees > 360) {
|
||||||
|
throw new IllegalArgumentException("Wind direction value must be in [0, 360] range.");
|
||||||
|
}
|
||||||
|
this.degrees = degrees;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets unitSystem.
|
||||||
|
*
|
||||||
|
* @return the unitSystem
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets unitSystem.
|
||||||
|
*
|
||||||
|
* @param unit the unitSystem
|
||||||
|
*/
|
||||||
|
public void setUnit(String unit) {
|
||||||
|
if (unit == null) {
|
||||||
|
throw new IllegalArgumentException("Unit must be set.");
|
||||||
|
}
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Wind)) return false;
|
||||||
|
Wind wind = (Wind) o;
|
||||||
|
return Double.compare(wind.speed, speed) == 0 &&
|
||||||
|
Objects.equals(degrees, wind.degrees) &&
|
||||||
|
Objects.equals(gust, wind.gust) &&
|
||||||
|
Objects.equals(unit, wind.unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(speed, degrees, gust, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String output = "Wind speed: " + speed + " " + unit +
|
||||||
|
", degrees: " + degrees;
|
||||||
|
if (gust != null) {
|
||||||
|
output += ", Gust: " + gust + " " + unit;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-7
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,12 +20,15 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.constants;
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
public final class System {
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
private System() {}
|
/**
|
||||||
|
* The interface Async request terminator.
|
||||||
public static final String OPEN_WEATHER_API_VERSION = "2.5";
|
*
|
||||||
public static final String OPEN_WEATHER_API_URL = "http://api.openweathermap.org/data/" + OPEN_WEATHER_API_VERSION + "/";
|
* @param <T> the type parameter
|
||||||
|
* @param <S> the type parameter
|
||||||
|
*/
|
||||||
|
public interface AsyncRequestTerminator<T, S> extends RequestTerminator<CompletableFuture<T>, CompletableFuture<S>> {
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Request customizer.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
*/
|
||||||
|
public interface RequestCustomizer<T extends RequestCustomizer<?>> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customize language.
|
||||||
|
*
|
||||||
|
* @param language the language
|
||||||
|
* @return the request customizer
|
||||||
|
*/
|
||||||
|
T language(Language language);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customize unit system.
|
||||||
|
*
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
* @return the request customizer
|
||||||
|
*/
|
||||||
|
T unitSystem(UnitSystem unitSystem);
|
||||||
|
}
|
||||||
+21
-7
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,13 +20,27 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.constants;
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
public final class Accuracy {
|
/**
|
||||||
|
* The interface Request terminator.
|
||||||
|
*
|
||||||
|
* @param <T> the type parameter
|
||||||
|
* @param <S> the type parameter
|
||||||
|
*/
|
||||||
|
public interface RequestTerminator<T, S> {
|
||||||
|
|
||||||
private Accuracy() {}
|
/**
|
||||||
|
* Java object response format.
|
||||||
public static final String LIKE = "like";
|
*
|
||||||
public static final String ACCURATE = "accurate";
|
* @return the java object
|
||||||
|
*/
|
||||||
|
T asJava();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON response format.
|
||||||
|
*
|
||||||
|
* @return the JSON string
|
||||||
|
*/
|
||||||
|
S asJSON();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Request url builder.
|
||||||
|
*/
|
||||||
|
public class RequestUrlBuilder {
|
||||||
|
|
||||||
|
private static final String API_KEY_PARAM_NAME = "appid";
|
||||||
|
|
||||||
|
private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/");
|
||||||
|
private final Map<String, Object> requestParameters = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Request url builder.
|
||||||
|
*
|
||||||
|
* @param key the API key
|
||||||
|
*/
|
||||||
|
public RequestUrlBuilder(String key) {
|
||||||
|
requestParameters.put(API_KEY_PARAM_NAME, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends value.
|
||||||
|
*
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
|
public void append(String value) {
|
||||||
|
builder.append(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds request parameter.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
*/
|
||||||
|
public void addRequestParameter(String key, Object value) {
|
||||||
|
requestParameters.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies customization.
|
||||||
|
*
|
||||||
|
* @param language the language
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public void applyCustomization(Language language, UnitSystem unitSystem) {
|
||||||
|
if (language != null) {
|
||||||
|
addRequestParameter("lang", language.getValue());
|
||||||
|
}
|
||||||
|
if (unitSystem != null && unitSystem != UnitSystem.STANDARD) {
|
||||||
|
addRequestParameter("units", unitSystem.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds url string.
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public String buildUrl() {
|
||||||
|
final String joinedParameters = requestParameters.entrySet().stream()
|
||||||
|
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||||
|
.collect(Collectors.joining("&"));
|
||||||
|
builder.append('?');
|
||||||
|
builder.append(joinedParameters);
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast async request terminator interface.
|
||||||
|
*/
|
||||||
|
public interface FiveDayThreeHourStepForecastAsyncRequestTerminator extends AsyncRequestTerminator<Forecast, String> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the completable future
|
||||||
|
*/
|
||||||
|
CompletableFuture<String> asXML();
|
||||||
|
}
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async request terminator.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl implements FiveDayThreeHourStepForecastAsyncRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Forecast> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
-29
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,37 +20,34 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.constants;
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
public final class Unit {
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
|
|
||||||
private Unit() {}
|
/**
|
||||||
|
* The forecast request customizer interface.
|
||||||
|
*/
|
||||||
|
public interface FiveDayThreeHourStepForecastRequestCustomizer extends RequestCustomizer<FiveDayThreeHourStepForecastRequestCustomizer> {
|
||||||
|
|
||||||
public static final String METRIC_SYSTEM = "metric";
|
/**
|
||||||
public static final String IMPERIAL_SYSTEM = "imperial";
|
* Count customizer.
|
||||||
public static final String STANDARD_SYSTEM = "standard";
|
*
|
||||||
|
* @param numberOfTimestamps the number of timestamps
|
||||||
|
* @return forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps);
|
||||||
|
|
||||||
public static String getWindUnit(String type) {
|
/**
|
||||||
switch (type) {
|
* Retrieve forecast request terminator.
|
||||||
case IMPERIAL_SYSTEM:
|
*
|
||||||
return "miles/hour";
|
* @return forecast request terminator
|
||||||
case STANDARD_SYSTEM:
|
*/
|
||||||
case METRIC_SYSTEM:
|
FiveDayThreeHourStepForecastRequestTerminator retrieve();
|
||||||
default:
|
|
||||||
return "meter/sec";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static char getTemperatureUnit(String type) {
|
|
||||||
switch (type) {
|
|
||||||
case METRIC_SYSTEM:
|
|
||||||
return '℃';
|
|
||||||
case IMPERIAL_SYSTEM:
|
|
||||||
return '℉';
|
|
||||||
case STANDARD_SYSTEM:
|
|
||||||
default:
|
|
||||||
return 'K';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve forecast async request terminator.
|
||||||
|
*
|
||||||
|
* @return forecast async request terminator
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync();
|
||||||
}
|
}
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast request customizer.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDayThreeHourStepForecastRequestCustomizer {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
private int count = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps) {
|
||||||
|
count = numberOfTimestamps;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
urlBuilder.addRequestParameter("cnt", count);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
urlBuilder.addRequestParameter("cnt", count);
|
||||||
|
return new FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast request terminator interface.
|
||||||
|
*/
|
||||||
|
public interface FiveDayThreeHourStepForecastRequestTerminator extends RequestTerminator<Forecast, String> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the XML string
|
||||||
|
*/
|
||||||
|
String asXML();
|
||||||
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Forecast;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast request terminator.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastRequestTerminatorImpl implements FiveDayThreeHourStepForecastRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Forecast asJava() {
|
||||||
|
return new FiveDayThreeHourStepForecastResponseMapper(unitSystem).mapToForecast(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for <a href="https://openweathermap.org/forecast5">API</a> methods.
|
||||||
|
*/
|
||||||
|
public interface FiveDayThreeHourStepForecastRequester {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city name forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param cityName the city name
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city name forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param cityName the city name
|
||||||
|
* @param stateCode the state code
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city name forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param cityName the city name
|
||||||
|
* @param stateCode the state code
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city id forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param cityId the city id
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By coordinate forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param coordinate the coordinate
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By zip code and country forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param zipCode the zip code
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By zip code in USA forecast request customizer.
|
||||||
|
*
|
||||||
|
* @param zipCode the zip code
|
||||||
|
* @return the forecast request customizer
|
||||||
|
*/
|
||||||
|
FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode);
|
||||||
|
}
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The forecast requester.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastRequesterImpl implements FiveDayThreeHourStepForecastRequester {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast requester.
|
||||||
|
*
|
||||||
|
* @param apiKey the api key
|
||||||
|
*/
|
||||||
|
public FiveDayThreeHourStepForecastRequesterImpl(String apiKey) {
|
||||||
|
urlBuilder = new RequestUrlBuilder(apiKey);
|
||||||
|
urlBuilder.append("forecast");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + stateCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId) {
|
||||||
|
urlBuilder.addRequestParameter("id", cityId);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode);
|
||||||
|
return new FiveDayThreeHourStepForecastRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
+292
@@ -0,0 +1,292 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.forecast.free;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.*;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Location;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Rain;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.Snow;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Temperature;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation.
|
||||||
|
* Parameters(but the real response can differ):
|
||||||
|
* --- cod Internal parameter
|
||||||
|
* --- message Internal parameter
|
||||||
|
* --- cnt A number of timestamps returned in the API response
|
||||||
|
* --- list
|
||||||
|
* |- list.dt Time of data forecasted, unix, UTC
|
||||||
|
* |- list.main
|
||||||
|
* |- list.main.temp Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- list.main.feels_like This temperature parameter accounts for the human perception of weather. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- list.main.temp_min Minimum temperature at the moment of calculation. This is minimal forecasted temperature (within large megalopolises and urban areas), use this parameter optionally. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- list.main.temp_max Maximum temperature at the moment of calculation. This is maximal forecasted temperature (within large megalopolises and urban areas), use this parameter optionally. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- list.main.pressure Atmospheric pressure on the sea level by default, hPa
|
||||||
|
* |- list.main.sea_level Atmospheric pressure on the sea level, hPa
|
||||||
|
* |- list.main.grnd_level Atmospheric pressure on the ground level, hPa
|
||||||
|
* |- list.main.humidity Humidity, %
|
||||||
|
* |- list.main.temp_kf Internal par
|
||||||
|
* |- list.weather
|
||||||
|
* |- list.weather.id Weather condition id
|
||||||
|
* |- list.weather.main Group of weather parameters (Rain, Snow, Extreme etc.)
|
||||||
|
* |- list.weather.description Weather condition within the group. You can get the output in your language.
|
||||||
|
* |- list.weather.icon Weather icon id
|
||||||
|
* |- list.clouds
|
||||||
|
* |- list.clouds.all Cloudiness, %
|
||||||
|
* |- list.wind
|
||||||
|
* |- list.wind.speed Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||||
|
* |- list.wind.deg Wind direction, degrees (meteorological)
|
||||||
|
* |- list.visibility Average visibility, metres
|
||||||
|
* |- list.pop Probability of precipitation
|
||||||
|
* |- list.rain
|
||||||
|
* |- list.rain.3h Rain volume for last 3 hours, mm
|
||||||
|
* |- list.snow
|
||||||
|
* |- list.snow.3h Snow volume for last 3 hours
|
||||||
|
* |- list.sys
|
||||||
|
* |- list.sys.pod Part of the day (n - night, d - day)
|
||||||
|
* |- list.dt_txt Time of data forecasted, ISO, UTC
|
||||||
|
* --- city
|
||||||
|
* |- city.id City ID
|
||||||
|
* |- city.name City name
|
||||||
|
* |- city.coord
|
||||||
|
* |- city.coord.lat City geo location, latitude
|
||||||
|
* |- city.coord.lon City geo location, longitude
|
||||||
|
* |- city.country Country code (GB, JP etc.)
|
||||||
|
* |- city.timezone Shift in seconds from UTC
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastResponseMapper {
|
||||||
|
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast response mapper.
|
||||||
|
*
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public FiveDayThreeHourStepForecastResponseMapper(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps forecast response into java object.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the forecast
|
||||||
|
*/
|
||||||
|
public Forecast mapToForecast(String json) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
Forecast forecast;
|
||||||
|
try {
|
||||||
|
JsonNode root = objectMapper.readTree(json);
|
||||||
|
forecast = mapToForecast(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Forecast response");
|
||||||
|
}
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Forecast mapToForecast(JsonNode root) {
|
||||||
|
Forecast forecast = new Forecast();
|
||||||
|
forecast.setLocation(parseLocation(root.get("city")));
|
||||||
|
|
||||||
|
List<WeatherForecast> forecasts = new ArrayList<>(root.get("cnt").asInt());
|
||||||
|
|
||||||
|
JsonNode forecastListNode = root.get("list");
|
||||||
|
forecastListNode.forEach(forecastNode -> forecasts.add(parseWeatherForecast(forecastNode)));
|
||||||
|
|
||||||
|
forecast.setWeatherForecasts(forecasts);
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WeatherForecast parseWeatherForecast(JsonNode rootNode) {
|
||||||
|
JsonNode weatherNode = rootNode.get("weather").get(0);
|
||||||
|
WeatherForecast weatherForecast = WeatherForecast.forValue(
|
||||||
|
weatherNode.get("main").asText(),
|
||||||
|
weatherNode.get("description").asText()
|
||||||
|
);
|
||||||
|
weatherForecast.setWeatherIconUrl("https://openweathermap.org/img/w/" + weatherNode.get("icon").asText() + ".png");
|
||||||
|
|
||||||
|
JsonNode mainNode = rootNode.get("main");
|
||||||
|
weatherForecast.setTemperature(parseTemperature(mainNode));
|
||||||
|
weatherForecast.setAtmosphericPressure(parsePressure(mainNode));
|
||||||
|
weatherForecast.setHumidity(parseHumidity(mainNode));
|
||||||
|
weatherForecast.setClouds(parseClouds(rootNode));
|
||||||
|
weatherForecast.setWind(parseWind(rootNode));
|
||||||
|
weatherForecast.setRain(parseRain(rootNode));
|
||||||
|
weatherForecast.setSnow(parseSnow(rootNode));
|
||||||
|
|
||||||
|
JsonNode sysNode = rootNode.get("sys");
|
||||||
|
if (sysNode != null) {
|
||||||
|
weatherForecast.setDayTime("d".equals(sysNode.get("pod").asText()) ? DayTime.DAY : DayTime.NIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
weatherForecast.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(rootNode.get("dt").asLong()), TimeZone.getDefault().toZoneId()));
|
||||||
|
weatherForecast.setForecastTimeISO(rootNode.get("dt_txt").asText());
|
||||||
|
|
||||||
|
return weatherForecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Temperature parseTemperature(JsonNode rootNode) {
|
||||||
|
final double tempValue = rootNode.get("temp").asDouble();
|
||||||
|
Temperature temperature = Temperature.withValue(tempValue, unitSystem.getTemperatureUnit());
|
||||||
|
|
||||||
|
final JsonNode tempMaxNode = rootNode.get("temp_max");
|
||||||
|
if (tempMaxNode != null) {
|
||||||
|
temperature.setMaxTemperature(tempMaxNode.asDouble());
|
||||||
|
}
|
||||||
|
final JsonNode tempMinNode = rootNode.get("temp_min");
|
||||||
|
if (tempMinNode != null) {
|
||||||
|
temperature.setMinTemperature(tempMinNode.asDouble());
|
||||||
|
}
|
||||||
|
final JsonNode tempFeelsLike = rootNode.get("fells_like");
|
||||||
|
if (tempFeelsLike != null) {
|
||||||
|
temperature.setFeelsLike(tempFeelsLike.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtmosphericPressure parsePressure(JsonNode rootNode) {
|
||||||
|
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(rootNode.get("pressure").asDouble());
|
||||||
|
|
||||||
|
final JsonNode seaLevelNode = rootNode.get("sea_level");
|
||||||
|
final JsonNode groundLevelNode = rootNode.get("grnd_level");
|
||||||
|
if (seaLevelNode != null) {
|
||||||
|
atmosphericPressure.setSeaLevelValue(seaLevelNode.asDouble());
|
||||||
|
}
|
||||||
|
if (groundLevelNode != null) {
|
||||||
|
atmosphericPressure.setGroundLevelValue(groundLevelNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Humidity parseHumidity(JsonNode rootNode) {
|
||||||
|
return Humidity.withValue((byte) (rootNode.get("humidity").asInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Wind parseWind(JsonNode root) {
|
||||||
|
final JsonNode windNode = root.get("wind");
|
||||||
|
double speed = windNode.get("speed").asDouble();
|
||||||
|
|
||||||
|
Wind wind = Wind.withValue(speed, unitSystem.getWindUnit());
|
||||||
|
final JsonNode degNode = windNode.get("deg");
|
||||||
|
if (degNode != null) {
|
||||||
|
wind.setDegrees(degNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rain parseRain(JsonNode root) {
|
||||||
|
final JsonNode rainNode = root.get("rain");
|
||||||
|
if (rainNode != null) {
|
||||||
|
final JsonNode threeHourNode = rainNode.get("3h");
|
||||||
|
if (threeHourNode != null) {
|
||||||
|
return Rain.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Snow parseSnow(JsonNode root) {
|
||||||
|
final JsonNode snowNode = root.get("snow");
|
||||||
|
if (snowNode != null) {
|
||||||
|
final JsonNode threeHourNode = snowNode.get("3h");
|
||||||
|
if (threeHourNode != null) {
|
||||||
|
Rain.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Clouds parseClouds(JsonNode rootNode) {
|
||||||
|
Clouds clouds = null;
|
||||||
|
|
||||||
|
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||||
|
final JsonNode allValueNode = cloudsNode.get("all");
|
||||||
|
if (allValueNode != null) {
|
||||||
|
clouds = Clouds.withValue((byte) allValueNode.asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
return clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location parseLocation(JsonNode rootNode) {
|
||||||
|
Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
|
||||||
|
|
||||||
|
final JsonNode timezoneNode = rootNode.get("timezone");
|
||||||
|
if (timezoneNode != null) {
|
||||||
|
location.setZoneOffset(ZoneOffset.ofTotalSeconds(timezoneNode.asInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode countryNode = rootNode.get("country");
|
||||||
|
if (countryNode != null) {
|
||||||
|
location.setCountryCode(countryNode.asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode sunriseNode = rootNode.get("sunrise");
|
||||||
|
final JsonNode sunsetNode = rootNode.get("sunset");
|
||||||
|
if (sunriseNode != null) {
|
||||||
|
location.setSunrise(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunriseNode.asLong()), TimeZone.getDefault().toZoneId()));
|
||||||
|
}
|
||||||
|
if (sunsetNode != null) {
|
||||||
|
location.setSunset(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunsetNode.asLong()), TimeZone.getDefault().toZoneId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
|
if (coordNode != null) {
|
||||||
|
location.setCoordinate(parseCoordinate(coordNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode populationNode = rootNode.get("population");
|
||||||
|
if (populationNode != null) {
|
||||||
|
location.setPopulation(populationNode.asLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Coordinate parseCoordinate(JsonNode rootNode) {
|
||||||
|
JsonNode latitudeNode = rootNode.get("lat");
|
||||||
|
JsonNode longitudeNode = rootNode.get("lon");
|
||||||
|
if (latitudeNode != null && longitudeNode != null) {
|
||||||
|
return Coordinate.withValues(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for <a href="https://openweathermap.org/current">API</a> methods.
|
||||||
|
*/
|
||||||
|
public interface CurrentWeatherRequester {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single location current weather requester.
|
||||||
|
*
|
||||||
|
* @return the single location current weather requester
|
||||||
|
*/
|
||||||
|
SingleLocationCurrentWeatherRequester single();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiple locations current weather requester.
|
||||||
|
*
|
||||||
|
* @return the multiple locations current weather requester
|
||||||
|
*/
|
||||||
|
MultipleLocationsCurrentWeatherRequester multiple();
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequesterImpl;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequester;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequesterImpl;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Current weather requester.
|
||||||
|
*/
|
||||||
|
public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Current weather requester.
|
||||||
|
*
|
||||||
|
* @param apiKey the api key
|
||||||
|
*/
|
||||||
|
public CurrentWeatherRequesterImpl(String apiKey) {
|
||||||
|
urlBuilder = new RequestUrlBuilder(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleLocationCurrentWeatherRequester single() {
|
||||||
|
return new SingleLocationCurrentWeatherRequesterImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipleLocationsCurrentWeatherRequester multiple() {
|
||||||
|
return new MultipleLocationsCurrentWeatherRequesterImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
+307
@@ -0,0 +1,307 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.*;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation:
|
||||||
|
* Parameters:
|
||||||
|
* --- coord
|
||||||
|
* |- coord.lon City geo location, longitude
|
||||||
|
* |- coord.lat City geo location, latitude
|
||||||
|
* --- weather (more info Weather condition codes)
|
||||||
|
* |- weather.id Weather condition id
|
||||||
|
* |- weather.main Group of weather parameters (Rain, Snow, Extreme etc.)
|
||||||
|
* |- weather.description Weather condition within the group
|
||||||
|
* |- weather.icon Weather icon id
|
||||||
|
* --- base Internal parameter
|
||||||
|
* --- main
|
||||||
|
* |- main.temp Temperature. UnitSystem Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- main.feels_like Temperature. This temperature parameter accounts for the human perception of weather. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- main.pressure Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
|
||||||
|
* |- main.humidity Humidity, %
|
||||||
|
* |- main.temp_min Minimum temperature at the moment. This is deviation from current temp that is possible for large cities and megalopolises geographically expanded (use these parameter optionally). UnitSystem Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- main.temp_max Maximum temperature at the moment. This is deviation from current temp that is possible for large cities and megalopolises geographically expanded (use these parameter optionally). UnitSystem Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||||
|
* |- main.sea_level Atmospheric pressure on the sea level, hPa
|
||||||
|
* |- main.grnd_level Atmospheric pressure on the ground level, hPa
|
||||||
|
* --- wind
|
||||||
|
* |- wind.speed Wind speed. UnitSystem Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||||
|
* |- wind.deg Wind direction, degrees (meteorological)
|
||||||
|
* |- wind.gust Wind gust. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour
|
||||||
|
* --- clouds
|
||||||
|
* |- clouds.all Cloudiness, %
|
||||||
|
* --- rain
|
||||||
|
* |- rain.1h Rain volume for the last 1 hour, mm
|
||||||
|
* |- rain.3h Rain volume for the last 3 hours, mm
|
||||||
|
* --- snow
|
||||||
|
* |- snow.1h Snow volume for the last 1 hour, mm
|
||||||
|
* |- snow.3h Snow volume for the last 3 hours, mm
|
||||||
|
* --- dt Time of data calculation, unix, UTC
|
||||||
|
* --- sys
|
||||||
|
* |- sys.type Internal parameter
|
||||||
|
* |- sys.id Internal parameter
|
||||||
|
* |- sys.message Internal parameter
|
||||||
|
* |- sys.country Country code (GB, JP etc.)
|
||||||
|
* |- sys.sunrise Sunrise time, unix, UTC
|
||||||
|
* |- sys.sunset Sunset time, unix, UTC
|
||||||
|
* --- timezone Shift in seconds from UTC
|
||||||
|
* --- id City ID
|
||||||
|
* --- name City name
|
||||||
|
* --- cod Internal parameter
|
||||||
|
*/
|
||||||
|
public class CurrentWeatherResponseMapper {
|
||||||
|
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Current weather response mapper.
|
||||||
|
*
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public CurrentWeatherResponseMapper(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem != null ? unitSystem : UnitSystem.STANDARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets single result.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the weather object
|
||||||
|
*/
|
||||||
|
public Weather getSingle(String json) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
Weather weather;
|
||||||
|
try {
|
||||||
|
JsonNode root = objectMapper.readTree(json);
|
||||||
|
weather = getSingle(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Weather response");
|
||||||
|
}
|
||||||
|
|
||||||
|
return weather;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Weather getSingle(JsonNode rootNode) {
|
||||||
|
JsonNode weatherState = rootNode.get("weather").get(0);
|
||||||
|
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.setTemperature(parseTemperature(rootNode));
|
||||||
|
weather.setAtmosphericPressure(parsePressure(rootNode));
|
||||||
|
weather.setHumidity(parseHumidity(rootNode));
|
||||||
|
weather.setWind(parseWind(rootNode));
|
||||||
|
weather.setRain(parseRain(rootNode));
|
||||||
|
weather.setSnow(parseSnow(rootNode));
|
||||||
|
weather.setClouds(parseClouds(rootNode));
|
||||||
|
weather.setLocation(parseLocation(rootNode));
|
||||||
|
|
||||||
|
final JsonNode dtNode = rootNode.get("dt");
|
||||||
|
if (dtNode != null) {
|
||||||
|
weather.setCalculatedOn(LocalDateTime.ofInstant(Instant.ofEpochSecond(dtNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return weather;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets list of results.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the list of weathers
|
||||||
|
*/
|
||||||
|
public List<Weather> getList(String json) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
List<Weather> weatherList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
final JsonNode listNode = root.get("list");
|
||||||
|
listNode.forEach(jsonNode -> weatherList.add(getSingle(jsonNode)));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Weather response");
|
||||||
|
}
|
||||||
|
|
||||||
|
return weatherList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Temperature parseTemperature(JsonNode rootNode) {
|
||||||
|
Temperature temperature;
|
||||||
|
final JsonNode mainNode = rootNode.get("main");
|
||||||
|
|
||||||
|
final double tempValue = mainNode.get("temp").asDouble();
|
||||||
|
temperature = Temperature.withValue(tempValue, unitSystem.getTemperatureUnit());
|
||||||
|
|
||||||
|
final JsonNode feelsLikeNode = mainNode.get("feels_like");
|
||||||
|
if (feelsLikeNode != null) {
|
||||||
|
temperature.setFeelsLike(feelsLikeNode.asDouble());
|
||||||
|
}
|
||||||
|
final JsonNode tempMaxNode = mainNode.get("temp_max");
|
||||||
|
if (tempMaxNode != null) {
|
||||||
|
temperature.setMaxTemperature(tempMaxNode.asDouble());
|
||||||
|
}
|
||||||
|
final JsonNode tempMinNode = mainNode.get("temp_min");
|
||||||
|
if (tempMinNode != null) {
|
||||||
|
temperature.setMinTemperature(tempMinNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return temperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtmosphericPressure parsePressure(JsonNode rootNode) {
|
||||||
|
final JsonNode mainNode = rootNode.get("main");
|
||||||
|
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(mainNode.get("pressure").asDouble());
|
||||||
|
|
||||||
|
final JsonNode seaLevelNode = mainNode.get("sea_level");
|
||||||
|
final JsonNode groundLevelNode = mainNode.get("grnd_level");
|
||||||
|
if (seaLevelNode != null) {
|
||||||
|
atmosphericPressure.setSeaLevelValue(seaLevelNode.asDouble());
|
||||||
|
}
|
||||||
|
if (groundLevelNode != null) {
|
||||||
|
atmosphericPressure.setGroundLevelValue(groundLevelNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Humidity parseHumidity(JsonNode rootNode) {
|
||||||
|
final JsonNode mainNode = rootNode.get("main");
|
||||||
|
|
||||||
|
return Humidity.withValue((byte) (mainNode.get("humidity").asInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Wind parseWind(JsonNode rootNode) {
|
||||||
|
final JsonNode windNode = rootNode.get("wind");
|
||||||
|
double speed = windNode.get("speed").asDouble();
|
||||||
|
|
||||||
|
Wind wind = Wind.withValue(speed, unitSystem.getWindUnit());
|
||||||
|
|
||||||
|
final JsonNode degNode = windNode.get("deg");
|
||||||
|
if (degNode != null) {
|
||||||
|
wind.setDegrees(degNode.asDouble());
|
||||||
|
}
|
||||||
|
final JsonNode gustNode = windNode.get("gust");
|
||||||
|
if (gustNode != null) {
|
||||||
|
wind.setGust(gustNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return wind;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Rain parseRain(JsonNode rootNode) {
|
||||||
|
final JsonNode rainNode = rootNode.get("rain");
|
||||||
|
if (rainNode != null) {
|
||||||
|
final JsonNode oneHourNode = rainNode.get("1h");
|
||||||
|
final JsonNode threeHourNode = rainNode.get("3h");
|
||||||
|
if (oneHourNode != null && oneHourNode.isDouble() && threeHourNode != null && threeHourNode.isDouble()) {
|
||||||
|
return Rain.withValues(oneHourNode.asDouble(), threeHourNode.asDouble());
|
||||||
|
} else if (oneHourNode != null && oneHourNode.isDouble()) {
|
||||||
|
return Rain.withOneHourLevelValue(oneHourNode.asDouble());
|
||||||
|
} else if (threeHourNode != null && threeHourNode.isDouble()) {
|
||||||
|
return Rain.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Snow parseSnow(JsonNode rootNode) {
|
||||||
|
final JsonNode snowNode = rootNode.get("snow");
|
||||||
|
if (snowNode != null) {
|
||||||
|
final JsonNode oneHourNode = snowNode.get("1h");
|
||||||
|
final JsonNode threeHourNode = snowNode.get("3h");
|
||||||
|
if (oneHourNode != null && oneHourNode.isDouble() && threeHourNode != null && threeHourNode.isDouble()) {
|
||||||
|
return Snow.withValues(oneHourNode.asDouble(), threeHourNode.asDouble());
|
||||||
|
} else if (oneHourNode != null && oneHourNode.isDouble()) {
|
||||||
|
return Snow.withOneHourLevelValue(oneHourNode.asDouble());
|
||||||
|
} else if (threeHourNode != null && threeHourNode.isDouble()) {
|
||||||
|
return Snow.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Clouds parseClouds(JsonNode rootNode) {
|
||||||
|
Clouds clouds = null;
|
||||||
|
|
||||||
|
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||||
|
final JsonNode allValueNode = cloudsNode.get("all");
|
||||||
|
if (allValueNode != null) {
|
||||||
|
clouds = Clouds.withValue((byte) allValueNode.asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
return clouds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Location parseLocation(JsonNode rootNode) {
|
||||||
|
Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
|
||||||
|
|
||||||
|
final JsonNode timezoneNode = rootNode.get("timezone");
|
||||||
|
if (timezoneNode != null) {
|
||||||
|
location.setZoneOffset(ZoneOffset.ofTotalSeconds(timezoneNode.asInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode sysNode = rootNode.get("sys");
|
||||||
|
if (sysNode != null) {
|
||||||
|
final JsonNode countryNode = sysNode.get("country");
|
||||||
|
if (countryNode != null) {
|
||||||
|
location.setCountryCode(countryNode.asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode sunriseNode = sysNode.get("sunrise");
|
||||||
|
final JsonNode sunsetNode = sysNode.get("sunset");
|
||||||
|
if (sunriseNode != null) {
|
||||||
|
location.setSunrise(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunriseNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
|
}
|
||||||
|
if (sunsetNode != null) {
|
||||||
|
location.setSunset(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunsetNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
|
if (coordNode != null) {
|
||||||
|
location.setCoordinate(parseCoordinate(coordNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Coordinate parseCoordinate(JsonNode rootNode) {
|
||||||
|
JsonNode latitudeNode = rootNode.get("lat");
|
||||||
|
JsonNode longitudeNode = rootNode.get("lon");
|
||||||
|
if (latitudeNode != null && longitudeNode != null) {
|
||||||
|
return Coordinate.withValues(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Multiple locations current weather requester.
|
||||||
|
*/
|
||||||
|
public interface MultipleLocationsCurrentWeatherRequester {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By rectangle multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param rectangle the rectangle
|
||||||
|
* @param zoom the zoom
|
||||||
|
* @return the multiple result current weather request customizer
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By cities in cycle multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param point the point
|
||||||
|
* @return the multiple result cities in circle current weather request customizer
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By cities in cycle multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param point the point
|
||||||
|
* @param citiesCount the cities count
|
||||||
|
* @return the multiple result cities in circle current weather request customizer
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount);
|
||||||
|
|
||||||
|
}
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple locations current weather requester.
|
||||||
|
*/
|
||||||
|
public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsCurrentWeatherRequester {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple locations current weather requester.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
public MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom) {
|
||||||
|
String coordinates = rectangle.getFormattedRequestString() + "," + zoom;
|
||||||
|
urlBuilder.append("box/city");
|
||||||
|
urlBuilder.addRequestParameter("bbox", coordinates);
|
||||||
|
|
||||||
|
return new MultipleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount) {
|
||||||
|
urlBuilder.append("find");
|
||||||
|
urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude()));
|
||||||
|
urlBuilder.addRequestParameter("cnt", Integer.toString(citiesCount));
|
||||||
|
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point) {
|
||||||
|
urlBuilder.append("find");
|
||||||
|
urlBuilder.addRequestParameter("lat", Double.toString(point.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", Double.toString(point.getLongitude()));
|
||||||
|
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Multiple result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public interface MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
|
||||||
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the completable future
|
||||||
|
*/
|
||||||
|
CompletableFuture<String> asXML();
|
||||||
|
}
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<Weather>> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Multiple result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public interface MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @return the multiple result current weather request terminator
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve async multiple result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @return the multiple result current weather async request terminator
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Multiple result current weather request terminator.
|
||||||
|
*/
|
||||||
|
public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
|
||||||
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the XML string
|
||||||
|
*/
|
||||||
|
String asXML();
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Weather> asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Multiple result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
|
||||||
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<Weather>> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Multiple result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCurrentWeatherRequestCustomizer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @return the multiple result current weather request terminator
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestTerminator retrieve();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve async multiple result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @return the multiple result current weather async request terminator
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultipleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-15
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,21 +20,15 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api;
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
public class OpenWeatherMapManager {
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
|
|
||||||
private String authToken;
|
import java.util.List;
|
||||||
|
|
||||||
public OpenWeatherMapManager(String token) {
|
/**
|
||||||
this.authToken = token;
|
* The interface Multiple result current weather request terminator.
|
||||||
}
|
*/
|
||||||
|
public interface MultipleResultCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
|
||||||
public WeatherRequester getWeatherRequester() {
|
|
||||||
return new WeatherRequester(authToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public HourlyForecastRequester getForecastRequester() {
|
|
||||||
return new HourlyForecastRequester(authToken);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Multiple result current weather request terminator.
|
||||||
|
*/
|
||||||
|
public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Multiple result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Weather> asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(unitSystem).getList(getRawResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The interface Single location current weather requester.
|
||||||
|
*/
|
||||||
|
public interface SingleLocationCurrentWeatherRequester {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city name current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param cityName the city name
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city name current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param cityName the city name
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city name current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param cityName the city name
|
||||||
|
* @param stateCode the state code
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By city id current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param cityId the city id
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By coordinate current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param coordinate the coordinate
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By zip code and country current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param zipCode the zip code
|
||||||
|
* @param countryCode the country code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By zip code in usa current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param zipCode the zip code
|
||||||
|
* @return the single result current weather request customizer
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode);
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single location current weather requester.
|
||||||
|
*/
|
||||||
|
public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationCurrentWeatherRequester {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single location current weather requester.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
public SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
urlBuilder.append("weather");
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + countryCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("q", cityName + "," + stateCode + "," + countryCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId) {
|
||||||
|
urlBuilder.addRequestParameter("id", cityId);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate) {
|
||||||
|
urlBuilder.addRequestParameter("lat", String.valueOf(coordinate.getLatitude()));
|
||||||
|
urlBuilder.addRequestParameter("lon", String.valueOf(coordinate.getLongitude()));
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode + "," + countryCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode) {
|
||||||
|
urlBuilder.addRequestParameter("zip", zipCode);
|
||||||
|
return new SingleResultCurrentWeatherRequestCustomizerImpl(urlBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current weather async request terminator interface.
|
||||||
|
*/
|
||||||
|
public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<Weather, String> {
|
||||||
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the completable future
|
||||||
|
*/
|
||||||
|
CompletableFuture<String> asXML();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML response format.
|
||||||
|
*
|
||||||
|
* @return the completable future
|
||||||
|
*/
|
||||||
|
CompletableFuture<String> asHTML();
|
||||||
|
}
|
||||||
+77
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single result current weather async request terminator.
|
||||||
|
*/
|
||||||
|
public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single result current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Weather> asJava() {
|
||||||
|
return CompletableFuture.supplyAsync(() -> new CurrentWeatherResponseMapper(unitSystem).getSingle(getRawResponse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asJSON() {
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<String> asHTML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "html");
|
||||||
|
return CompletableFuture.supplyAsync(this::getRawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-22
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,30 +20,27 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.utils;
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
/**
|
||||||
import java.io.IOException;
|
* The current weather request customizer interface.
|
||||||
import java.io.InputStream;
|
*/
|
||||||
import java.io.InputStreamReader;
|
public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<SingleResultCurrentWeatherRequestCustomizer> {
|
||||||
|
|
||||||
public final class JsonUtils {
|
/**
|
||||||
|
* Retrieve current weather request terminator.
|
||||||
|
*
|
||||||
|
* @return the single result current weather request terminator
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestTerminator retrieve();
|
||||||
|
|
||||||
private JsonUtils() {}
|
/**
|
||||||
|
* Retrieve current weather async request terminator.
|
||||||
|
*
|
||||||
|
* @return the single result current weather async request terminator
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync();
|
||||||
|
|
||||||
public static Object parseJson(InputStream inputStream, Class clazz) throws IOException {
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
result.append(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
reader.close();
|
|
||||||
|
|
||||||
return JSON.parseObject(result.toString(), clazz);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.Language;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single result current weather request customizer.
|
||||||
|
*/
|
||||||
|
public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
|
||||||
|
private Language language;
|
||||||
|
private UnitSystem unitSystem = UnitSystem.STANDARD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single result current weather request customizer.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestTerminator retrieve() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new SingleResultCurrentWeatherRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync() {
|
||||||
|
urlBuilder.applyCustomization(language, unitSystem);
|
||||||
|
return new SingleResultCurrentWeatherAsyncRequestTerminatorImpl(urlBuilder, unitSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer language(Language language) {
|
||||||
|
this.language = language;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleResultCurrentWeatherRequestCustomizer unitSystem(UnitSystem unitSystem) {
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current weather request terminator interface.
|
||||||
|
*/
|
||||||
|
public interface SingleResultCurrentWeatherRequestTerminator extends RequestTerminator<Weather, String> {
|
||||||
|
/**
|
||||||
|
* XML response format.
|
||||||
|
*
|
||||||
|
* @return the XML string
|
||||||
|
*/
|
||||||
|
String asXML();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML response format.
|
||||||
|
*
|
||||||
|
* @return the HTML string
|
||||||
|
*/
|
||||||
|
String asHTML();
|
||||||
|
}
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.request.weather.single;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
|
||||||
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Single result current weather request terminator.
|
||||||
|
*/
|
||||||
|
public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator {
|
||||||
|
|
||||||
|
private final RequestUrlBuilder urlBuilder;
|
||||||
|
private final UnitSystem unitSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new Single result current weather request terminator.
|
||||||
|
*
|
||||||
|
* @param urlBuilder the url builder
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
|
||||||
|
this.urlBuilder = urlBuilder;
|
||||||
|
this.unitSystem = unitSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Weather asJava() {
|
||||||
|
return new CurrentWeatherResponseMapper(unitSystem).getSingle(asJSON());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asJSON() {
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asXML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "xml");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String asHTML() {
|
||||||
|
urlBuilder.addRequestParameter("mode", "html");
|
||||||
|
return getRawResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRawResponse() {
|
||||||
|
return RequestUtils.getResponse(urlBuilder.buildUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,20 +22,61 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.utils;
|
package com.github.prominence.openweathermap.api.utils;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for API calls execution.
|
||||||
|
*/
|
||||||
public final class RequestUtils {
|
public final class RequestUtils {
|
||||||
|
|
||||||
private RequestUtils() {}
|
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
||||||
|
|
||||||
public static InputStream executeGetRequest(URL requestUrl) throws InvalidAuthTokenException, DataNotFoundException {
|
private RequestUtils() {
|
||||||
InputStream resultStream = null;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
||||||
|
*
|
||||||
|
* @param url the url to make API request.
|
||||||
|
* @return response from the request in <code>String</code> representation.
|
||||||
|
* @throws IllegalArgumentException in case if provided parameter isn't a valid url for {@link URL} instance.
|
||||||
|
*/
|
||||||
|
public static String getResponse(String url) {
|
||||||
|
URL requestUrl;
|
||||||
|
try {
|
||||||
|
requestUrl = new URL(url);
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
logger.error("Invalid URL: ", ex);
|
||||||
|
throw new IllegalArgumentException(ex);
|
||||||
|
}
|
||||||
|
logger.debug("Executing OpenWeatherMap API request: " + url);
|
||||||
|
final InputStream requestInputStream = executeRequest(requestUrl);
|
||||||
|
|
||||||
|
return convertInputStreamToString(requestInputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes call to provided API url and retrieves response as an <code>InputStream</code> instance.
|
||||||
|
*
|
||||||
|
* @param requestUrl url for API call execution.
|
||||||
|
* @return <code>InputStream</code> instance containing http response body.
|
||||||
|
* @throws InvalidAuthTokenException in case if authentication token wasn't set or requested functionality is not permitted for its subscription plan.
|
||||||
|
* @throws NoDataFoundException in case if there is no any data for requested location(s) or request is invalid.
|
||||||
|
*/
|
||||||
|
private static InputStream executeRequest(URL requestUrl) {
|
||||||
|
InputStream resultStream;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
|
||||||
@@ -48,13 +89,39 @@ public final class RequestUtils {
|
|||||||
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
||||||
throw new InvalidAuthTokenException();
|
throw new InvalidAuthTokenException();
|
||||||
case HttpURLConnection.HTTP_NOT_FOUND:
|
case HttpURLConnection.HTTP_NOT_FOUND:
|
||||||
throw new DataNotFoundException();
|
case HttpURLConnection.HTTP_BAD_REQUEST:
|
||||||
|
throw new NoDataFoundException();
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unexpected value: " + connection.getResponseCode());
|
||||||
}
|
}
|
||||||
} catch (IOException | ClassCastException ex) {
|
} catch (IllegalStateException | IOException ex) {
|
||||||
ex.printStackTrace();
|
logger.error("An error occurred during OpenWeatherMap API response parsing: ", ex);
|
||||||
|
throw new NoDataFoundException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultStream;
|
return resultStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the input stream line-by-line and returns its content in <code>String</code> representation.
|
||||||
|
*
|
||||||
|
* @param inputStream input stream to convert.
|
||||||
|
* @return converted <code>InputStream</code> content.
|
||||||
|
* @throws IllegalArgumentException in case if input stream is unable to be read.
|
||||||
|
*/
|
||||||
|
private static String convertInputStreamToString(InputStream inputStream) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logger.error("Error during response reading: ", ex);
|
||||||
|
throw new IllegalArgumentException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,12 +22,19 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api;
|
package com.github.prominence.openweathermap.api;
|
||||||
|
|
||||||
abstract class AuthenticationTokenBasedRequester {
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
protected String authToken;
|
public class ApiTest {
|
||||||
|
|
||||||
protected AuthenticationTokenBasedRequester(String authToken) {
|
private static OpenWeatherMapClient manager;
|
||||||
this.authToken = authToken;
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void retrieveApiKey() {
|
||||||
|
String apiKey = System.getenv("OPENWEATHER_API_KEY");
|
||||||
|
manager = new OpenWeatherMapClient(apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static OpenWeatherMapClient getClient() {
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+148
@@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AtmosphericPressureUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreatePressureWithArgs_thenValueIsSet() {
|
||||||
|
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(100);
|
||||||
|
Assert.assertEquals(100, atmosphericPressure.getValue(), 0.00001);
|
||||||
|
|
||||||
|
Assert.assertEquals(0, AtmosphericPressure.withValue(0).getValue(), 0.00001);
|
||||||
|
Assert.assertEquals(100, AtmosphericPressure.withValue(100).getValue(), 0.00001);
|
||||||
|
Assert.assertEquals(55, AtmosphericPressure.withValue(55).getValue(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||||
|
AtmosphericPressure one = AtmosphericPressure.withValue(22);
|
||||||
|
AtmosphericPressure two = AtmosphericPressure.withValue(22);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
|
||||||
|
one.setSeaLevelValue(333);
|
||||||
|
one.setGroundLevelValue(555);
|
||||||
|
|
||||||
|
two.setSeaLevelValue(333);
|
||||||
|
two.setGroundLevelValue(555);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
Assert.assertTrue(two.equals(one));
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||||
|
AtmosphericPressure one = AtmosphericPressure.withValue(5);
|
||||||
|
AtmosphericPressure two = AtmosphericPressure.withValue(88);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
Assert.assertFalse(two.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
Assert.assertNotEquals(one.hashCode(), two.hashCode());
|
||||||
|
|
||||||
|
one = AtmosphericPressure.withValue(44);
|
||||||
|
one.setSeaLevelValue(44);
|
||||||
|
two = AtmosphericPressure.withValue(44);
|
||||||
|
two.setGroundLevelValue(22);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
Assert.assertFalse(two.equals(one));
|
||||||
|
|
||||||
|
two.setSeaLevelValue(44);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
Assert.assertFalse(two.equals(one));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValidValues_thenAllIsFine() {
|
||||||
|
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(14);
|
||||||
|
atmosphericPressure.setValue(0);
|
||||||
|
atmosphericPressure.setValue(15);
|
||||||
|
atmosphericPressure.setValue(100);
|
||||||
|
|
||||||
|
atmosphericPressure.setGroundLevelValue(222);
|
||||||
|
Assert.assertEquals(222, atmosphericPressure.getGroundLevelValue(), 0.00001);
|
||||||
|
|
||||||
|
atmosphericPressure.setSeaLevelValue(4232);
|
||||||
|
Assert.assertEquals(4232, atmosphericPressure.getSeaLevelValue(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final String pressureString = AtmosphericPressure.withValue(44).toString();
|
||||||
|
Assert.assertNotNull(pressureString);
|
||||||
|
Assert.assertNotEquals("", pressureString);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreatePressureByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||||
|
AtmosphericPressure.withValue(-33);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreatePressureAndSetInvalidDataNegative_thenThrowAnException() {
|
||||||
|
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
|
||||||
|
atmosphericPressure.setValue(-89);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidSeaLevelPressure_thenThrowAnException() {
|
||||||
|
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
|
||||||
|
atmosphericPressure.setSeaLevelValue(-89);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidGroundLevelPressure_thenThrowAnException() {
|
||||||
|
AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88);
|
||||||
|
atmosphericPressure.setGroundLevelValue(-223);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CloudsUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateCloudsWithValidArgs_thenValueIsSet() {
|
||||||
|
Clouds clouds = Clouds.withValue((byte) 100);
|
||||||
|
Assert.assertEquals(100, clouds.getValue());
|
||||||
|
|
||||||
|
Assert.assertEquals(0, Clouds.withValue((byte) 0).getValue());
|
||||||
|
Assert.assertEquals(100, Clouds.withValue((byte) 100).getValue());
|
||||||
|
Assert.assertEquals(55, Clouds.withValue((byte) 55).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCloudsByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
|
||||||
|
Clouds.withValue((byte) 110);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCloudsByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||||
|
Clouds.withValue((byte) -33);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValidValues_thenAllIsFine() {
|
||||||
|
Clouds clouds = Clouds.withValue((byte) 14);
|
||||||
|
clouds.setValue((byte) 0);
|
||||||
|
Assert.assertEquals(0, clouds.getValue());
|
||||||
|
clouds.setValue((byte) 15);
|
||||||
|
Assert.assertEquals(15, clouds.getValue());
|
||||||
|
clouds.setValue((byte) 100);
|
||||||
|
Assert.assertEquals(100, clouds.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCloudsAndSetInvalidDataAboveHundred_thenThrowAnException() {
|
||||||
|
Clouds clouds = Clouds.withValue((byte) 12);
|
||||||
|
clouds.setValue((byte) 112);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCloudsAndSetInvalidDataNegative_thenThrowAnException() {
|
||||||
|
Clouds clouds = Clouds.withValue((byte) 88);
|
||||||
|
clouds.setValue((byte) -89);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||||
|
Clouds one = Clouds.withValue((byte) 22);
|
||||||
|
Clouds two = Clouds.withValue((byte) 22);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||||
|
Clouds one = Clouds.withValue((byte) 5);
|
||||||
|
Clouds two = Clouds.withValue((byte) 88);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
Assert.assertFalse(two.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
Assert.assertNotEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final String cloudsString = Clouds.withValue((byte) 44).toString();
|
||||||
|
Assert.assertNotNull(cloudsString);
|
||||||
|
Assert.assertNotEquals("", cloudsString);
|
||||||
|
}
|
||||||
|
}
|
||||||
+170
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CoordinateRectangleUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||||
|
CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLatitudeBottomBelowMinus90_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(44.5, -91.2, 54.4, 22.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLatitudeBottomAbove90_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(44.5, 91.2, 54.4, 22.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLatitudeTopBelowMinus90_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(44.5, 22.4, 54.4, -92.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLatitudeTopAbove90_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(44.5, 22.5, 54.4, 94.887);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLongitudeLeftBelowMinus180_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(-944.5, 22.4, 54.4, 22.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLongitudeLeftAbove180_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(544.5, 22.4, 54.4, 22.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLongitudeRightBelowMinus180_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(44.5, 22.4, -254.4, 22.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithLongitudeRightAbove180_thenThrowAnException() {
|
||||||
|
CoordinateRectangle.withValues(44.5, 22.4, 354.4, 22.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectUsingBuilderWithInvalidLatitudeBottom_thenFail() {
|
||||||
|
new CoordinateRectangle.Builder()
|
||||||
|
.setLatitudeBottom(-1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectUsingBuilderWithInvalidLatitudeTop_thenFail() {
|
||||||
|
new CoordinateRectangle.Builder()
|
||||||
|
.setLatitudeTop(-1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectUsingBuilderWithInvalidLongitudeLeft_thenFail() {
|
||||||
|
new CoordinateRectangle.Builder()
|
||||||
|
.setLongitudeLeft(-1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectUsingBuilderWithInvalidLongitudeRight_thenFail() {
|
||||||
|
new CoordinateRectangle.Builder()
|
||||||
|
.setLongitudeRight(-1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet_thenFail() {
|
||||||
|
new CoordinateRectangle.Builder()
|
||||||
|
.setLongitudeRight(10)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreateObjectUsingBuilderWithCorrectUsage_thenOk() {
|
||||||
|
new CoordinateRectangle.Builder()
|
||||||
|
.setLongitudeRight(10)
|
||||||
|
.setLongitudeLeft(10)
|
||||||
|
.setLatitudeTop(10)
|
||||||
|
.setLatitudeBottom(10)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetAllParameters_thenAllIsFine() {
|
||||||
|
final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
|
||||||
|
Assert.assertEquals(44.5, rectangle.getLongitudeLeft(), 0.00001);
|
||||||
|
Assert.assertEquals(22.4, rectangle.getLatitudeBottom(), 0.00001);
|
||||||
|
Assert.assertEquals(54.4, rectangle.getLongitudeRight(), 0.00001);
|
||||||
|
Assert.assertEquals(22.2, rectangle.getLatitudeTop(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
|
||||||
|
|
||||||
|
Assert.assertNotNull(rectangle.toString());
|
||||||
|
Assert.assertNotEquals("", rectangle.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
|
||||||
|
final CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
final CoordinateRectangle third = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 23.566);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), third.hashCode());
|
||||||
|
Assert.assertNotEquals(second.hashCode(), third.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
|
||||||
|
CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
Assert.assertTrue(first.equals(first));
|
||||||
|
Assert.assertFalse(first.equals(new Object()));
|
||||||
|
|
||||||
|
first = CoordinateRectangle.withValues(49.5, 22.4, 54.4, 22.2);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
first = CoordinateRectangle.withValues(44.5, 29.4, 54.4, 22.2);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
first = CoordinateRectangle.withValues(44.5, 22.4, 24.4, 22.2);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, -2.2);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CoordinateUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateCoordinateWithValidValues_thenObjectCreated() {
|
||||||
|
Coordinate.withValues(44, 53);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCoordinateWithInvalidLatitudeBelowMinus90_thenThrowAnException() {
|
||||||
|
Coordinate.withValues(-333, 44);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCoordinateWithInvalidLatitudeAbove90_thenThrowAnException() {
|
||||||
|
Coordinate.withValues(223, 44);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCoordinateWithInvalidLongitudeBelowMinus180_thenThrowAnException() {
|
||||||
|
Coordinate.withValues(33, -999);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateCoordinateWithInvalidLongitudeAbove180_thenThrowAnException() {
|
||||||
|
Coordinate.withValues(33, 999);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValidCoordinates_thenAllIsFine() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
|
||||||
|
coordinate.setLatitude(-90);
|
||||||
|
Assert.assertEquals(-90, coordinate.getLatitude(), 0.00001);
|
||||||
|
coordinate.setLatitude(90);
|
||||||
|
Assert.assertEquals(90, coordinate.getLatitude(), 0.00001);
|
||||||
|
coordinate.setLatitude(44);
|
||||||
|
Assert.assertEquals(44, coordinate.getLatitude(), 0.00001);
|
||||||
|
|
||||||
|
coordinate.setLongitude(-180);
|
||||||
|
Assert.assertEquals(-180, coordinate.getLongitude(), 0.00001);
|
||||||
|
coordinate.setLongitude(180);
|
||||||
|
Assert.assertEquals(180, coordinate.getLongitude(), 0.00001);
|
||||||
|
coordinate.setLongitude(130);
|
||||||
|
Assert.assertEquals(130, coordinate.getLongitude(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidLatitudeBelowMinus90_thenThrowAnException() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
coordinate.setLatitude(-91);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidLatitudeAbove90_thenThrowAnException() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
coordinate.setLatitude(92);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidLongitudeBelowMinus180_thenThrowAnException() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
coordinate.setLongitude(-194);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidLongitudeAbove180_thenThrowAnException() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
coordinate.setLongitude(444);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetLatitude_thenAllIsFine() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
Assert.assertEquals(0, coordinate.getLatitude(), 0.00001);
|
||||||
|
|
||||||
|
coordinate.setLatitude(45);
|
||||||
|
|
||||||
|
Assert.assertEquals(45, coordinate.getLatitude(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetLongitude_thenAllIsFine() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
Assert.assertEquals(0, coordinate.getLongitude(), 0.00001);
|
||||||
|
|
||||||
|
coordinate.setLongitude(33);
|
||||||
|
|
||||||
|
Assert.assertEquals(33, coordinate.getLongitude(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(0, 0);
|
||||||
|
Assert.assertNotNull(coordinate.toString());
|
||||||
|
Assert.assertNotEquals("", coordinate.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final Coordinate first = Coordinate.withValues(22, 66);
|
||||||
|
final Coordinate second = Coordinate.withValues(22, 44);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
second.setLongitude(66);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
second.setLatitude(89);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
first.setLatitude(89);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final Coordinate first = Coordinate.withValues(11, 99);
|
||||||
|
final Coordinate second = Coordinate.withValues(11, 99);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
Assert.assertTrue(first.equals(first));
|
||||||
|
Assert.assertFalse(first.equals(new Object()));
|
||||||
|
|
||||||
|
first.setLatitude(34);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
second.setLatitude(34);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
|
||||||
|
second.setLongitude(74);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
first.setLongitude(74);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-7
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Alexey Zinchenko
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,11 +22,13 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
public interface OpenWeatherResponse {
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
String getCityName();
|
public class DayTimeUnitTest {
|
||||||
long getCityId();
|
@Test
|
||||||
String getCountry();
|
public void whenGetValue_thenValueIsPresentAndValid() {
|
||||||
Coordinates getCoordinates();
|
Assert.assertEquals("d", DayTime.DAY.getValue());
|
||||||
short getResponseCode();
|
Assert.assertEquals("n", DayTime.NIGHT.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HumidityUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateHumidityWithArgs_thenValueIsSet() {
|
||||||
|
Humidity humidity = Humidity.withValue((byte) 100);
|
||||||
|
Assert.assertEquals(100, humidity.getValue());
|
||||||
|
|
||||||
|
Assert.assertEquals(0, Humidity.withValue((byte) 0).getValue());
|
||||||
|
Assert.assertEquals(55, Humidity.withValue((byte) 55).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateHumidityByConstructorWithInvalidDataAboveHundred_thenThrowAnException() {
|
||||||
|
Humidity.withValue((byte) 112);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateHumidityByConstructorWithInvalidDataNegative_thenThrowAnException() {
|
||||||
|
Humidity.withValue((byte) -33);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValidValues_thenAllIsFine() {
|
||||||
|
Humidity humidity = Humidity.withValue((byte) 14);
|
||||||
|
Assert.assertEquals(14, humidity.getValue());
|
||||||
|
humidity.setValue((byte) 0);
|
||||||
|
Assert.assertEquals(0, humidity.getValue());
|
||||||
|
humidity.setValue((byte) 15);
|
||||||
|
Assert.assertEquals(15, humidity.getValue());
|
||||||
|
humidity.setValue((byte) 100);
|
||||||
|
Assert.assertEquals(100, humidity.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateHumidityAndSetInvalidDataAboveHundred_thenThrowAnException() {
|
||||||
|
Humidity humidity = Humidity.withValue((byte) 12);
|
||||||
|
humidity.setValue((byte) 112);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateHumidityAndSetInvalidDataNegative_thenThrowAnException() {
|
||||||
|
Humidity humidity = Humidity.withValue((byte) 88);
|
||||||
|
humidity.setValue((byte) -89);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() {
|
||||||
|
Humidity one = Humidity.withValue((byte) 22);
|
||||||
|
Humidity two = Humidity.withValue((byte) 22);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() {
|
||||||
|
Humidity one = Humidity.withValue((byte) 5);
|
||||||
|
Humidity two = Humidity.withValue((byte) 88);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
Assert.assertFalse(two.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
Assert.assertNotEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final String humidityString = Humidity.withValue((byte) 44).toString();
|
||||||
|
Assert.assertNotNull(humidityString);
|
||||||
|
Assert.assertNotEquals("", humidityString);
|
||||||
|
}
|
||||||
|
}
|
||||||
+174
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TemperatureUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||||
|
Temperature.withValue(22.2, "K");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithEmptyUnit_thenThrowAnException() {
|
||||||
|
Temperature.withValue(22.2, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValue_thenAllIsFine() {
|
||||||
|
final Temperature temperature = Temperature.withValue(22.2, "K");
|
||||||
|
temperature.setValue(55.44);
|
||||||
|
|
||||||
|
Assert.assertEquals(55.44, temperature.getValue(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetMaximumTemperature_thenAllIsOk() {
|
||||||
|
final Temperature temperature = Temperature.withValue(22.2, "K");
|
||||||
|
temperature.setMaxTemperature(44.4);
|
||||||
|
|
||||||
|
Assert.assertEquals(44.4, temperature.getMaxTemperature(), 0.00001);
|
||||||
|
|
||||||
|
temperature.setMaxTemperature(null);
|
||||||
|
|
||||||
|
Assert.assertNull(temperature.getMaxTemperature());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetMinimumTemperature_thenAllIsOk() {
|
||||||
|
final Temperature temperature = Temperature.withValue(22.2, "K");
|
||||||
|
temperature.setMinTemperature(33.2);
|
||||||
|
|
||||||
|
Assert.assertEquals(33.2, temperature.getMinTemperature(), 0.00001);
|
||||||
|
|
||||||
|
temperature.setMinTemperature(null);
|
||||||
|
|
||||||
|
Assert.assertNull(temperature.getMinTemperature());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetFeelsLikeTemperature_thenAllIsOk() {
|
||||||
|
final Temperature temperature = Temperature.withValue(22.2, "K");
|
||||||
|
temperature.setFeelsLike(22.3);
|
||||||
|
|
||||||
|
Assert.assertEquals(22.3, temperature.getFeelsLike(), 0.00001);
|
||||||
|
|
||||||
|
temperature.setFeelsLike(null);
|
||||||
|
|
||||||
|
Assert.assertNull(temperature.getFeelsLike());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetNonNullUnit_thenAllIsOk() {
|
||||||
|
final Temperature temperature = Temperature.withValue(22.2, "K");
|
||||||
|
temperature.setUnit("test");
|
||||||
|
|
||||||
|
Assert.assertTrue("test".equals(temperature.getUnit()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetNullUnit_thenThrowAnException() {
|
||||||
|
final Temperature temperature = Temperature.withValue(22.2, "K");
|
||||||
|
|
||||||
|
temperature.setUnit(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final Temperature temperature = Temperature.withValue(22.2, "K");
|
||||||
|
|
||||||
|
Assert.assertNotNull(temperature.toString());
|
||||||
|
Assert.assertNotEquals("", temperature.toString());
|
||||||
|
|
||||||
|
temperature.setMinTemperature(11.2);
|
||||||
|
|
||||||
|
Assert.assertNotNull(temperature.toString());
|
||||||
|
Assert.assertNotEquals("", temperature.toString());
|
||||||
|
|
||||||
|
temperature.setMaxTemperature(44.3);
|
||||||
|
|
||||||
|
Assert.assertNotNull(temperature.toString());
|
||||||
|
Assert.assertNotEquals("", temperature.toString());
|
||||||
|
|
||||||
|
temperature.setFeelsLike(22.4);
|
||||||
|
|
||||||
|
Assert.assertNotNull(temperature.toString());
|
||||||
|
Assert.assertNotEquals("", temperature.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final Temperature one = Temperature.withValue(22.2, "K");
|
||||||
|
final Temperature two = Temperature.withValue(22.2, "K");
|
||||||
|
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final Temperature one = Temperature.withValue(22.2, "K");
|
||||||
|
final Temperature two = Temperature.withValue(21.2, "K");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
one.setValue(21.2);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setMaxTemperature(33.56);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setMaxTemperature(33.56);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setMinTemperature(11.54);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setMinTemperature(11.54);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
two.setUnit("U");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
one.setUnit("U");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setFeelsLike(22.3);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setFeelsLike(22.3);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
}
|
||||||
|
}
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ForecastUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenLocationIsSet_thenAllIsOk() {
|
||||||
|
final Forecast forecast = new Forecast();
|
||||||
|
forecast.setLocation(Location.withValues(2, "asd"));
|
||||||
|
|
||||||
|
Assert.assertNotNull(forecast.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenWeatherForecastsAreSet_thenAllIsOk() {
|
||||||
|
final Forecast forecast = new Forecast();
|
||||||
|
forecast.setWeatherForecasts(new ArrayList<>());
|
||||||
|
|
||||||
|
Assert.assertNotNull(forecast.getWeatherForecasts());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCalculateHashCode_thenAllIsOk() {
|
||||||
|
final Forecast one = new Forecast();
|
||||||
|
final Forecast two = new Forecast();
|
||||||
|
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
|
||||||
|
one.setLocation(Location.withValues(22, "444"));
|
||||||
|
|
||||||
|
Assert.assertNotEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsOk() {
|
||||||
|
final Forecast one = new Forecast();
|
||||||
|
final Forecast two = new Forecast();
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(null));
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
|
||||||
|
one.setLocation(Location.withValues(22, "234"));
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setLocation(one.getLocation());
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setWeatherForecasts(new ArrayList<>());
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
}
|
||||||
|
}
|
||||||
+221
@@ -0,0 +1,221 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
|
public class LocationUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||||
|
Location.withValues(33, "test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithoutName_thenThrowAnException() {
|
||||||
|
Location.withValues(33, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetId_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
location.setId(55);
|
||||||
|
|
||||||
|
Assert.assertEquals(55, location.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetName_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
location.setName("city");
|
||||||
|
|
||||||
|
Assert.assertEquals("city", location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetCountryCode_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
location.setCountryCode("by");
|
||||||
|
|
||||||
|
Assert.assertEquals("by", location.getCountryCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetSunrise_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
location.setSunrise(now);
|
||||||
|
|
||||||
|
Assert.assertEquals(now, location.getSunrise());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetSunset_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
location.setSunset(now);
|
||||||
|
|
||||||
|
Assert.assertEquals(now, location.getSunset());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetZoneOffset_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final ZoneOffset offset = ZoneOffset.UTC;
|
||||||
|
location.setZoneOffset(offset);
|
||||||
|
|
||||||
|
Assert.assertEquals(offset, location.getZoneOffset());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetCoordinate_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
|
||||||
|
location.setCoordinate(coordinate);
|
||||||
|
|
||||||
|
Assert.assertEquals(coordinate, location.getCoordinate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetPopulation_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
location.setPopulation(3444L);
|
||||||
|
|
||||||
|
Assert.assertEquals(3444L, location.getPopulation().longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final Location location = Location.withValues(44, "test");
|
||||||
|
|
||||||
|
Assert.assertNotEquals("", location.toString());
|
||||||
|
|
||||||
|
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
|
||||||
|
|
||||||
|
Assert.assertNotEquals("", location.toString());
|
||||||
|
|
||||||
|
location.setCountryCode("TN");
|
||||||
|
|
||||||
|
Assert.assertNotEquals("", location.toString());
|
||||||
|
Assert.assertNotNull(location.toString());
|
||||||
|
|
||||||
|
location.setPopulation(34343L);
|
||||||
|
Assert.assertNotEquals("", location.toString());
|
||||||
|
Assert.assertNotNull(location.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final Location one = Location.withValues(44, "test");
|
||||||
|
final Location two = Location.withValues(44, "test");
|
||||||
|
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
|
||||||
|
two.setName("112");
|
||||||
|
|
||||||
|
Assert.assertNotEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final Location one = Location.withValues(44, "test");
|
||||||
|
final Location two = Location.withValues(44, "test");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
two.setId(23);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
one.setId(23);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setName("23");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setName("23");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setCountryCode("11");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setCountryCode("11");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
one.setSunrise(now);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setSunrise(now);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setSunset(now);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setSunset(now);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setZoneOffset(ZoneOffset.UTC);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setZoneOffset(ZoneOffset.UTC);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
|
||||||
|
|
||||||
|
one.setCoordinate(coordinate);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setCoordinate(coordinate);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setPopulation(20000L);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setPopulation(20000L);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
}
|
||||||
|
}
|
||||||
+98
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class RainUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateRainWithValidArgs_thenObjectIsCreated() {
|
||||||
|
Rain.withThreeHourLevelValue(2222.3);
|
||||||
|
Rain.withThreeHourLevelValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateWithInvalidData_thenFail() {
|
||||||
|
Rain.withThreeHourLevelValue(-20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValues_thenTheyAreSet() {
|
||||||
|
final Rain rain = Rain.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
Assert.assertEquals(0, rain.getThreeHourRainLevel(), 0.00001);
|
||||||
|
|
||||||
|
rain.setThreeHourRainLevel(55.5);
|
||||||
|
Assert.assertEquals(55.5, rain.getThreeHourRainLevel(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidValue_thenFail() {
|
||||||
|
final Rain rain = Rain.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
rain.setThreeHourRainLevel(-20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final Rain rain = Rain.withThreeHourLevelValue(33.5);
|
||||||
|
|
||||||
|
Assert.assertNotNull(rain.toString());
|
||||||
|
Assert.assertNotEquals("", rain.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final Rain first = Rain.withThreeHourLevelValue(0);
|
||||||
|
final Rain second = Rain.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
second.setThreeHourRainLevel(11.0);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
first.setThreeHourRainLevel(11.0);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final Rain first = Rain.withThreeHourLevelValue(0);
|
||||||
|
final Rain second = Rain.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
Assert.assertTrue(first.equals(first));
|
||||||
|
Assert.assertFalse(first.equals(new Object()));
|
||||||
|
|
||||||
|
second.setThreeHourRainLevel(66.7);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
first.setThreeHourRainLevel(66.7);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
}
|
||||||
|
}
|
||||||
+97
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class SnowUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateSnowWithValidArgs_ObjectIsCreated() {
|
||||||
|
Snow.withThreeHourLevelValue(2222.3);
|
||||||
|
Snow.withThreeHourLevelValue(0);
|
||||||
|
}
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateWithInvalidData_thenFail() {
|
||||||
|
Snow.withThreeHourLevelValue(-20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValues_thenTheyAreSet() {
|
||||||
|
final Snow snow = Snow.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
Assert.assertEquals(0, snow.getThreeHourSnowLevel(), 0.00001);
|
||||||
|
|
||||||
|
snow.setThreeHourSnowLevel(55.5);
|
||||||
|
Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidValue_thenFail() {
|
||||||
|
final Snow snow = Snow.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
snow.setThreeHourSnowLevel(-20);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final Snow snow = Snow.withThreeHourLevelValue(33.5);
|
||||||
|
|
||||||
|
Assert.assertNotNull(snow.toString());
|
||||||
|
Assert.assertNotEquals("", snow.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final Snow first = Snow.withThreeHourLevelValue(0);
|
||||||
|
final Snow second = Snow.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
second.setThreeHourSnowLevel(11.0);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
first.setThreeHourSnowLevel(11.0);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final Snow first = Snow.withThreeHourLevelValue(0);
|
||||||
|
final Snow second = Snow.withThreeHourLevelValue(0);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
Assert.assertTrue(first.equals(first));
|
||||||
|
Assert.assertFalse(first.equals(new Object()));
|
||||||
|
|
||||||
|
second.setThreeHourSnowLevel(66.7);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
first.setThreeHourSnowLevel(66.7);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
}
|
||||||
|
}
|
||||||
+361
@@ -0,0 +1,361 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class WeatherForecastUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||||
|
WeatherForecast.forValue("state", "desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithoutState_thenThrowAnException() {
|
||||||
|
WeatherForecast.forValue(null, "desc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithoutDescription_thenThrowAnException() {
|
||||||
|
WeatherForecast.forValue("state", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetState_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
weatherForecast.setState("test");
|
||||||
|
|
||||||
|
Assert.assertEquals("test", weatherForecast.getState());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetNullState_thenThrowAnException() {
|
||||||
|
final WeatherForecast weather = WeatherForecast.forValue("state", "desc");
|
||||||
|
weather.setState(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetDescription_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
weatherForecast.setDescription("test");
|
||||||
|
|
||||||
|
Assert.assertEquals("test", weatherForecast.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetNullDescription_thenThrowAnException() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
weatherForecast.setDescription(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetIconUrl_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
weatherForecast.setWeatherIconUrl("test");
|
||||||
|
|
||||||
|
Assert.assertEquals("test", weatherForecast.getWeatherIconUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetForecastTime_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
weatherForecast.setForecastTime(now);
|
||||||
|
|
||||||
|
Assert.assertEquals(now, weatherForecast.getForecastTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetTemperature_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final Temperature temperature = Temperature.withValue(22.3, "a");
|
||||||
|
weatherForecast.setTemperature(temperature);
|
||||||
|
|
||||||
|
Assert.assertEquals(temperature, weatherForecast.getTemperature());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetPressure_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2);
|
||||||
|
weatherForecast.setAtmosphericPressure(atmosphericPressure);
|
||||||
|
|
||||||
|
Assert.assertEquals(atmosphericPressure, weatherForecast.getAtmosphericPressure());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetHumidity_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final Humidity humidity = Humidity.withValue((byte) 44);
|
||||||
|
weatherForecast.setHumidity(humidity);
|
||||||
|
|
||||||
|
Assert.assertEquals(humidity, weatherForecast.getHumidity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetWind_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final Wind wind = Wind.withValue(22.2, "a");
|
||||||
|
weatherForecast.setWind(wind);
|
||||||
|
|
||||||
|
Assert.assertEquals(wind, weatherForecast.getWind());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetRain_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final Rain rain = Rain.withThreeHourLevelValue(0);
|
||||||
|
weatherForecast.setRain(rain);
|
||||||
|
|
||||||
|
Assert.assertEquals(rain, weatherForecast.getRain());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetSnow_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final Snow snow = Snow.withThreeHourLevelValue(0);
|
||||||
|
weatherForecast.setSnow(snow);
|
||||||
|
|
||||||
|
Assert.assertEquals(snow, weatherForecast.getSnow());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetClouds_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final Clouds clouds = Clouds.withValue((byte) 33);
|
||||||
|
weatherForecast.setClouds(clouds);
|
||||||
|
|
||||||
|
Assert.assertEquals(clouds, weatherForecast.getClouds());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetForecastTimeISO_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
|
||||||
|
Assert.assertNull(weatherForecast.getForecastTimeISO());
|
||||||
|
|
||||||
|
weatherForecast.setForecastTimeISO("1994-2-3");
|
||||||
|
|
||||||
|
Assert.assertEquals("1994-2-3", weatherForecast.getForecastTimeISO());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetDayTime_thenValueIsSet() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
|
||||||
|
Assert.assertNull(weatherForecast.getDayTime());
|
||||||
|
|
||||||
|
weatherForecast.setDayTime(DayTime.DAY);
|
||||||
|
|
||||||
|
Assert.assertEquals(DayTime.DAY, weatherForecast.getDayTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||||
|
final Location location = Location.withValues(12312, "asd");
|
||||||
|
final Temperature temperature = Temperature.withValue(33.2, "asd");
|
||||||
|
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4);
|
||||||
|
final Clouds clouds = Clouds.withValue((byte) 55);
|
||||||
|
final Rain rain = Rain.withThreeHourLevelValue(33.2);
|
||||||
|
final Snow snow = Snow.withThreeHourLevelValue(33.1);
|
||||||
|
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
location.setCountryCode("3d");
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setTemperature(temperature);
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setAtmosphericPressure(atmosphericPressure);
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setClouds(clouds);
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setRain(rain);
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setSnow(snow);
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setRain(null);
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setSnow(null);
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setRain(Rain.withThreeHourLevelValue(0));
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
|
||||||
|
weatherForecast.setSnow(Snow.withThreeHourLevelValue(0));
|
||||||
|
Assert.assertNotEquals("", weatherForecast.toString());
|
||||||
|
Assert.assertNotNull(weatherForecast.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final WeatherForecast one = WeatherForecast.forValue("state", "desc");
|
||||||
|
final WeatherForecast two = WeatherForecast.forValue("state", "desc");
|
||||||
|
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
|
||||||
|
two.setDescription("112");
|
||||||
|
|
||||||
|
Assert.assertNotEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final WeatherForecast one = WeatherForecast.forValue("state", "desc");
|
||||||
|
final WeatherForecast two = WeatherForecast.forValue("state1", "desc1");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(null));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setState("state");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setDescription("desc");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setWeatherIconUrl("1");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setWeatherIconUrl("1");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
one.setForecastTime(now);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setForecastTime(now);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Temperature temperature = Temperature.withValue(33.2, "as");
|
||||||
|
one.setTemperature(temperature);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setTemperature(temperature);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33);
|
||||||
|
one.setAtmosphericPressure(atmosphericPressure);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setAtmosphericPressure(atmosphericPressure);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Humidity humidity = Humidity.withValue((byte) 33);
|
||||||
|
one.setHumidity(humidity);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setHumidity(humidity);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Wind wind = Wind.withValue(33.6, "asd");
|
||||||
|
one.setWind(wind);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setWind(wind);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Rain rain = Rain.withThreeHourLevelValue(0);
|
||||||
|
one.setRain(rain);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setRain(rain);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Snow snow = Snow.withThreeHourLevelValue(0);
|
||||||
|
one.setSnow(snow);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setSnow(snow);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Clouds clouds = Clouds.withValue((byte) 33);
|
||||||
|
one.setClouds(clouds);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setClouds(clouds);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setForecastTimeISO("test");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setForecastTimeISO("test");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setDayTime(DayTime.NIGHT);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setDayTime(DayTime.DAY);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
one.setDayTime(DayTime.DAY);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
}
|
||||||
|
}
|
||||||
+179
@@ -0,0 +1,179 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class WindUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateWindWithValidArgs_thenValueIsSet() {
|
||||||
|
Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() {
|
||||||
|
Wind.withValue(-21, "a");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() {
|
||||||
|
Wind.withValue(342, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValidSpeed_thenValueIsSet() {
|
||||||
|
final Wind wind = Wind.withValue(33, "as");
|
||||||
|
|
||||||
|
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
|
||||||
|
|
||||||
|
wind.setSpeed(0);
|
||||||
|
|
||||||
|
Assert.assertEquals(0, wind.getSpeed(), 0.00001);
|
||||||
|
|
||||||
|
wind.setSpeed(3656);
|
||||||
|
|
||||||
|
Assert.assertEquals(3656, wind.getSpeed(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidSpeedBelow0_thenThrowAnException() {
|
||||||
|
final Wind wind = Wind.withValue(33, "as");
|
||||||
|
|
||||||
|
Assert.assertEquals(33, wind.getSpeed(), 0.00001);
|
||||||
|
|
||||||
|
wind.setSpeed(-22);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetValidDegrees_thenValueIsSet() {
|
||||||
|
final Wind wind = Wind.withValue(33, "as");
|
||||||
|
|
||||||
|
Assert.assertNull(wind.getDegrees());
|
||||||
|
|
||||||
|
wind.setDegrees(22);
|
||||||
|
|
||||||
|
Assert.assertEquals(22, wind.getDegrees(), 0.00001);
|
||||||
|
|
||||||
|
wind.setDegrees(0);
|
||||||
|
|
||||||
|
Assert.assertEquals(0, wind.getDegrees(), 0.00001);
|
||||||
|
|
||||||
|
wind.setDegrees(360);
|
||||||
|
|
||||||
|
Assert.assertEquals(360, wind.getDegrees(), 0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidDegreesBelow0_thenThrowAnException() {
|
||||||
|
final Wind wind = Wind.withValue(33, "as");
|
||||||
|
wind.setDegrees(-32);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetInvalidDegreesAbove360_thenThrowAnException() {
|
||||||
|
final Wind wind = Wind.withValue(33, "as");
|
||||||
|
wind.setDegrees(378);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetNonNullUnit_thenValueIsSet() {
|
||||||
|
final Wind wind = Wind.withValue(33, "as");
|
||||||
|
|
||||||
|
Assert.assertEquals(wind.getUnit(), "as");
|
||||||
|
|
||||||
|
wind.setUnit("myUnit");
|
||||||
|
|
||||||
|
Assert.assertEquals(wind.getUnit(), "myUnit");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenSetNullUnit_thenThrowAnException() {
|
||||||
|
final Wind wind = Wind.withValue(33, "as");
|
||||||
|
|
||||||
|
wind.setUnit(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final Wind wind = Wind.withValue(302, "a");
|
||||||
|
|
||||||
|
Assert.assertNotNull(wind.toString());
|
||||||
|
|
||||||
|
wind.setDegrees(22);
|
||||||
|
|
||||||
|
Assert.assertNotNull(wind.toString());
|
||||||
|
Assert.assertNotEquals("", wind.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final Wind first = Wind.withValue(22, "a");
|
||||||
|
final Wind second = Wind.withValue(22, "b");
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
second.setUnit("a");
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
second.setSpeed(33);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
first.setSpeed(333);
|
||||||
|
|
||||||
|
Assert.assertNotEquals(first.hashCode(), second.hashCode());
|
||||||
|
|
||||||
|
first.setSpeed(33);
|
||||||
|
|
||||||
|
Assert.assertEquals(first.hashCode(), second.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final Wind first = Wind.withValue(11, "a");
|
||||||
|
final Wind second = Wind.withValue(11, "a");
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
Assert.assertTrue(first.equals(first));
|
||||||
|
Assert.assertFalse(first.equals(new Object()));
|
||||||
|
|
||||||
|
first.setDegrees(34);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
second.setDegrees(34);
|
||||||
|
|
||||||
|
Assert.assertTrue(first.equals(second));
|
||||||
|
|
||||||
|
second.setUnit("v");
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
|
||||||
|
first.setUnit("v");
|
||||||
|
first.setSpeed(second.getSpeed() + 4);
|
||||||
|
|
||||||
|
Assert.assertFalse(first.equals(second));
|
||||||
|
}
|
||||||
|
}
|
||||||
+201
@@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
|
public class LocationUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenCreateObjectWithValidArgs_thenObjectIsCreated() {
|
||||||
|
Location.withValues(33, "test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenCreateObjectWithoutName_thenThrowAnException() {
|
||||||
|
Location.withValues(33, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetId_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
location.setId(55);
|
||||||
|
|
||||||
|
Assert.assertEquals(55, location.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetName_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
location.setName("city");
|
||||||
|
|
||||||
|
Assert.assertEquals("city", location.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetCountryCode_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
location.setCountryCode("by");
|
||||||
|
|
||||||
|
Assert.assertEquals("by", location.getCountryCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetSunrise_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
location.setSunrise(now);
|
||||||
|
|
||||||
|
Assert.assertEquals(now, location.getSunrise());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetSunset_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
location.setSunset(now);
|
||||||
|
|
||||||
|
Assert.assertEquals(now, location.getSunset());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetZoneOffset_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final ZoneOffset offset = ZoneOffset.UTC;
|
||||||
|
location.setZoneOffset(offset);
|
||||||
|
|
||||||
|
Assert.assertEquals(offset, location.getZoneOffset());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSetCoordinate_thenValueIsSet() {
|
||||||
|
final Location location = Location.withValues(33, "test");
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(33.2, 64.2);
|
||||||
|
location.setCoordinate(coordinate);
|
||||||
|
|
||||||
|
Assert.assertEquals(coordinate, location.getCoordinate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallToString_thenAllIsFine() {
|
||||||
|
final Location location = Location.withValues(44, "test");
|
||||||
|
|
||||||
|
Assert.assertNotEquals("", location.toString());
|
||||||
|
|
||||||
|
location.setCoordinate(Coordinate.withValues(33.2, 56.3));
|
||||||
|
|
||||||
|
Assert.assertNotEquals("", location.toString());
|
||||||
|
|
||||||
|
location.setCountryCode("TN");
|
||||||
|
|
||||||
|
Assert.assertNotEquals("", location.toString());
|
||||||
|
Assert.assertNotNull(location.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCallHashCode_thenAllIsFine() {
|
||||||
|
final Location one = Location.withValues(44, "test");
|
||||||
|
final Location two = Location.withValues(44, "test");
|
||||||
|
|
||||||
|
Assert.assertEquals(one.hashCode(), two.hashCode());
|
||||||
|
|
||||||
|
two.setName("112");
|
||||||
|
|
||||||
|
Assert.assertNotEquals(one.hashCode(), two.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCheckEquality_thenAllIsFine() {
|
||||||
|
final Location one = Location.withValues(44, "test");
|
||||||
|
final Location two = Location.withValues(44, "test");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(one));
|
||||||
|
Assert.assertFalse(one.equals(new Object()));
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
two.setId(23);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
one.setId(23);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setName("23");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setName("23");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setCountryCode("11");
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setCountryCode("11");
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
one.setSunrise(now);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setSunrise(now);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setSunset(now);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setSunset(now);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
one.setZoneOffset(ZoneOffset.UTC);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setZoneOffset(ZoneOffset.UTC);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
|
||||||
|
final Coordinate coordinate = Coordinate.withValues(33.5, -22.4);
|
||||||
|
|
||||||
|
one.setCoordinate(coordinate);
|
||||||
|
|
||||||
|
Assert.assertFalse(one.equals(two));
|
||||||
|
|
||||||
|
two.setCoordinate(coordinate);
|
||||||
|
|
||||||
|
Assert.assertTrue(one.equals(two));
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user