mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 19:26:43 +03:00
Compare commits
12 Commits
5ca31780da
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| a2b0360e4b | |||
| b83b121e90 | |||
| fb2e0e01be | |||
| 2d81dadfad | |||
| 5e4b34632e | |||
| 6c1a1642f1 | |||
| 8a1daa0fe2 | |||
| 7e88fe597c | |||
| aa48ac3aa0 | |||
| 7f0866ffa2 | |||
| 4fdb48986e | |||
| 8ca55b15f7 |
+1
-1
@@ -1,5 +1,5 @@
|
||||
container:
|
||||
image: gradle:jdk17
|
||||
image: gradle:jdk8
|
||||
|
||||
testCoverage_task:
|
||||
gradle_cache:
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
*.iml
|
||||
.idea/
|
||||
.idea
|
||||
.gradle
|
||||
build/
|
||||
target/
|
||||
build
|
||||
target
|
||||
out
|
||||
@@ -7,6 +7,14 @@ Free:
|
||||
* 5 day / 3-hour forecast
|
||||
* One Call API
|
||||
* Air pollution
|
||||
* Geocoding API
|
||||
|
||||
Paid:
|
||||
* Hourly Forecast 4 days
|
||||
* Daily Forecast 16 days
|
||||
* Climatic Forecast 30 days
|
||||
* Solar Radiation API
|
||||
* Road Risk API
|
||||
|
||||
Other:
|
||||
* Request timeout settings
|
||||
@@ -14,14 +22,19 @@ Other:
|
||||
### Will be implemented later:
|
||||
|
||||
Free:
|
||||
* Geocoding API
|
||||
* Weather Stations
|
||||
* Weather Triggers
|
||||
|
||||
Paid:
|
||||
* Daily Forecast 16 days
|
||||
* Hourly Forecast 4 days
|
||||
* probably others...
|
||||
* Bulk Downloading
|
||||
* Historical Weather API
|
||||
* Historical Weather API 40 years by timestamp
|
||||
* Historical Weather API 40 years full archive
|
||||
* History Bulk
|
||||
* History Forecast Bulk
|
||||
* Statistical Weather Data API
|
||||
* Accumulated Parameters
|
||||
* Historical Weather Data by State for all ZIP codes, USA
|
||||
|
||||
### Maven coordinates:
|
||||
|
||||
|
||||
+16
-10
@@ -3,26 +3,32 @@ plugins {
|
||||
id 'maven-publish'
|
||||
id 'signing'
|
||||
id 'jacoco'
|
||||
id 'io.freefair.lombok' version '6.5.0.3'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = uri('https://repo.maven.apache.org/maven2/')
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4'
|
||||
implementation 'org.slf4j:slf4j-api:1.7.36'
|
||||
testImplementation 'org.junit.platform:junit-platform-runner:1.8.2'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
|
||||
|
||||
testImplementation 'org.junit.platform:junit-platform-runner:1.9.0'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.0'
|
||||
testImplementation 'ch.qos.logback:logback-classic:1.2.11'
|
||||
testImplementation 'commons-io:commons-io:2.11.0'
|
||||
testImplementation 'org.mockito:mockito-core:4.8.0'
|
||||
}
|
||||
|
||||
group = 'com.github.prominence'
|
||||
version = '3.0.0-SNAPSHOT'
|
||||
description = 'Java OpenWeatherMap API'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
configure([tasks.compileJava]) {
|
||||
sourceCompatibility = 8
|
||||
}
|
||||
|
||||
ext {
|
||||
isReleaseVersion = !version.endsWith("SNAPSHOT")
|
||||
@@ -104,8 +110,8 @@ jacocoTestReport {
|
||||
dependsOn test // tests are required to run before generating the report
|
||||
reports {
|
||||
csv.required = false
|
||||
xml.enabled true
|
||||
xml.destination file("${buildDir}/reports/jacoco/report.xml")
|
||||
xml.required = true
|
||||
xml.outputLocation = layout.buildDirectory.file('reports/jacoco/report.xml')
|
||||
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:1.0')
|
||||
implementation 'com.github.prominence:openweathermap-api:1.0'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:1.1')
|
||||
implementation 'com.github.prominence:openweathermap-api:1.1'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:1.2')
|
||||
implementation 'com.github.prominence:openweathermap-api:1.2'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.0.0')
|
||||
implementation 'com.github.prominence:openweathermap-api:2.0.0'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.0.1')
|
||||
implementation 'com.github.prominence:openweathermap-api:2.0.1'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.1.0')
|
||||
implementation 'com.github.prominence:openweathermap-api:2.1.0'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.1.1')
|
||||
implementation 'com.github.prominence:openweathermap-api:2.1.1'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.2.0')
|
||||
implementation 'com.github.prominence:openweathermap-api:2.2.0'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
@@ -21,7 +21,7 @@ Other:
|
||||
### Gradle coordinates:
|
||||
|
||||
```groovy
|
||||
compile('com.github.prominence:openweathermap-api:2.3.0')
|
||||
implementation 'com.github.prominence:openweathermap-api:2.3.0'
|
||||
```
|
||||
|
||||
### How to use:
|
||||
|
||||
+12
-7
@@ -1,8 +1,13 @@
|
||||
### Implemented features:
|
||||
* Current weather data
|
||||
* 5 day / 3-hour forecast
|
||||
* Hourly forecast
|
||||
* One Call API
|
||||
* Daily forecast
|
||||
* Solar Radiation API
|
||||
* 5 day / 3-hour forecast
|
||||
* Road Risk API
|
||||
* Air Pollution
|
||||
* Geocoding API
|
||||
|
||||
|
||||
Other:
|
||||
@@ -159,7 +164,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
| `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`. |
|
||||
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinates`. |
|
||||
| `toString()` | Returns informative string for the whole available weather information. |
|
||||
|
||||
`toString()` output example:
|
||||
@@ -218,7 +223,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinates` and `population`. |
|
||||
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||
|
||||
@@ -227,7 +232,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
A forecast for Minsk with 15 timestamps.
|
||||
```
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||
`com.github.prominence.openweathermap.api.model.forecast.free.WeatherForecast`'s useful public methods(setters are not listed):
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
@@ -341,7 +346,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|--------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getCurrent()` | Returns `Current` object with current weather state if available. |
|
||||
@@ -429,7 +434,7 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|-------------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getTimezone()` | Returns location timezone object. |
|
||||
| `getTimezoneOffset()` | Returns zone offset. |
|
||||
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||
@@ -492,7 +497,7 @@ final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||
|
||||
| Method | Description |
|
||||
|-------------------------------|---------------------------------------------------------------------------|
|
||||
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getCoordinates()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||
| `getAirPollutionRecords()` | Returns list of `AirPollutionRecord` objects. |
|
||||
|
||||
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord`'s useful public methods(setters are not listed):
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# This file is generated by the 'io.freefair.lombok' Gradle plugin
|
||||
config.stopBubbling = true
|
||||
lombok.addSuppressWarnings = true
|
||||
lombok.addLombokGeneratedAnnotation = true
|
||||
lombok.nonNull.exceptionType = IllegalArgumentException
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -23,74 +23,146 @@
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||
import com.github.prominence.openweathermap.api.context.ApiConfiguration;
|
||||
import com.github.prominence.openweathermap.api.context.ApiConfigurationHolder;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
import com.github.prominence.openweathermap.api.request.air.pollution.AirPollutionRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.climatic.ClimaticForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.daily.DailyForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.forecast.hourly.FourDaysHourlyForecastRequester;
|
||||
import com.github.prominence.openweathermap.api.request.geocoding.GeocodingRequester;
|
||||
import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRequester;
|
||||
import com.github.prominence.openweathermap.api.request.radiation.SolarRadiationRequester;
|
||||
import com.github.prominence.openweathermap.api.request.roadrisk.RoadRiskRequester;
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||
import lombok.NonNull;
|
||||
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.DEVELOPER;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ENTERPRISE;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.PAID;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.PROFESSIONAL;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.SPECIAL;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private final TimeoutSettings timeoutSettings = new TimeoutSettings();
|
||||
private final ApiConfiguration apiConfiguration;
|
||||
|
||||
public OpenWeatherMapClient() {
|
||||
this(ApiConfigurationHolder.getConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Created OpenWeatherMap client object.
|
||||
* @param apiKey API key obtained on <a href="https://home.openweathermap.org/api_keys">OpenWeatherMap site</a>.
|
||||
*
|
||||
* @param apiConfiguration configuration options.
|
||||
*/
|
||||
public OpenWeatherMapClient(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(int connectionTimeout) {
|
||||
timeoutSettings.setConnectionTimeout(connectionTimeout);
|
||||
}
|
||||
|
||||
public void setReadTimeout(int readTimeout) {
|
||||
timeoutSettings.setReadTimeout(readTimeout);
|
||||
public OpenWeatherMapClient(@NonNull ApiConfiguration apiConfiguration) {
|
||||
this.apiConfiguration = apiConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 CurrentWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
return new CurrentWeatherRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* 5 Day / 3 Hour Forecast <a href="https://openweathermap.org/forecast5">API</a>.
|
||||
* @return requester for retrieving 5 day/3-hour weather forecast information.
|
||||
* Hourly forecast <a href="https://openweathermap.org/api/hourly-forecast">API</a>.
|
||||
*
|
||||
* @return requester for retrieving hourly weather forecast information for 4 days.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
||||
return new FiveDayThreeHourStepForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
@SubscriptionAvailability(plans = {DEVELOPER, PROFESSIONAL, ENTERPRISE})
|
||||
public FourDaysHourlyForecastRequester forecastHourly4Days() {
|
||||
return new FourDaysHourlyForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* One Call <a href="https://openweathermap.org/api/one-call-api">API</a>.
|
||||
* To get information about current weather, minute forecast for 1 hour, hourly forecast for 48 hours, daily forecast for 7 days and government weather alerts.
|
||||
*
|
||||
* @return requester for retrieving one call weather information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public OneCallWeatherRequester oneCall() {
|
||||
return new OneCallWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
return new OneCallWeatherRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Daily forecast <a href="https://openweathermap.org/api/hourly-forecast">API</a>.
|
||||
*
|
||||
* @return requester for retrieving daily weather forecast information for 16 days.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = PAID)
|
||||
public DailyForecastRequester forecastDaily16Days() {
|
||||
return new DailyForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Climatic forecast <a href="https://openweathermap.org/api/forecast30">API</a>.
|
||||
*
|
||||
* @return requester for retrieving climatic weather forecast information for 30 days.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = {DEVELOPER, PROFESSIONAL, ENTERPRISE})
|
||||
public ClimaticForecastRequester climaticForecast30Days() {
|
||||
return new ClimaticForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Solar Radiation <a href="https://openweathermap.org/api/solar-radiation">API</a>.
|
||||
*
|
||||
* @return requester for retrieving solar radiation information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = SPECIAL)
|
||||
public SolarRadiationRequester solarRadiation() {
|
||||
return new SolarRadiationRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 FiveDayThreeHourStepForecastRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Road Risk <a href="https://openweathermap.org/api/road-risk">API</a>.
|
||||
*
|
||||
* @return requester for retrieving road risk information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = SPECIAL)
|
||||
public RoadRiskRequester roadRisk() {
|
||||
return new RoadRiskRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Air Pollution <a href="https://openweathermap.org/api/air-pollution">API</a>.
|
||||
* Air Pollution API provides current, forecast and historical air pollution data for any coordinates on the globe.
|
||||
*
|
||||
* @return requester for air pollution information retrieval.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public AirPollutionRequester airPollution() {
|
||||
return new AirPollutionRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
return new AirPollutionRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
public GeocodingRequester geocoding() {
|
||||
return new GeocodingRequester(getRequestSettings());
|
||||
}
|
||||
|
||||
private RequestSettings getRequestSettings() {
|
||||
return new RequestSettings(apiConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -22,9 +22,12 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.conf;
|
||||
|
||||
public class TimeoutSettings {
|
||||
private Integer connectionTimeout;
|
||||
private Integer readTimeout;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public final class TimeoutSettings {
|
||||
private final Integer connectionTimeout;
|
||||
private final Integer readTimeout;
|
||||
|
||||
public TimeoutSettings() {
|
||||
this(2000, 2000);
|
||||
@@ -44,15 +47,7 @@ public class TimeoutSettings {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(Integer connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
public Integer getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeout(Integer readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.context;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||
import com.github.prominence.openweathermap.api.core.net.HttpClient;
|
||||
import com.github.prominence.openweathermap.api.core.net.HttpURLConnectionBasedHttpClient;
|
||||
import com.github.prominence.openweathermap.api.enums.ApiVariant;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
public class ApiConfiguration {
|
||||
@NonNull
|
||||
private final String apiKey;
|
||||
@NonNull
|
||||
private final Map<ApiVariant, String> baseUrls;
|
||||
@NonNull
|
||||
private final HttpClient httpClient;
|
||||
@NonNull
|
||||
private final TimeoutSettings defaultTimeoutSettings;
|
||||
private final ObjectReader objectReader;
|
||||
private final ObjectWriter objectWriter;
|
||||
|
||||
private ApiConfiguration(String apiKey, Map<ApiVariant, String> baseUrls, HttpClient httpClient,
|
||||
ObjectMapper objectMapper, TimeoutSettings defaultTimeoutSettings) {
|
||||
this.apiKey = apiKey;
|
||||
this.baseUrls = Collections.unmodifiableMap(baseUrls);
|
||||
this.httpClient = httpClient;
|
||||
this.defaultTimeoutSettings = defaultTimeoutSettings;
|
||||
this.objectReader = objectMapper.reader();
|
||||
this.objectWriter = objectMapper.writer();
|
||||
}
|
||||
|
||||
public static ApiConfigurationBuilder builder() {
|
||||
return new ApiConfigurationBuilder();
|
||||
}
|
||||
|
||||
public static class ApiConfigurationBuilder {
|
||||
private String apiKey;
|
||||
private Map<ApiVariant, String> baseUrls;
|
||||
private HttpClient httpClient = new HttpURLConnectionBasedHttpClient();
|
||||
private TimeoutSettings defaultTimeoutSettings = new TimeoutSettings();
|
||||
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public ApiConfigurationBuilder() {
|
||||
baseUrls = Arrays.stream(ApiVariant.values())
|
||||
.collect(Collectors.toMap(Function.identity(), ApiVariant::getBaseUrl));
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder apiKey(@NonNull String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder baseUrls(@NonNull Map<ApiVariant, String> baseUrls) {
|
||||
final List<ApiVariant> variants = Arrays.stream(ApiVariant.values()).collect(Collectors.toList());
|
||||
if (!baseUrls.keySet().containsAll(variants)) {
|
||||
throw new IllegalArgumentException("Not all API variants were found: " + baseUrls.keySet() + " , expected: " + variants);
|
||||
}
|
||||
this.baseUrls = new HashMap<>(baseUrls);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder httpClient(@NonNull HttpClient httpClient) {
|
||||
this.httpClient = httpClient;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder objectMapper(@NonNull ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfigurationBuilder defaultTimeoutSettings(@NonNull TimeoutSettings defaultTimeoutSettings) {
|
||||
this.defaultTimeoutSettings = new TimeoutSettings(defaultTimeoutSettings);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiConfiguration build() {
|
||||
return new ApiConfiguration(apiKey, baseUrls, httpClient, objectMapper, defaultTimeoutSettings);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ApiConfiguration.ApiConfigurationBuilder(apiKey=" + this.apiKey + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.context;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
public class ApiConfigurationHolder {
|
||||
|
||||
private static ApiConfiguration configuration = ApiConfiguration.builder()
|
||||
.apiKey(System.getenv("OPENWEATHER_API_KEY"))
|
||||
.build();
|
||||
public static ApiConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public static void setConfiguration(@NonNull ApiConfiguration configuration) {
|
||||
ApiConfigurationHolder.configuration = configuration;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.core.net;
|
||||
|
||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||
|
||||
public interface HttpClient {
|
||||
void setTimeoutSettings(TimeoutSettings timeoutSettings);
|
||||
|
||||
String executeGetRequest(String url);
|
||||
String executePostRequest(String url, String body);
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.core.net;
|
||||
|
||||
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HttpURLConnectionBasedHttpClient implements HttpClient {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HttpURLConnectionBasedHttpClient.class);
|
||||
|
||||
private TimeoutSettings timeoutSettings;
|
||||
|
||||
@Override
|
||||
public void setTimeoutSettings(TimeoutSettings timeoutSettings) {
|
||||
this.timeoutSettings = timeoutSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executeGetRequest(String url) {
|
||||
return doExecute(url, RequestExecutor.Method.GET, null);
|
||||
}
|
||||
|
||||
private String doExecute(String url, RequestExecutor.Method method, String body) {
|
||||
InputStream resultStream = null;
|
||||
try {
|
||||
HttpURLConnection connection = getConnection(url);
|
||||
configureTimeouts(connection);
|
||||
configureConnection(connection, method, body);
|
||||
|
||||
resultStream = evaluateResponse(connection);
|
||||
logger.debug("Executing OpenWeatherMap API request: " + url);
|
||||
return convertInputStreamToString(resultStream);
|
||||
} catch (IllegalStateException | IOException ex) {
|
||||
logger.error("An error occurred during OpenWeatherMap API response parsing: ", ex);
|
||||
throw new NoDataFoundException(ex);
|
||||
} finally {
|
||||
closeQuietly(resultStream);
|
||||
}
|
||||
}
|
||||
|
||||
HttpURLConnection getConnection(String url) throws IOException {
|
||||
return (HttpURLConnection) new URL(url).openConnection();
|
||||
}
|
||||
|
||||
private void closeQuietly(InputStream resultStream) {
|
||||
if (resultStream != null) {
|
||||
try {
|
||||
resultStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream evaluateResponse(HttpURLConnection connection) throws IOException {
|
||||
final int responseCode = connection.getResponseCode();
|
||||
switch (responseCode) {
|
||||
case HttpURLConnection.HTTP_OK:
|
||||
return connection.getInputStream();
|
||||
case HttpURLConnection.HTTP_UNAUTHORIZED:
|
||||
throw new InvalidAuthTokenException();
|
||||
case HttpURLConnection.HTTP_NOT_FOUND:
|
||||
case HttpURLConnection.HTTP_BAD_REQUEST:
|
||||
throw new NoDataFoundException();
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
private void configureTimeouts(HttpURLConnection connection) {
|
||||
Optional.ofNullable(timeoutSettings)
|
||||
.ifPresent(ts -> {
|
||||
Optional.ofNullable(ts.getConnectionTimeout())
|
||||
.ifPresent(connection::setConnectTimeout);
|
||||
Optional.ofNullable(ts.getReadTimeout())
|
||||
.ifPresent(connection::setReadTimeout);
|
||||
});
|
||||
}
|
||||
|
||||
private void configureConnection(HttpURLConnection connection, RequestExecutor.Method method, String body) throws IOException {
|
||||
connection.setRequestMethod(method.name());
|
||||
connection.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||
connection.setRequestProperty("Accept", "application/json");
|
||||
addOptionalBodyContent(connection, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executePostRequest(String url, String body) {
|
||||
return doExecute(url, RequestExecutor.Method.POST, body);
|
||||
}
|
||||
|
||||
private void addOptionalBodyContent(HttpURLConnection connection, String body) throws IOException {
|
||||
if (body != null) {
|
||||
connection.setDoOutput(true);
|
||||
try (OutputStream os = connection.getOutputStream()) {
|
||||
byte[] input = body.getBytes(StandardCharsets.UTF_8);
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 String convertInputStreamToString(InputStream inputStream) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
} catch (IOException ex) {
|
||||
logger.error("Error during response reading: ", ex);
|
||||
throw new IllegalArgumentException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.core.net;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.github.prominence.openweathermap.api.enums.ApiVariant;
|
||||
import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class RequestExecutor {
|
||||
|
||||
private final RequestSettings requestSettings;
|
||||
|
||||
public RequestExecutor(RequestSettings requestSettings) {
|
||||
this.requestSettings = requestSettings;
|
||||
}
|
||||
|
||||
public String getResponse(ApiVariant variant) {
|
||||
return getResponse(variant, Method.GET);
|
||||
}
|
||||
|
||||
public String getResponse(ApiVariant variant, Method httpMethod) {
|
||||
return getResponse(selectRequestUrl(variant), httpMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes call to provided API url and retrieves response in <code>String</code> representation.
|
||||
*
|
||||
* @param url the url to make API request.
|
||||
* @param httpMethod HTTP method to execute.
|
||||
* @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.
|
||||
*/
|
||||
private String getResponse(String url, Method httpMethod) {
|
||||
final HttpClient httpClient = requestSettings.getApiConfiguration().getHttpClient();
|
||||
httpClient.setTimeoutSettings(requestSettings.getTimeoutSettings());
|
||||
|
||||
if (httpMethod == Method.GET) {
|
||||
return httpClient.executeGetRequest(url);
|
||||
} else {
|
||||
return httpClient.executePostRequest(url, getSerializedPayload());
|
||||
}
|
||||
}
|
||||
|
||||
private String selectRequestUrl(ApiVariant variant) {
|
||||
StringBuilder requestUrlBuilder = new StringBuilder(requestSettings.getApiConfiguration().getBaseUrls().get(variant));
|
||||
requestUrlBuilder.append(requestSettings.getUrlAppender());
|
||||
requestUrlBuilder.append('?');
|
||||
String parameters = requestSettings.getRequestParameters().entrySet().stream()
|
||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||
.collect(Collectors.joining("&"));
|
||||
requestUrlBuilder.append(parameters);
|
||||
return requestUrlBuilder.toString();
|
||||
}
|
||||
|
||||
private String getSerializedPayload() {
|
||||
final ObjectWriter objectWriter = requestSettings.getApiConfiguration().getObjectWriter();
|
||||
try {
|
||||
return objectWriter.writeValueAsString(requestSettings.getPayloadObject());
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Method {
|
||||
GET,
|
||||
POST
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.Concentration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ConcentrationDeserializer extends JsonDeserializer<Concentration> {
|
||||
|
||||
@Override
|
||||
public Concentration deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(Concentration::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Optional;
|
||||
|
||||
public class EpochSecondsDeserializer extends JsonDeserializer<OffsetDateTime> {
|
||||
|
||||
@Override
|
||||
public OffsetDateTime deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(Long.class))
|
||||
.map(Instant::ofEpochSecond)
|
||||
.map((Instant instant) -> OffsetDateTime.ofInstant(instant, ZoneOffset.UTC))
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PercentageZeroToOneDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(v -> v.multiply(BigDecimal.valueOf(100)))
|
||||
.map(v -> v.setScale(0, RoundingMode.HALF_EVEN))
|
||||
.map(BigDecimal::intValue)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationIntensity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PrecipitationIntensityDeserializer extends JsonDeserializer<PrecipitationIntensity> {
|
||||
|
||||
@Override
|
||||
public PrecipitationIntensity deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(PrecipitationIntensity::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class RequiredPercentageDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(Integer.class))
|
||||
.filter(v -> v <= 100)
|
||||
.filter(v -> v >= 0)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Invalid data found for percentage"));
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TemperatureValueDeserializer extends JsonDeserializer<TemperatureValue> {
|
||||
|
||||
@Override
|
||||
public TemperatureValue deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(TemperatureValue::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class VisibilityDeserializer extends JsonDeserializer<Visibility> {
|
||||
|
||||
@Override
|
||||
public Visibility deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(Visibility::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindSpeed;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WindSpeedDeserializer extends JsonDeserializer<WindSpeed> {
|
||||
|
||||
@Override
|
||||
public WindSpeed deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(BigDecimal.class))
|
||||
.map(WindSpeed::new)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ZoneIdDeserializer extends JsonDeserializer<ZoneId> {
|
||||
|
||||
@Override
|
||||
public ZoneId deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(String.class))
|
||||
.map(ZoneId::of)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.deserializer;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ZoneOffsetDeserializer extends JsonDeserializer<ZoneOffset> {
|
||||
|
||||
@Override
|
||||
public ZoneOffset deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
|
||||
return Optional.ofNullable(parser.readValueAs(Integer.class))
|
||||
.map(ZoneOffset::ofTotalSeconds)
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present Alexey Zinchenko
|
||||
*
|
||||
* * 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.
|
||||
* 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;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The enum Air quality index.
|
||||
@@ -73,8 +73,11 @@ public enum AirQualityIndex {
|
||||
* @param index the index
|
||||
* @return the by index
|
||||
*/
|
||||
public static AirQualityIndex getByIndex(int index) {
|
||||
final Optional<AirQualityIndex> optionalAirQualityIndex = Arrays.stream(values()).filter(airQualityIndex -> airQualityIndex.getValue() == index).findFirst();
|
||||
return optionalAirQualityIndex.orElse(null);
|
||||
@JsonCreator
|
||||
public static AirQualityIndex getByIndex(@JsonProperty("aqi") int index) {
|
||||
return Arrays.stream(values())
|
||||
.filter(airQualityIndex -> airQualityIndex.getValue() == index)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
|
||||
public enum ApiVariant {
|
||||
|
||||
BASE("https://api.openweathermap.org/"),
|
||||
PRO("https://pro.openweathermap.org/");
|
||||
|
||||
private final String baseUrl;
|
||||
|
||||
ApiVariant(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
}
|
||||
+21
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -20,7 +20,11 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Enumeration for time of a day representation.
|
||||
@@ -44,9 +48,24 @@ public enum DayTime {
|
||||
|
||||
/**
|
||||
* Returns time of a day value.
|
||||
*
|
||||
* @return string value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the appropriate day time based on the short form value.
|
||||
*
|
||||
* @param value the short form value (d/n).
|
||||
* @return day time
|
||||
*/
|
||||
@JsonCreator
|
||||
public static DayTime findByValue(String value) {
|
||||
return Arrays.stream(values())
|
||||
.filter(dayTime -> dayTime.getValue().equals(value))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum EventLevel {
|
||||
/**
|
||||
* Unknown event severity.
|
||||
*/
|
||||
UNKNOWN(0),
|
||||
/**
|
||||
* Green alert.
|
||||
*/
|
||||
GREEN(1),
|
||||
/**
|
||||
* Yellow alert.
|
||||
*/
|
||||
YELLOW(2),
|
||||
/**
|
||||
* Orange alert.
|
||||
*/
|
||||
ORANGE(3),
|
||||
/**
|
||||
* Red alert.
|
||||
*/
|
||||
RED(4);
|
||||
|
||||
private final int value;
|
||||
|
||||
EventLevel(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the appropriate event level based on the numerical level.
|
||||
*
|
||||
* @param value the numerical level.
|
||||
* @return event level
|
||||
*/
|
||||
@JsonCreator
|
||||
public static EventLevel findByValue(int value) {
|
||||
return Arrays.stream(values())
|
||||
.filter(eventLevel -> eventLevel.getValue() == value)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -52,9 +52,10 @@ public enum MoonType {
|
||||
return WANING_GIBBOUS;
|
||||
} else if (numericValue > 0.75 && numericValue < 1) {
|
||||
return WANING_CRESCENT;
|
||||
}
|
||||
} else {
|
||||
return INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equals(double d1, double d2) {
|
||||
return Math.abs(d1 - d2) < precision;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
public enum ResponseType {
|
||||
JSON("json"),
|
||||
HTML("html"),
|
||||
XML("xml");
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum RoadState {
|
||||
NO_REPORT(0),
|
||||
DRY(1),
|
||||
MOIST(2),
|
||||
MOIST_AND_CHEMICALLY_TREATED(3),
|
||||
WET(4),
|
||||
WET_AND_CHEMICALLY_TREATED(5),
|
||||
ICE(6),
|
||||
FROST(7),
|
||||
SNOW(8),
|
||||
SNOW_OR_ICE_WATCH(9),
|
||||
SNOW_OR_ICE_WARNING(10),
|
||||
WET_ABOVE_FREEZING(11),
|
||||
WET_BELOW_FREEZING(12),
|
||||
ABSORPTION(13),
|
||||
ABSORPTION_AT_DEWPOINT(14),
|
||||
DEW(15),
|
||||
BLACK_ICE_WARNING(16),
|
||||
OTHER(17),
|
||||
SLUSH(18);
|
||||
|
||||
private final int value;
|
||||
|
||||
RoadState(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the appropriate road state based on the numerical code.
|
||||
*
|
||||
* @param value the numerical code.
|
||||
* @return road state
|
||||
*/
|
||||
@JsonCreator
|
||||
public static RoadState findByValue(int value) {
|
||||
return Arrays.stream(values()).filter(roadState -> roadState.getValue() == value).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -28,9 +28,9 @@ package com.github.prominence.openweathermap.api.enums;
|
||||
*/
|
||||
public enum SubscriptionPlan {
|
||||
/**
|
||||
* Free subscription plan.
|
||||
* An alias that represents any of paid plans: startup, developer, professional or enterprise.
|
||||
*/
|
||||
FREE,
|
||||
PAID,
|
||||
|
||||
/**
|
||||
* Startup subscription plan.
|
||||
@@ -52,6 +52,12 @@ public enum SubscriptionPlan {
|
||||
*/
|
||||
ENTERPRISE,
|
||||
|
||||
/**
|
||||
* Special subscription plan. You should contact a manager to get an access.
|
||||
*/
|
||||
SPECIAL,
|
||||
|
||||
|
||||
/**
|
||||
* All existing subscription plans.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -47,37 +47,6 @@ public enum UnitSystem {
|
||||
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 "°C";
|
||||
case IMPERIAL:
|
||||
return "°F";
|
||||
case STANDARD:
|
||||
default:
|
||||
return "K";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns unit system value.
|
||||
* @return value unit system.
|
||||
|
||||
+35
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -22,6 +22,9 @@
|
||||
|
||||
package com.github.prominence.openweathermap.api.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -277,7 +280,7 @@ public enum WeatherCondition {
|
||||
private final String description;
|
||||
private final String iconId;
|
||||
|
||||
private WeatherCondition(int id, String name, String description, String iconId) {
|
||||
WeatherCondition(int id, String name, String description, String iconId) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -311,13 +314,24 @@ public enum WeatherCondition {
|
||||
return description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets icon id based on part of day.
|
||||
*
|
||||
* @param partOfDay The part of day we need the icon for.
|
||||
* @return the icon id
|
||||
*/
|
||||
public String getIconId(DayTime partOfDay) {
|
||||
return iconId + partOfDay.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets day icon id.
|
||||
*
|
||||
* @return the day icon id
|
||||
*/
|
||||
public String getDayIconId() {
|
||||
return iconId + 'd';
|
||||
return getIconId(DayTime.DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,35 +340,42 @@ public enum WeatherCondition {
|
||||
* @return the night icon id
|
||||
*/
|
||||
public String getNightIconId() {
|
||||
return iconId + 'n';
|
||||
return getIconId(DayTime.NIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets day icon url.
|
||||
*
|
||||
* @param secure Determines whether we need to use secure channel (HTTPS) for loading the image.
|
||||
* @return the day icon url
|
||||
*/
|
||||
public String getDayIconUrl() {
|
||||
return getIconUrl(getDayIconId());
|
||||
public String getDayIconUrl(boolean secure) {
|
||||
return getIconUrl(getDayIconId(), secure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets night icon url.
|
||||
*
|
||||
* @param secure Determines whether we need to use secure channel (HTTPS) for loading the image.
|
||||
* @return the night icon url
|
||||
*/
|
||||
public String getNightIconUrl() {
|
||||
return getIconUrl(getNightIconId());
|
||||
public String getNightIconUrl(boolean secure) {
|
||||
return getIconUrl(getNightIconId(), secure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets icon url.
|
||||
*
|
||||
* @param iconId the icon id
|
||||
* @param secure Determines whether we need to use secure channel (HTTPS) for loading the image.
|
||||
* @return the icon url
|
||||
*/
|
||||
public static String getIconUrl(String iconId) {
|
||||
return "http://openweathermap.org/img/w/" + iconId + ".png";
|
||||
public static String getIconUrl(String iconId, boolean secure) {
|
||||
String scheme = "http";
|
||||
if (secure) {
|
||||
scheme = "https";
|
||||
}
|
||||
return scheme + "://openweathermap.org/img/w/" + iconId + ".png";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,8 +384,10 @@ public enum WeatherCondition {
|
||||
* @param id the id
|
||||
* @return the by id
|
||||
*/
|
||||
public static WeatherCondition getById(int id) {
|
||||
final Optional<WeatherCondition> optionalWeatherCondition = Arrays.stream(values()).filter(weatherCondition -> weatherCondition.getId() == id).findFirst();
|
||||
@JsonCreator
|
||||
public static WeatherCondition getById(@JsonProperty("id") int id) {
|
||||
final Optional<WeatherCondition> optionalWeatherCondition =
|
||||
Arrays.stream(values()).filter(weatherCondition -> weatherCondition.getId() == id).findFirst();
|
||||
return optionalWeatherCondition.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.exception;
|
||||
|
||||
public class ApiPayloadParseException extends RuntimeException {
|
||||
public ApiPayloadParseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails;
|
||||
import com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* The type Air pollution response mapper.
|
||||
*/
|
||||
public class AirPollutionResponseMapper {
|
||||
/**
|
||||
* Map to air pollution air pollution.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the air pollution
|
||||
*/
|
||||
public AirPollutionDetails mapToAirPollution(String json) {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
AirPollutionDetails airPollutionDetails;
|
||||
try {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
airPollutionDetails = mapToAirPollution(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse Air Pollution response");
|
||||
}
|
||||
|
||||
return airPollutionDetails;
|
||||
}
|
||||
|
||||
private AirPollutionDetails mapToAirPollution(JsonNode rootNode) {
|
||||
final AirPollutionDetails airPollutionDetails = new AirPollutionDetails();
|
||||
airPollutionDetails.setCoordinate(parseCoordinate(rootNode.get("coord")));
|
||||
|
||||
final List<AirPollutionRecord> sampleList = new ArrayList<>();
|
||||
final JsonNode sampleListNode = rootNode.get("list");
|
||||
sampleListNode.forEach(sampleNode -> {
|
||||
sampleList.add(parseAirPollutionSample(sampleNode));
|
||||
});
|
||||
airPollutionDetails.setAirPollutionRecords(sampleList);
|
||||
|
||||
return airPollutionDetails;
|
||||
}
|
||||
|
||||
private AirPollutionRecord parseAirPollutionSample(JsonNode sampleNode) {
|
||||
AirPollutionRecord airPollutionRecord = new AirPollutionRecord();
|
||||
airPollutionRecord.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sampleNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
airPollutionRecord.setAirQualityIndex(AirQualityIndex.getByIndex(sampleNode.get("main").get("aqi").asInt()));
|
||||
|
||||
final JsonNode componentsNode = sampleNode.get("components");
|
||||
airPollutionRecord.setCO(componentsNode.get("co").asDouble());
|
||||
airPollutionRecord.setNO(componentsNode.get("no").asDouble());
|
||||
airPollutionRecord.setNO2(componentsNode.get("no2").asDouble());
|
||||
airPollutionRecord.setO3(componentsNode.get("o3").asDouble());
|
||||
airPollutionRecord.setSO2(componentsNode.get("so2").asDouble());
|
||||
airPollutionRecord.setPM2_5(componentsNode.get("pm2_5").asDouble());
|
||||
airPollutionRecord.setPM10(componentsNode.get("pm10").asDouble());
|
||||
airPollutionRecord.setNH3(componentsNode.get("nh3").asDouble());
|
||||
|
||||
return airPollutionRecord;
|
||||
}
|
||||
|
||||
private Coordinate parseCoordinate(JsonNode rootNode) {
|
||||
final JsonNode latitudeNode = rootNode.get("lat");
|
||||
final JsonNode longitudeNode = rootNode.get("lon");
|
||||
if (latitudeNode != null && longitudeNode != null) {
|
||||
return Coordinate.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-317
@@ -1,317 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.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) {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
Weather weather;
|
||||
try {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
weather = getSingle(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse Weather response");
|
||||
}
|
||||
|
||||
return weather;
|
||||
}
|
||||
|
||||
private Weather getSingle(JsonNode rootNode) {
|
||||
final JsonNode weatherArrayNode = rootNode.get("weather");
|
||||
final JsonNode weatherNode = weatherArrayNode != null ? weatherArrayNode.get(0) : null;
|
||||
final Weather weather = new Weather();
|
||||
|
||||
weather.setWeatherState(parseWeatherState(weatherNode));
|
||||
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.setCalculationTime(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) {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
final 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 (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse Weather response");
|
||||
}
|
||||
|
||||
return weatherList;
|
||||
}
|
||||
|
||||
private WeatherState parseWeatherState(JsonNode weatherNode) {
|
||||
if (weatherNode == null) {
|
||||
return null;
|
||||
}
|
||||
final WeatherState weatherState = new WeatherState(
|
||||
weatherNode.get("id").asInt(),
|
||||
weatherNode.get("main").asText(),
|
||||
weatherNode.get("description").asText()
|
||||
);
|
||||
weatherState.setIconId(weatherNode.get("icon").asText());
|
||||
|
||||
return weatherState;
|
||||
}
|
||||
|
||||
private Temperature parseTemperature(JsonNode rootNode) {
|
||||
final JsonNode mainNode = rootNode.get("main");
|
||||
final double tempValue = mainNode.get("temp").asDouble();
|
||||
final Temperature 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");
|
||||
final 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();
|
||||
|
||||
final 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 && threeHourNode != null) {
|
||||
return Rain.withValues(oneHourNode.asDouble(), threeHourNode.asDouble());
|
||||
} else if (oneHourNode != null) {
|
||||
return Rain.withOneHourLevelValue(oneHourNode.asDouble());
|
||||
} else if (threeHourNode != null) {
|
||||
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 && threeHourNode != null) {
|
||||
return Snow.withValues(oneHourNode.asDouble(), threeHourNode.asDouble());
|
||||
} else if (oneHourNode != null) {
|
||||
return Snow.withOneHourLevelValue(oneHourNode.asDouble());
|
||||
} else if (threeHourNode != null) {
|
||||
return Snow.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Clouds parseClouds(JsonNode rootNode) {
|
||||
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||
final JsonNode allValueNode = cloudsNode.get("all");
|
||||
if (allValueNode != null) {
|
||||
return Clouds.withValue((byte) allValueNode.asInt());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Location parseLocation(JsonNode rootNode) {
|
||||
final 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.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunriseNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
if (sunsetNode != null) {
|
||||
location.setSunsetTime(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) {
|
||||
final JsonNode latitudeNode = rootNode.get("lat");
|
||||
final JsonNode longitudeNode = rootNode.get("lon");
|
||||
if (latitudeNode != null && longitudeNode != null) {
|
||||
return Coordinate.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-303
@@ -1,303 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.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) {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
Forecast forecast;
|
||||
try {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
forecast = mapToForecast(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse Forecast response");
|
||||
}
|
||||
|
||||
return forecast;
|
||||
}
|
||||
|
||||
private Forecast mapToForecast(JsonNode root) {
|
||||
final Forecast forecast = new Forecast();
|
||||
forecast.setLocation(parseLocation(root.get("city")));
|
||||
|
||||
final List<WeatherForecast> forecasts = new ArrayList<>(root.get("cnt").asInt());
|
||||
|
||||
final JsonNode forecastListNode = root.get("list");
|
||||
forecastListNode.forEach(forecastNode -> forecasts.add(parseWeatherForecast(forecastNode)));
|
||||
|
||||
forecast.setWeatherForecasts(forecasts);
|
||||
|
||||
return forecast;
|
||||
}
|
||||
|
||||
private WeatherForecast parseWeatherForecast(JsonNode rootNode) {
|
||||
final WeatherForecast weatherForecast = new WeatherForecast();
|
||||
final JsonNode weatherArrayNode = rootNode.get("weather");
|
||||
if (weatherArrayNode != null) {
|
||||
final JsonNode weatherNode = weatherArrayNode.get(0);
|
||||
weatherForecast.setWeatherState(parseWeatherState(weatherNode));
|
||||
}
|
||||
|
||||
final 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));
|
||||
|
||||
final 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 WeatherState parseWeatherState(JsonNode weatherNode) {
|
||||
if (weatherNode == null) {
|
||||
return null;
|
||||
}
|
||||
final WeatherState weatherState = new WeatherState(
|
||||
weatherNode.get("id").asInt(),
|
||||
weatherNode.get("main").asText(),
|
||||
weatherNode.get("description").asText()
|
||||
);
|
||||
weatherState.setIconId(weatherNode.get("icon").asText());
|
||||
|
||||
return weatherState;
|
||||
}
|
||||
|
||||
private Temperature parseTemperature(JsonNode rootNode) {
|
||||
final double tempValue = rootNode.get("temp").asDouble();
|
||||
final 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("feels_like");
|
||||
if (tempFeelsLike != null) {
|
||||
temperature.setFeelsLike(tempFeelsLike.asDouble());
|
||||
}
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
private AtmosphericPressure parsePressure(JsonNode rootNode) {
|
||||
final 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();
|
||||
|
||||
final 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) {
|
||||
return Snow.withThreeHourLevelValue(threeHourNode.asDouble());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Clouds parseClouds(JsonNode rootNode) {
|
||||
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||
final JsonNode allValueNode = cloudsNode.get("all");
|
||||
if (allValueNode != null) {
|
||||
return Clouds.withValue((byte) allValueNode.asInt());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Location parseLocation(JsonNode rootNode) {
|
||||
final 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.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(sunriseNode.asLong()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
if (sunsetNode != null) {
|
||||
location.setSunsetTime(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) {
|
||||
final JsonNode latitudeNode = rootNode.get("lat");
|
||||
final JsonNode longitudeNode = rootNode.get("lon");
|
||||
if (latitudeNode != null && longitudeNode != null) {
|
||||
return Coordinate.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-442
@@ -1,442 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.mapper;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.WeatherState;
|
||||
import com.github.prominence.openweathermap.api.model.onecall.*;
|
||||
import com.github.prominence.openweathermap.api.model.onecall.current.*;
|
||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather;
|
||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical;
|
||||
import com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Object mapper for OneCall API response.
|
||||
*/
|
||||
public class OneCallWeatherResponseMapper {
|
||||
private final UnitSystem unitSystem;
|
||||
|
||||
/**
|
||||
* Instantiates a new forecast response mapper.
|
||||
*
|
||||
* @param unitSystem the unit system
|
||||
*/
|
||||
public OneCallWeatherResponseMapper(UnitSystem unitSystem) {
|
||||
this.unitSystem = unitSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps current weather data response into java object.
|
||||
*
|
||||
* @param json the json string
|
||||
* @return the current data object
|
||||
*/
|
||||
public CurrentWeatherData mapToCurrent(String json) {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
CurrentWeatherData currentData;
|
||||
try {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
currentData = mapToCurrent(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse OneCall response");
|
||||
}
|
||||
|
||||
return currentData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps current weather data response into java object.
|
||||
*
|
||||
* @param json the json string
|
||||
* @return the current data object
|
||||
*/
|
||||
public HistoricalWeatherData mapToHistorical(String json) {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
HistoricalWeatherData historicalData;
|
||||
try {
|
||||
final JsonNode root = objectMapper.readTree(json);
|
||||
historicalData = mapToHistorical(root);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Cannot parse OneCall response");
|
||||
}
|
||||
|
||||
return historicalData;
|
||||
}
|
||||
|
||||
private CurrentWeatherData mapToCurrent(JsonNode rootNode) {
|
||||
final CurrentWeatherData currentData = new CurrentWeatherData();
|
||||
currentData.setCoordinate(Coordinate.of(rootNode.get("lat").asDouble(), rootNode.get("lon").asDouble()));
|
||||
currentData.setTimezone(ZoneId.of(rootNode.get("timezone").asText()));
|
||||
currentData.setTimezoneOffset(ZoneOffset.ofTotalSeconds(rootNode.get("timezone_offset").asInt()));
|
||||
currentData.setCurrent(parseCurrent(rootNode.get("current")));
|
||||
currentData.setMinutelyList(parseMinutelyList(rootNode.get("minutely")));
|
||||
currentData.setHourlyList(parseHourlyList(rootNode.get("hourly")));
|
||||
currentData.setDailyList(parseDailyList(rootNode.get("daily")));
|
||||
currentData.setAlerts(parseAlerts(rootNode.get("alerts")));
|
||||
|
||||
return currentData;
|
||||
}
|
||||
|
||||
private Current parseCurrent(JsonNode currentNode) {
|
||||
if (currentNode == null) {
|
||||
return null;
|
||||
}
|
||||
final Current current = new Current();
|
||||
current.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(currentNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
current.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(currentNode.get("sunrise").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
current.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(currentNode.get("sunset").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
|
||||
current.setWeatherState(parseWeatherState(currentNode.get("weather").get(0)));
|
||||
current.setTemperature(parseTemperature(currentNode));
|
||||
current.setAtmosphericPressure(parsePressure(currentNode));
|
||||
current.setHumidity(parseHumidity(currentNode));
|
||||
current.setClouds(parseClouds(currentNode));
|
||||
current.setUvIndex(currentNode.get("uvi").asDouble());
|
||||
final JsonNode visibilityNode = currentNode.get("visibility");
|
||||
if (visibilityNode != null) {
|
||||
current.setVisibilityInMetres(visibilityNode.asDouble());
|
||||
}
|
||||
current.setWind(parseWind(currentNode));
|
||||
current.setRain(parseRain(currentNode));
|
||||
current.setSnow(parseSnow(currentNode));
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
private List<Minutely> parseMinutelyList(JsonNode minutelyListNode) {
|
||||
if (minutelyListNode == null) {
|
||||
return null;
|
||||
}
|
||||
final List<Minutely> minutelyList = new ArrayList<>();
|
||||
for (final JsonNode minutelyNode : minutelyListNode) {
|
||||
minutelyList.add(Minutely.withValue(
|
||||
LocalDateTime.ofInstant(Instant.ofEpochSecond(minutelyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()),
|
||||
minutelyNode.get("precipitation").asDouble()
|
||||
));
|
||||
}
|
||||
|
||||
return minutelyList;
|
||||
}
|
||||
|
||||
private List<Hourly> parseHourlyList(JsonNode hourlyListNode) {
|
||||
if (hourlyListNode == null) {
|
||||
return null;
|
||||
}
|
||||
final List<Hourly> hourlyList = new ArrayList<>();
|
||||
for (final JsonNode hourlyNode : hourlyListNode) {
|
||||
final Hourly hourly = new Hourly();
|
||||
hourly.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(hourlyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
|
||||
hourly.setWeatherState(parseWeatherState(hourlyNode.get("weather").get(0)));
|
||||
hourly.setTemperature(parseTemperature(hourlyNode));
|
||||
hourly.setAtmosphericPressure(parsePressure(hourlyNode));
|
||||
hourly.setHumidity(parseHumidity(hourlyNode));
|
||||
hourly.setClouds(parseClouds(hourlyNode));
|
||||
|
||||
final JsonNode uviNode = hourlyNode.get("uvi");
|
||||
if (uviNode != null) {
|
||||
hourly.setUvIndex(uviNode.asDouble());
|
||||
}
|
||||
|
||||
final JsonNode visibilityNode = hourlyNode.get("visibility");
|
||||
if (visibilityNode != null) {
|
||||
hourly.setVisibilityInMetres(visibilityNode.asDouble());
|
||||
}
|
||||
hourly.setWind(parseWind(hourlyNode));
|
||||
final JsonNode popNode = hourlyNode.get("pop");
|
||||
if (popNode != null) {
|
||||
hourly.setProbabilityOfPrecipitation(popNode.asDouble());
|
||||
}
|
||||
hourly.setRain(parseRain(hourlyNode));
|
||||
hourly.setSnow(parseSnow(hourlyNode));
|
||||
|
||||
hourlyList.add(hourly);
|
||||
}
|
||||
|
||||
return hourlyList;
|
||||
}
|
||||
|
||||
private List<Daily> parseDailyList(JsonNode dailyListNode) {
|
||||
if (dailyListNode == null) {
|
||||
return null;
|
||||
}
|
||||
final List<Daily> dailyList = new ArrayList<>();
|
||||
for (final JsonNode dailyNode : dailyListNode) {
|
||||
final Daily daily = new Daily();
|
||||
daily.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
daily.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunrise").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
daily.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(dailyNode.get("sunset").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
final JsonNode moonriseTimeNode = dailyNode.get("moonrise");
|
||||
if (moonriseTimeNode != null) {
|
||||
daily.setMoonriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(moonriseTimeNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
final JsonNode moonsetTimeNode = dailyNode.get("moonset");
|
||||
if (moonsetTimeNode != null) {
|
||||
daily.setMoonsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(moonsetTimeNode.asInt()), TimeZone.getDefault().toZoneId()));
|
||||
}
|
||||
final JsonNode moonPhaseNode = dailyNode.get("moon_phase");
|
||||
if (moonPhaseNode != null) {
|
||||
daily.setMoonPhase(new MoonPhase(moonPhaseNode.asDouble()));
|
||||
}
|
||||
|
||||
daily.setWeatherState(parseWeatherState(dailyNode.get("weather").get(0)));
|
||||
daily.setTemperature(parseDailyTemperature(dailyNode));
|
||||
daily.setAtmosphericPressure(parsePressure(dailyNode));
|
||||
daily.setHumidity(parseHumidity(dailyNode));
|
||||
daily.setWind(parseWind(dailyNode));
|
||||
daily.setClouds(parseClouds(dailyNode));
|
||||
daily.setUvIndex(dailyNode.get("uvi").asDouble());
|
||||
daily.setProbabilityOfPrecipitation(dailyNode.get("pop").asDouble());
|
||||
daily.setRain(parseDailyRain(dailyNode));
|
||||
daily.setSnow(parseDailySnow(dailyNode));
|
||||
|
||||
dailyList.add(daily);
|
||||
}
|
||||
|
||||
return dailyList;
|
||||
}
|
||||
|
||||
private List<Alert> parseAlerts(JsonNode alertsNode) {
|
||||
if (alertsNode == null) {
|
||||
return null;
|
||||
}
|
||||
final List<Alert> alerts = new ArrayList<>();
|
||||
for (final JsonNode alertNode : alertsNode) {
|
||||
Alert alert = new Alert();
|
||||
alert.setSenderName(alertNode.get("sender_name").asText());
|
||||
alert.setEventName(alertNode.get("event").asText());
|
||||
alert.setStartTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(alertNode.get("start").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
alert.setEndTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(alertNode.get("end").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
alert.setDescription(alertNode.get("description").asText());
|
||||
alerts.add(alert);
|
||||
}
|
||||
return alerts;
|
||||
}
|
||||
|
||||
private HistoricalWeatherData mapToHistorical(JsonNode rootNode) {
|
||||
final HistoricalWeatherData historicalData = new HistoricalWeatherData();
|
||||
historicalData.setCoordinate(Coordinate.of(rootNode.get("lat").asDouble(), rootNode.get("lon").asDouble()));
|
||||
historicalData.setTimezone(ZoneId.of(rootNode.get("timezone").asText()));
|
||||
historicalData.setTimezoneOffset(ZoneOffset.ofTotalSeconds(rootNode.get("timezone_offset").asInt()));
|
||||
historicalData.setHistoricalWeather(parseHistoricalWeather(rootNode.get("current")));
|
||||
historicalData.setHourlyList(parseHourlyHistoricalList(rootNode.get("hourly")));
|
||||
|
||||
return historicalData;
|
||||
}
|
||||
|
||||
private HistoricalWeather parseHistoricalWeather(JsonNode currentNode) {
|
||||
if (currentNode == null) {
|
||||
return null;
|
||||
}
|
||||
final HistoricalWeather historicalWeather = new HistoricalWeather();
|
||||
historicalWeather.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(currentNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
historicalWeather.setSunriseTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(currentNode.get("sunrise").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
historicalWeather.setSunsetTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(currentNode.get("sunset").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
|
||||
final JsonNode weatherListNode = currentNode.get("weather");
|
||||
if (weatherListNode != null) {
|
||||
historicalWeather.setWeatherState(parseWeatherState(weatherListNode.get(0)));
|
||||
}
|
||||
historicalWeather.setTemperature(parseTemperature(currentNode));
|
||||
historicalWeather.setAtmosphericPressure(parsePressure(currentNode));
|
||||
historicalWeather.setHumidity(parseHumidity(currentNode));
|
||||
historicalWeather.setClouds(parseClouds(currentNode));
|
||||
historicalWeather.setUvIndex(currentNode.get("uvi").asDouble());
|
||||
final JsonNode visibilityMode = currentNode.get("visibility");
|
||||
if (visibilityMode != null) {
|
||||
historicalWeather.setVisibilityInMetres(visibilityMode.asDouble());
|
||||
}
|
||||
historicalWeather.setWind(parseWind(currentNode));
|
||||
historicalWeather.setRain(parseRain(currentNode));
|
||||
historicalWeather.setSnow(parseSnow(currentNode));
|
||||
|
||||
return historicalWeather;
|
||||
}
|
||||
|
||||
private List<HourlyHistorical> parseHourlyHistoricalList(JsonNode hourlyListNode) {
|
||||
if (hourlyListNode == null) {
|
||||
return null;
|
||||
}
|
||||
final List<HourlyHistorical> hourlyList = new ArrayList<>();
|
||||
for (final JsonNode hourlyNode : hourlyListNode) {
|
||||
final HourlyHistorical hourly = new HourlyHistorical();
|
||||
hourly.setForecastTime(LocalDateTime.ofInstant(Instant.ofEpochSecond(hourlyNode.get("dt").asInt()), TimeZone.getDefault().toZoneId()));
|
||||
|
||||
hourly.setWeatherState(parseWeatherState(hourlyNode.get("weather").get(0)));
|
||||
hourly.setTemperature(parseTemperature(hourlyNode));
|
||||
hourly.setAtmosphericPressure(parsePressure(hourlyNode));
|
||||
hourly.setHumidity(parseHumidity(hourlyNode));
|
||||
hourly.setClouds(parseClouds(hourlyNode));
|
||||
|
||||
final JsonNode visibilityNode = hourlyNode.get("visibility");
|
||||
if (visibilityNode != null) {
|
||||
hourly.setVisibilityInMetres(visibilityNode.asDouble());
|
||||
}
|
||||
hourly.setWind(parseWind(hourlyNode));
|
||||
hourly.setRain(parseRain(hourlyNode));
|
||||
hourly.setSnow(parseSnow(hourlyNode));
|
||||
|
||||
hourlyList.add(hourly);
|
||||
}
|
||||
|
||||
return hourlyList;
|
||||
}
|
||||
|
||||
private WeatherState parseWeatherState(JsonNode weatherNode) {
|
||||
if (weatherNode == null) {
|
||||
return null;
|
||||
}
|
||||
final WeatherState weatherState = new WeatherState(
|
||||
weatherNode.get("id").asInt(),
|
||||
weatherNode.get("main").asText(),
|
||||
weatherNode.get("description").asText()
|
||||
);
|
||||
weatherState.setIconId(weatherNode.get("icon").asText());
|
||||
|
||||
return weatherState;
|
||||
}
|
||||
|
||||
private Temperature parseTemperature(JsonNode rootNode) {
|
||||
final double tempValue = rootNode.get("temp").asDouble();
|
||||
final Temperature temperature = Temperature.withValue(tempValue, unitSystem.getTemperatureUnit());
|
||||
|
||||
final JsonNode tempFeelsLike = rootNode.get("feels_like");
|
||||
if (tempFeelsLike != null) {
|
||||
temperature.setFeelsLike(tempFeelsLike.asDouble());
|
||||
}
|
||||
final JsonNode dewPoint = rootNode.get("dew_point");
|
||||
if (dewPoint != null) {
|
||||
temperature.setDewPoint(dewPoint.asDouble());
|
||||
}
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
private DailyTemperature parseDailyTemperature(JsonNode dailyNode) {
|
||||
final DailyTemperature temperature = new DailyTemperature();
|
||||
final JsonNode tempNode = dailyNode.get("temp");
|
||||
temperature.setMorning(tempNode.get("morn").asDouble());
|
||||
temperature.setDay(tempNode.get("day").asDouble());
|
||||
temperature.setEve(tempNode.get("eve").asDouble());
|
||||
temperature.setNight(tempNode.get("night").asDouble());
|
||||
temperature.setMin(tempNode.get("min").asDouble());
|
||||
temperature.setMax(tempNode.get("max").asDouble());
|
||||
|
||||
final JsonNode feelsLikeNode = dailyNode.get("feels_like");
|
||||
temperature.setMorningFeelsLike(feelsLikeNode.get("morn").asDouble());
|
||||
temperature.setDayFeelsLike(feelsLikeNode.get("day").asDouble());
|
||||
temperature.setEveFeelsLike(feelsLikeNode.get("eve").asDouble());
|
||||
temperature.setNightFeelsLike(feelsLikeNode.get("night").asDouble());
|
||||
|
||||
return temperature;
|
||||
}
|
||||
|
||||
private AtmosphericPressure parsePressure(JsonNode rootNode) {
|
||||
return AtmosphericPressure.withValue(rootNode.get("pressure").asDouble());
|
||||
}
|
||||
|
||||
private Humidity parseHumidity(JsonNode rootNode) {
|
||||
return Humidity.withValue((byte) (rootNode.get("humidity").asInt()));
|
||||
}
|
||||
|
||||
private Wind parseWind(JsonNode rootNode) {
|
||||
final JsonNode windSpeedNode = rootNode.get("wind_speed");
|
||||
if (windSpeedNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Wind wind = Wind.withValue(windSpeedNode.asDouble(), unitSystem.getWindUnit());
|
||||
|
||||
final JsonNode degNode = rootNode.get("wind_deg");
|
||||
if (degNode != null) {
|
||||
wind.setDegrees(degNode.asDouble());
|
||||
}
|
||||
final JsonNode gustNode = rootNode.get("wind_gust");
|
||||
if (gustNode != null) {
|
||||
wind.setGust(gustNode.asDouble());
|
||||
}
|
||||
|
||||
return wind;
|
||||
}
|
||||
|
||||
private Rain parseRain(JsonNode root) {
|
||||
final JsonNode rainNode = root.get("rain");
|
||||
if (rainNode != null) {
|
||||
final JsonNode oneHourNode = rainNode.get("1h");
|
||||
if (oneHourNode != null) {
|
||||
return Rain.withOneHourLevelValue(oneHourNode.asDouble());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DailyRain parseDailyRain(JsonNode dailyNode) {
|
||||
final JsonNode valueNode = dailyNode.get("rain");
|
||||
if (valueNode != null) {
|
||||
return DailyRain.withValue(valueNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Snow parseSnow(JsonNode root) {
|
||||
final JsonNode snowNode = root.get("snow");
|
||||
if (snowNode != null) {
|
||||
final JsonNode OneHourNode = snowNode.get("1h");
|
||||
if (OneHourNode != null) {
|
||||
Rain.withOneHourLevelValue(OneHourNode.asDouble());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private DailySnow parseDailySnow(JsonNode dailyNode) {
|
||||
final JsonNode valueNode = dailyNode.get("snow");
|
||||
if (valueNode != null) {
|
||||
return DailySnow.withValue(valueNode.asDouble());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Clouds parseClouds(JsonNode rootNode) {
|
||||
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||
if (cloudsNode != null) {
|
||||
return Clouds.withValue((byte) cloudsNode.asInt());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-155
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* 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,106 +0,0 @@
|
||||
/*
|
||||
* 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 Clouds type represents cloudiness value percentage.
|
||||
* Its value can only be an integer in [0, 100] range.
|
||||
*/
|
||||
public class Clouds {
|
||||
private static final String DEFAULT_UNIT = "%";
|
||||
|
||||
private byte value;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns cloudiness percentage value.
|
||||
*
|
||||
* @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
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Clouds)) return false;
|
||||
Clouds clouds = (Clouds) o;
|
||||
return value == clouds.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Clouds: " + value + getUnit();
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* 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() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for {@link Coordinate} creation with correctness check.
|
||||
* @param latitude latitude
|
||||
* @param longitude longitude
|
||||
* @return coordinate object.
|
||||
*/
|
||||
public static Coordinate of(double latitude, double longitude) {
|
||||
final Coordinate coordinate = new Coordinate();
|
||||
coordinate.setLatitude(latitude);
|
||||
coordinate.setLongitude(longitude);
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* 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,183 +0,0 @@
|
||||
/*
|
||||
* 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() {
|
||||
final 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,136 +0,0 @@
|
||||
/*
|
||||
* 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 com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The type Weather state.
|
||||
*/
|
||||
public class WeatherState {
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private String iconId;
|
||||
private final WeatherCondition weatherConditionEnum;
|
||||
|
||||
public WeatherState(Integer id, String name, String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.weatherConditionEnum = WeatherCondition.getById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets icon id.
|
||||
*
|
||||
* @return the icon id
|
||||
*/
|
||||
public String getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets icon id.
|
||||
*
|
||||
* @param iconId the icon id
|
||||
*/
|
||||
public void setIconId(String iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather condition enum.
|
||||
*
|
||||
* @return the weather condition enum
|
||||
*/
|
||||
public WeatherCondition getWeatherConditionEnum() {
|
||||
return weatherConditionEnum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon url.
|
||||
*
|
||||
* @return the weather icon url
|
||||
*/
|
||||
public String getWeatherIconUrl() {
|
||||
if (iconId != null) {
|
||||
return WeatherCondition.getIconUrl(iconId);
|
||||
}
|
||||
if (weatherConditionEnum != null) {
|
||||
// return the default one for the current weather condition
|
||||
return weatherConditionEnum.getDayIconUrl();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WeatherState that = (WeatherState) o;
|
||||
return Objects.equals(id, that.id) &&
|
||||
Objects.equals(name, that.name) &&
|
||||
Objects.equals(description, that.description) &&
|
||||
Objects.equals(iconId, that.iconId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name, description, iconId, weatherConditionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weather state: " + name + "(" + description + ").";
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Interface of air pollution concentration measurements.
|
||||
*/
|
||||
public interface AirPollutionConcentration {
|
||||
/**
|
||||
* The date time when the measurement happened.
|
||||
*
|
||||
* @return datetime
|
||||
*/
|
||||
OffsetDateTime getMeasurementTime();
|
||||
|
||||
/**
|
||||
* The air quality index as an (overview).
|
||||
*
|
||||
* @return index
|
||||
*/
|
||||
AirQualityIndex getAirQualityIndex();
|
||||
|
||||
/**
|
||||
* The concentration of CO in the air.
|
||||
*
|
||||
* @return CO
|
||||
*/
|
||||
Concentration getCarbonMonoxide();
|
||||
|
||||
/**
|
||||
* The concentration of NO in the air.
|
||||
*
|
||||
* @return NO
|
||||
*/
|
||||
Concentration getNitrogenMonoxide();
|
||||
|
||||
/**
|
||||
* The concentration of NO2 in the air.
|
||||
*
|
||||
* @return NO2
|
||||
*/
|
||||
Concentration getNitrogenDioxide();
|
||||
|
||||
/**
|
||||
* The concentration of O3 in the air.
|
||||
*
|
||||
* @return O3
|
||||
*/
|
||||
Concentration getOzone();
|
||||
|
||||
/**
|
||||
* The concentration of SO2 in the air.
|
||||
*
|
||||
* @return SO2
|
||||
*/
|
||||
Concentration getSulphurDioxide();
|
||||
|
||||
/**
|
||||
* The concentration of pine particles matter in the air.
|
||||
*
|
||||
* @return fine particles
|
||||
*/
|
||||
Concentration getFineParticlesMatter();
|
||||
|
||||
/**
|
||||
* The concentration of coarse particulate matter in the air.
|
||||
*
|
||||
* @return coarse particles
|
||||
*/
|
||||
Concentration getCoarseParticulateMatter();
|
||||
|
||||
/**
|
||||
* The concentration of NH3 in the air.
|
||||
*
|
||||
* @return NH3
|
||||
*/
|
||||
Concentration getAmmonia();
|
||||
}
|
||||
+23
-71
@@ -1,87 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present Alexey Zinchenko
|
||||
*
|
||||
* * 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.
|
||||
* 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.air.pollution;
|
||||
|
||||
import com.github.prominence.openweathermap.api.model.Coordinate;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.CoordinateAware;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The type Air pollution.
|
||||
* Interface of air pollution overview.
|
||||
*/
|
||||
public class AirPollutionDetails {
|
||||
private Coordinate coordinate;
|
||||
private List<AirPollutionRecord> airPollutionRecords;
|
||||
public interface AirPollutionDetails extends CoordinateAware {
|
||||
|
||||
/**
|
||||
* Gets coordinate.
|
||||
*
|
||||
* @return the coordinate
|
||||
* The pollution details.
|
||||
* @return pollution
|
||||
*/
|
||||
public Coordinate getCoordinate() {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets coordinate.
|
||||
*
|
||||
* @param coordinate the coordinate
|
||||
*/
|
||||
public void setCoordinate(Coordinate coordinate) {
|
||||
this.coordinate = coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets air pollution details.
|
||||
*
|
||||
* @return the air pollution details
|
||||
*/
|
||||
public List<AirPollutionRecord> getAirPollutionRecords() {
|
||||
return airPollutionRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets air pollution details.
|
||||
*
|
||||
* @param airPollutionRecords the air pollution details
|
||||
*/
|
||||
public void setAirPollutionRecords(List<AirPollutionRecord> airPollutionRecords) {
|
||||
this.airPollutionRecords = airPollutionRecords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AirPollutionDetails that = (AirPollutionDetails) o;
|
||||
return Objects.equals(coordinate, that.coordinate) && Objects.equals(airPollutionRecords, that.airPollutionRecords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(coordinate, airPollutionRecords);
|
||||
}
|
||||
List<AirPollutionConcentration> getAirPollutionConcentration();
|
||||
}
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.air.pollution;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.Coordinates;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type representing Air pollution data.
|
||||
*/
|
||||
@Data
|
||||
public class AirPollutionDetailsModel implements AirPollutionDetails {
|
||||
@JsonProperty("coord")
|
||||
private Coordinates coordinates;
|
||||
@JsonProperty("list")
|
||||
private List<AirPollutionRecord> airPollutionRecords;
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public List<AirPollutionConcentration> getAirPollutionConcentration() {
|
||||
return airPollutionRecords.stream()
|
||||
.map(AirPollutionConcentration.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.air.pollution;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.ConcentrationDeserializer;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* The type Air pollution record.
|
||||
*/
|
||||
@Data
|
||||
public class AirPollutionMeasurements {
|
||||
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("co")
|
||||
private Concentration carbonMonoxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("no")
|
||||
private Concentration nitrogenMonoxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("no2")
|
||||
private Concentration nitrogenDioxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("o3")
|
||||
private Concentration ozone;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("so2")
|
||||
private Concentration sulphurDioxide;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("pm2_5")
|
||||
private Concentration fineParticlesMatter;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("pm10")
|
||||
private Concentration coarseParticulateMatter;
|
||||
@JsonDeserialize(using = ConcentrationDeserializer.class)
|
||||
@JsonProperty("nh3")
|
||||
private Concentration ammonia;
|
||||
|
||||
}
|
||||
+71
-342
@@ -1,376 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present Alexey Zinchenko
|
||||
*
|
||||
* * 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.
|
||||
* 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.air.pollution;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The type Air pollution record.
|
||||
* The type representing an Air pollution record.
|
||||
*/
|
||||
public class AirPollutionRecord {
|
||||
private LocalDateTime forecastTime;
|
||||
@Data
|
||||
public class AirPollutionRecord implements AirPollutionConcentration {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime measurementTime;
|
||||
@JsonProperty("main")
|
||||
private AirQualityIndex airQualityIndex;
|
||||
@JsonProperty("components")
|
||||
private AirPollutionMeasurements components;
|
||||
|
||||
private Double CO;
|
||||
private Double NO;
|
||||
private Double NO2;
|
||||
private Double O3;
|
||||
private Double SO2;
|
||||
private Double PM2_5;
|
||||
private Double PM10;
|
||||
private Double NH3;
|
||||
|
||||
/**
|
||||
* Gets forecast time.
|
||||
*
|
||||
* @return the forecast time
|
||||
*/
|
||||
public LocalDateTime getForecastTime() {
|
||||
return forecastTime;
|
||||
@Override
|
||||
public OffsetDateTime getMeasurementTime() {
|
||||
return measurementTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets forecast time.
|
||||
*
|
||||
* @param forecastTime the forecast time
|
||||
*/
|
||||
public void setForecastTime(LocalDateTime forecastTime) {
|
||||
this.forecastTime = forecastTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets air quality index.
|
||||
*
|
||||
* @return the air quality index
|
||||
*/
|
||||
@Override
|
||||
public AirQualityIndex getAirQualityIndex() {
|
||||
return airQualityIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets air quality index.
|
||||
*
|
||||
* @param airQualityIndex the air quality index
|
||||
*/
|
||||
public void setAirQualityIndex(AirQualityIndex airQualityIndex) {
|
||||
this.airQualityIndex = airQualityIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets carbon monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the carbon monoxide value
|
||||
*/
|
||||
public Double getCO() {
|
||||
return CO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets carbon monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the carbon monoxide value
|
||||
*/
|
||||
public Double getCarbonMonoxide() {
|
||||
return getCO();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets carbon monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param CO the carbon monoxide value
|
||||
*/
|
||||
public void setCO(Double CO) {
|
||||
this.CO = CO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen monoxide value
|
||||
*/
|
||||
public Double getNO() {
|
||||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen monoxide value
|
||||
*/
|
||||
public Double getNitrogenMonoxide() {
|
||||
return getNO();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets nitrogen monoxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param NO the nitrogen monoxide value
|
||||
*/
|
||||
public void setNO(Double NO) {
|
||||
this.NO = NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen dioxide value
|
||||
*/
|
||||
public Double getNO2() {
|
||||
return NO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets nitrogen dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the nitrogen dioxide value
|
||||
*/
|
||||
public Double getNitrogenDioxide() {
|
||||
return getNO2();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets nitrogen dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param NO2 the nitrogen dioxide value
|
||||
*/
|
||||
public void setNO2(Double NO2) {
|
||||
this.NO2 = NO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ozone concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ozone value
|
||||
*/
|
||||
public Double getO3() {
|
||||
return O3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ozone concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ozone value
|
||||
*/
|
||||
public Double getOzone() {
|
||||
return getO3();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ozone concentration value in μg/m^3.
|
||||
*
|
||||
* @param o3 the ozone value
|
||||
*/
|
||||
public void setO3(Double o3) {
|
||||
O3 = o3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sulphur dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the sulphur dioxide value
|
||||
*/
|
||||
public Double getSO2() {
|
||||
return SO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sulphur dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @return the sulphur dioxide value
|
||||
*/
|
||||
public Double getSulphurDioxide() {
|
||||
return getSO2();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sulphur dioxide concentration value in μg/m^3.
|
||||
*
|
||||
* @param SO2 the sulphur dioxide value
|
||||
*/
|
||||
public void setSO2(Double SO2) {
|
||||
this.SO2 = SO2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets fine particles matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the fine particles matter value
|
||||
*/
|
||||
public Double getPM2_5() {
|
||||
return PM2_5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets fine particles matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the fine particles matter value
|
||||
*/
|
||||
public Double getFineParticlesMatter() {
|
||||
return getPM2_5();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets fine particles matter concentration value in μg/m^3.
|
||||
*
|
||||
* @param PM2_5 the fine particles matter value
|
||||
*/
|
||||
public void setPM2_5(Double PM2_5) {
|
||||
this.PM2_5 = PM2_5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets coarse particulate matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the coarse particulate matter value
|
||||
*/
|
||||
public Double getPM10() {
|
||||
return PM10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets coarse particulate matter concentration value in μg/m^3.
|
||||
*
|
||||
* @return the coarse particulate matter value
|
||||
*/
|
||||
public Double getCoarseParticulateMatter() {
|
||||
return getPM10();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets coarse particulate matter concentration value in μg/m^3.
|
||||
*
|
||||
* @param PM10 the coarse particulate matter value
|
||||
*/
|
||||
public void setPM10(Double PM10) {
|
||||
this.PM10 = PM10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ammonia concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ammonia value
|
||||
*/
|
||||
public Double getNH3() {
|
||||
return NH3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ammonia concentration value in μg/m^3.
|
||||
*
|
||||
* @return the ammonia value
|
||||
*/
|
||||
public Double getAmmonia() {
|
||||
return getNH3();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets ammonia concentration value in μg/m^3.
|
||||
*
|
||||
* @param NH3 the ammonia value
|
||||
*/
|
||||
public void setNH3(Double NH3) {
|
||||
this.NH3 = NH3;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AirPollutionRecord that = (AirPollutionRecord) o;
|
||||
return Objects.equals(forecastTime, that.forecastTime) && airQualityIndex == that.airQualityIndex && Objects.equals(CO, that.CO) && Objects.equals(NO, that.NO) && Objects.equals(NO2, that.NO2) && Objects.equals(O3, that.O3) && Objects.equals(SO2, that.SO2) && Objects.equals(PM2_5, that.PM2_5) && Objects.equals(PM10, that.PM10) && Objects.equals(NH3, that.NH3);
|
||||
public Concentration getCarbonMonoxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getCarbonMonoxide).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(forecastTime, airQualityIndex, CO, NO, NO2, O3, SO2, PM2_5, PM10, NH3);
|
||||
public Concentration getNitrogenMonoxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getNitrogenMonoxide).orElse(null);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder stringBuilder = new StringBuilder()
|
||||
.append("Air Pollution Record for ")
|
||||
.append(forecastTime)
|
||||
.append(", AQI=")
|
||||
.append(airQualityIndex.name())
|
||||
.append(".");
|
||||
final boolean anyConcentrationAvailable = Stream.of(CO, NO, NO2, O3, SO2, PM2_5, PM10, NH3).anyMatch(Objects::nonNull);
|
||||
if (anyConcentrationAvailable) {
|
||||
stringBuilder.append(" Concentrations:");
|
||||
if (CO != null) {
|
||||
stringBuilder
|
||||
.append(" CO(Carbon monoxide) = ")
|
||||
.append(CO)
|
||||
.append(" μg/m^3;");
|
||||
public Concentration getNitrogenDioxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getNitrogenDioxide).orElse(null);
|
||||
}
|
||||
if (NO != null) {
|
||||
stringBuilder
|
||||
.append(" NO(Nitrogen monoxide) = ")
|
||||
.append(NO)
|
||||
.append(" μg/m^3;");
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getOzone() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getOzone).orElse(null);
|
||||
}
|
||||
if (NO2 != null) {
|
||||
stringBuilder
|
||||
.append(" NO2(Nitrogen dioxide) = ")
|
||||
.append(NO2)
|
||||
.append(" μg/m^3;");
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getSulphurDioxide() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getSulphurDioxide).orElse(null);
|
||||
}
|
||||
if (O3 != null) {
|
||||
stringBuilder
|
||||
.append(" O3(Ozone) = ")
|
||||
.append(O3)
|
||||
.append(" μg/m^3;");
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getFineParticlesMatter() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getFineParticlesMatter).orElse(null);
|
||||
}
|
||||
if (SO2 != null) {
|
||||
stringBuilder
|
||||
.append(" SO2(Sulphur dioxide) = ")
|
||||
.append(SO2)
|
||||
.append(" μg/m^3;");
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getCoarseParticulateMatter() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getCoarseParticulateMatter).orElse(null);
|
||||
}
|
||||
if (PM2_5 != null) {
|
||||
stringBuilder
|
||||
.append(" PM2.5(Fine particles matter) = ")
|
||||
.append(PM2_5)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (PM10 != null) {
|
||||
stringBuilder
|
||||
.append(" PM10(Coarse particulate matter) = ")
|
||||
.append(PM10)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
if (NH3 != null) {
|
||||
stringBuilder
|
||||
.append(" NH3(Ammonia) = ")
|
||||
.append(NH3)
|
||||
.append(" μg/m^3;");
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public Concentration getAmmonia() {
|
||||
return Optional.ofNullable(components).map(AirPollutionMeasurements::getAmmonia).orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.air.pollution;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* Entity for air pollution concentration measurement.
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
public class Concentration {
|
||||
private static final int DECIMAL_PLACES = 10;
|
||||
@NonNull
|
||||
private final BigDecimal value;
|
||||
|
||||
/**
|
||||
* Returns the measured value in micrograms/m^3.
|
||||
*
|
||||
* @return value
|
||||
*/
|
||||
@JsonIgnore
|
||||
public BigDecimal asMicrogramsPerCubicMeters() {
|
||||
return value.setScale(DECIMAL_PLACES, RoundingMode.HALF_EVEN);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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.";
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
/*
|
||||
* 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 sunriseTime;
|
||||
private LocalDateTime sunsetTime;
|
||||
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 getSunriseTime() {
|
||||
return sunriseTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets location sunrise time.
|
||||
* @param sunriseTime sunrise time
|
||||
*/
|
||||
public void setSunriseTime(LocalDateTime sunriseTime) {
|
||||
this.sunriseTime = sunriseTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns location sunset time.
|
||||
* @return sunset time
|
||||
*/
|
||||
public LocalDateTime getSunsetTime() {
|
||||
return sunsetTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets location sunset time.
|
||||
* @param sunsetTime sunset time
|
||||
*/
|
||||
public void setSunsetTime(LocalDateTime sunsetTime) {
|
||||
this.sunsetTime = sunsetTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(sunriseTime, location.sunriseTime) &&
|
||||
Objects.equals(sunsetTime, location.sunsetTime) &&
|
||||
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, sunriseTime, sunsetTime, 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,33 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MetaData {
|
||||
@JsonProperty("pod")
|
||||
private DayTime partOfDay;
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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 threeHourLevel;
|
||||
|
||||
private Rain(double threeHourLevel) {
|
||||
this.threeHourLevel = threeHourLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link Rain} object with correctness check.
|
||||
* @param threeHourLevel 3-hour rain level value
|
||||
* @return rain object.
|
||||
*/
|
||||
public static Rain withThreeHourLevelValue(double threeHourLevel) {
|
||||
if (threeHourLevel < 0) {
|
||||
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||
}
|
||||
return new Rain(threeHourLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 3-hour rain level value.
|
||||
* @return 3-hour rain level value
|
||||
*/
|
||||
public double getThreeHourLevel() {
|
||||
return threeHourLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets 3-hour rain level value with correctness check.
|
||||
* @param threeHourLevel 3-hour rain level value
|
||||
*/
|
||||
public void setThreeHourLevel(double threeHourLevel) {
|
||||
if (threeHourLevel < 0) {
|
||||
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||
}
|
||||
this.threeHourLevel = threeHourLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.threeHourLevel, threeHourLevel) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(threeHourLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "3-hour rain level: " +
|
||||
threeHourLevel + ' ' +
|
||||
getUnit();
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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 threeHourLevel;
|
||||
|
||||
private Snow(double threeHourLevel) {
|
||||
this.threeHourLevel = threeHourLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link Snow} object with correctness check.
|
||||
* @param threeHourLevel 3-hour snow level value
|
||||
* @return snow object.
|
||||
*/
|
||||
public static Snow withThreeHourLevelValue(double threeHourLevel) {
|
||||
if (threeHourLevel < 0) {
|
||||
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||
}
|
||||
return new Snow(threeHourLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 3-hour snow level value.
|
||||
* @return 3-hour snow level value
|
||||
*/
|
||||
public double getThreeHourLevel() {
|
||||
return threeHourLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets 3-hour snow level value with correctness check.
|
||||
* @param threeHourLevel 3-hour snow level value
|
||||
*/
|
||||
public void setThreeHourLevel(double threeHourLevel) {
|
||||
if (threeHourLevel < 0) {
|
||||
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||
}
|
||||
this.threeHourLevel = threeHourLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.threeHourLevel, threeHourLevel) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(threeHourLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "3-hour snow level: " +
|
||||
threeHourLevel + ' ' +
|
||||
getUnit();
|
||||
}
|
||||
}
|
||||
-309
@@ -1,309 +0,0 @@
|
||||
/*
|
||||
* 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 LocalDateTime forecastTime;
|
||||
|
||||
private WeatherState weatherState;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 weather state.
|
||||
*
|
||||
* @return the weather state
|
||||
*/
|
||||
public WeatherState getWeatherState() {
|
||||
return weatherState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather state.
|
||||
*
|
||||
* @param weatherState the weather state
|
||||
*/
|
||||
public void setWeatherState(WeatherState weatherState) {
|
||||
this.weatherState = weatherState;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(forecastTime, that.forecastTime) &&
|
||||
Objects.equals(weatherState, that.weatherState) &&
|
||||
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(forecastTime, weatherState, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Timestamp: ");
|
||||
stringBuilder.append(forecastTimeISO);
|
||||
if (weatherState != null) {
|
||||
stringBuilder.append(", Weather: ");
|
||||
stringBuilder.append(weatherState.getDescription());
|
||||
}
|
||||
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.getThreeHourLevel());
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(rain.getUnit());
|
||||
}
|
||||
if (snow != null) {
|
||||
stringBuilder.append(", Snow: ");
|
||||
stringBuilder.append(snow.getThreeHourLevel());
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(snow.getUnit());
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.climatic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Root object for 30 days long daily forecasts.
|
||||
*/
|
||||
public interface ThirtyDaysDailyForecast {
|
||||
|
||||
/**
|
||||
* The location where the forecast belongs to.
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseLocation getLocation();
|
||||
|
||||
/**
|
||||
* The forecasts.
|
||||
* @return days
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<WeatherForecastDay> getWeatherForecasts();
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.climatic;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocationModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
public class ThirtyDaysDailyForecastModel implements ThirtyDaysDailyForecast {
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("city")
|
||||
private BaseLocationModel locationModel;
|
||||
@JsonProperty("list")
|
||||
private List<WeatherForecast> forecasts;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseLocation getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<WeatherForecastDay> getWeatherForecasts() {
|
||||
return forecasts.stream().map(WeatherForecastDay.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.climatic;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.RequiredPercentageDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.WindSpeedDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationValues;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyBasic;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyDetailed;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.BasicWind;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindSpeed;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
public class WeatherForecast implements WeatherForecastDay, DailyTemperature, BaseAtmosphericPressure, BasicWind, Humidity,
|
||||
PrecipitationValues, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("temp")
|
||||
private TemperatureDailyDetailed temperature;
|
||||
@JsonProperty("feels_like")
|
||||
private TemperatureDailyBasic feelsLike;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("humidity")
|
||||
private int humidityPercentage;
|
||||
@JsonProperty("pressure")
|
||||
private BigDecimal pressure;
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("clouds")
|
||||
private int clouds;
|
||||
@JsonDeserialize(using = WindSpeedDeserializer.class)
|
||||
@JsonProperty("speed")
|
||||
private WindSpeed speed;
|
||||
@JsonProperty("deg")
|
||||
private Integer directionDegrees;
|
||||
@JsonProperty("rain")
|
||||
private BigDecimal rain;
|
||||
@JsonProperty("snow")
|
||||
private BigDecimal snow;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DailyTemperature getTemperature() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BasicWind getWind() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorning() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDay() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEve() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNight() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMin() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMin).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMax() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMax).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorningFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDayFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEveFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNightFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseAtmosphericPressure getAtmosphericPressure() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public CloudCoverage getCloudCoverage() {
|
||||
return new Clouds(this.clouds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationValues getPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.climatic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationValues;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.BasicWind;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains forecast information for one day of the 30 day long climatic forecasts.
|
||||
*/
|
||||
public interface WeatherForecastDay extends TimeAware {
|
||||
/**
|
||||
* The temperature forecast.
|
||||
*
|
||||
* @return temps
|
||||
*/
|
||||
@JsonIgnore
|
||||
DailyTemperature getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity forecast.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure forecast.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The forecasted wind conditions.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
@JsonIgnore
|
||||
BasicWind getWind();
|
||||
|
||||
/**
|
||||
* The expected weather states.
|
||||
*
|
||||
* @return weather states
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The forecasted cloud coverage.
|
||||
*
|
||||
* @return clouds
|
||||
*/
|
||||
@JsonIgnore
|
||||
CloudCoverage getCloudCoverage();
|
||||
|
||||
/**
|
||||
* The forecasted precipitation.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationValues getPrecipitation();
|
||||
|
||||
/**
|
||||
* Information about sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.daily;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface for weather forecast data used by the SixteenDaysDailyForecast.
|
||||
*/
|
||||
public interface DailyWeather extends TimeAware {
|
||||
|
||||
/**
|
||||
* The temperature data,
|
||||
*
|
||||
* @return temp
|
||||
*/
|
||||
@JsonIgnore
|
||||
DailyTemperature getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The wind conditions.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedWindInfo getWind();
|
||||
|
||||
/**
|
||||
* The weather states.
|
||||
*
|
||||
* @return weather
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The cloud coverage.
|
||||
*
|
||||
* @return louds
|
||||
*/
|
||||
@JsonIgnore
|
||||
CloudCoverage getCloudCoverage();
|
||||
|
||||
/**
|
||||
* The precipitation.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationForecast getPrecipitation();
|
||||
|
||||
/**
|
||||
* The sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.daily;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the daily forecast for the next sixteen days
|
||||
*/
|
||||
public interface SixteenDaysDailyForecast {
|
||||
/**
|
||||
* Information about the location.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedLocationInfo getLocation();
|
||||
|
||||
/**
|
||||
* The daily forecasts.
|
||||
*
|
||||
* @return forecasts
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<DailyWeather> getWeatherForecasts();
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.daily;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"cnt"})
|
||||
public class SixteenDaysDailyForecastModel implements SixteenDaysDailyForecast {
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("city")
|
||||
private DetailedLocationModel locationModel;
|
||||
@JsonProperty("list")
|
||||
private List<WeatherForecast> forecasts;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedLocationInfo getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<DailyWeather> getWeatherForecasts() {
|
||||
return forecasts.stream().map(DailyWeather.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.daily;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.PercentageZeroToOneDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.RequiredPercentageDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.WindSpeedDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.BaseAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.DailyTemperature;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyBasic;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureDailyDetailed;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindSpeed;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
public class WeatherForecast
|
||||
implements DailyWeather, DailyTemperature, BaseAtmosphericPressure, DetailedWindInfo, Humidity, PrecipitationForecast, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("temp")
|
||||
private TemperatureDailyDetailed temperature;
|
||||
@JsonProperty("feels_like")
|
||||
private TemperatureDailyBasic feelsLike;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("humidity")
|
||||
private int humidityPercentage;
|
||||
@JsonProperty("pressure")
|
||||
private BigDecimal pressure;
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("clouds")
|
||||
private int clouds;
|
||||
@JsonDeserialize(using = WindSpeedDeserializer.class)
|
||||
@JsonProperty("speed")
|
||||
private WindSpeed speed;
|
||||
@JsonProperty("deg")
|
||||
private Integer directionDegrees;
|
||||
@JsonDeserialize(using = WindSpeedDeserializer.class)
|
||||
@JsonProperty("gust")
|
||||
private WindSpeed gust;
|
||||
@JsonProperty("rain")
|
||||
private BigDecimal rain;
|
||||
@JsonProperty("snow")
|
||||
private BigDecimal snow;
|
||||
@JsonDeserialize(using = PercentageZeroToOneDeserializer.class)
|
||||
@JsonProperty("pop")
|
||||
private Integer probabilityOfPrecipitation;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DailyTemperature getTemperature() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedWindInfo getWind() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorning() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDay() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEve() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNight() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMin() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMin).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMax() {
|
||||
return Optional.ofNullable(temperature).map(TemperatureDailyDetailed::getMax).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getMorningFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getMorning).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getDayFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getEveFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getEve).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureValue getNightFeelsLike() {
|
||||
return Optional.ofNullable(feelsLike).map(TemperatureDailyBasic::getNight).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseAtmosphericPressure getAtmosphericPressure() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public CloudCoverage getCloudCoverage() {
|
||||
return new Clouds(this.clouds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationForecast getPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the 3 hours forecast for the next five days
|
||||
*/
|
||||
public interface FiveDaysThreeHoursForecast {
|
||||
/**
|
||||
* Information about the location.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedLocationInfo getLocation();
|
||||
|
||||
/**
|
||||
* The expected sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
|
||||
/**
|
||||
* The 3-hourly forecasts.
|
||||
*
|
||||
* @return forecasts
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<ThreeHourWeather> getWeatherForecasts();
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"cnt"})
|
||||
public class FiveDaysThreeHoursForecastModel implements FiveDaysThreeHoursForecast {
|
||||
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("city")
|
||||
private LocationModel locationModel;
|
||||
@JsonProperty("list")
|
||||
private List<WeatherForecast> forecasts;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedLocationInfo getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<ThreeHourWeather> getWeatherForecasts() {
|
||||
return forecasts.stream().map(ThreeHourWeather.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.DetailedLocationModel;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Represents location information.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class LocationModel extends DetailedLocationModel implements DetailedLocationInfo, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Represents snow/rain information.
|
||||
*/
|
||||
@Data
|
||||
public class Precipitation {
|
||||
@JsonProperty("3h")
|
||||
private BigDecimal threeHourLevel;
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Weather forecasts for 3 hours.
|
||||
*/
|
||||
public interface ThreeHourWeather extends TimeAware {
|
||||
/**
|
||||
* The temperature forecast.
|
||||
*
|
||||
* @return temperature
|
||||
*/
|
||||
@JsonIgnore
|
||||
TemperatureWithRange getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity forecast.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure forecast.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The wind forecast.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedWindInfo getWind();
|
||||
|
||||
/**
|
||||
* The weather states.
|
||||
*
|
||||
* @return states
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The forecasted cloud cover.
|
||||
*
|
||||
* @return clouds
|
||||
*/
|
||||
CloudCoverage getClouds();
|
||||
|
||||
/**
|
||||
* The precipitation forecast.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationForecast getThreeHoursPrecipitation();
|
||||
|
||||
/**
|
||||
* The visibility forecast.
|
||||
*
|
||||
* @return visibility
|
||||
*/
|
||||
Visibility getVisibility();
|
||||
|
||||
/**
|
||||
* The part of day.
|
||||
*
|
||||
* @return part of day
|
||||
*/
|
||||
@JsonIgnore
|
||||
DayTime getPartOfDay();
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.free;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.PercentageZeroToOneDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.VisibilityDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.MetaData;
|
||||
import com.github.prominence.openweathermap.api.model.generic.MainMetrics;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"dt_txt"})
|
||||
public class WeatherForecast implements TimeAware, ThreeHourWeather, PrecipitationForecast {
|
||||
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("main")
|
||||
private MainMetrics mainMetrics;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonProperty("clouds")
|
||||
private Clouds clouds;
|
||||
@JsonProperty("wind")
|
||||
private WindModel windModel;
|
||||
@JsonProperty("rain")
|
||||
private Precipitation rainModel;
|
||||
@JsonProperty("snow")
|
||||
private Precipitation snowModel;
|
||||
@JsonDeserialize(using = VisibilityDeserializer.class)
|
||||
@JsonProperty("visibility")
|
||||
private Visibility visibility;
|
||||
@JsonDeserialize(using = PercentageZeroToOneDeserializer.class)
|
||||
@JsonProperty("pop")
|
||||
private Integer probabilityOfPrecipitation;
|
||||
@JsonProperty("sys")
|
||||
private MetaData sysMeta;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureWithRange getTemperature() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedAtmosphericPressure getAtmosphericPressure() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedWindInfo getWind() {
|
||||
return windModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DayTime getPartOfDay() {
|
||||
return Optional.ofNullable(sysMeta).map(MetaData::getPartOfDay).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationForecast getThreeHoursPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getRain() {
|
||||
return Optional.ofNullable(rainModel)
|
||||
.map(Precipitation::getThreeHourLevel)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getSnow() {
|
||||
return Optional.ofNullable(snowModel)
|
||||
.map(Precipitation::getThreeHourLevel)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudCoverage getClouds() {
|
||||
return clouds;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the hourly forecast for the next four days
|
||||
*/
|
||||
public interface FourDaysHourlyForecast {
|
||||
|
||||
/**
|
||||
* Information about the location.
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@JsonIgnore
|
||||
BaseLocation getLocation();
|
||||
|
||||
/**
|
||||
* The expected sunlight stages.
|
||||
*
|
||||
* @return sunlight
|
||||
*/
|
||||
@JsonIgnore
|
||||
SunlightStages getSunlightStages();
|
||||
|
||||
/**
|
||||
* The hourly forecasts.
|
||||
*
|
||||
* @return hours
|
||||
*/
|
||||
@JsonIgnore
|
||||
List<HourlyWeather> getWeatherForecasts();
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Represents information about forecast for different timestamps.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"cnt"})
|
||||
public class FourDaysHourlyForecastModel implements FourDaysHourlyForecast {
|
||||
|
||||
@JsonProperty("cod")
|
||||
private long cod;
|
||||
@JsonProperty("message")
|
||||
private BigDecimal message;
|
||||
@JsonProperty("list")
|
||||
private List<HourlyWeatherForecast> forecasts;
|
||||
@JsonProperty("city")
|
||||
private LocationModel locationModel;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BaseLocation getLocation() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public SunlightStages getSunlightStages() {
|
||||
return locationModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public List<HourlyWeather> getWeatherForecasts() {
|
||||
return forecasts.stream().map(HourlyWeather.class::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Forecast details for a single hour.
|
||||
*/
|
||||
public interface HourlyWeather extends TimeAware {
|
||||
/**
|
||||
* The temperature forecast.
|
||||
*
|
||||
* @return temperature
|
||||
*/
|
||||
@JsonIgnore
|
||||
TemperatureWithRange getTemperature();
|
||||
|
||||
/**
|
||||
* The humidity forecast.
|
||||
*
|
||||
* @return humidity
|
||||
*/
|
||||
@JsonIgnore
|
||||
Humidity getHumidity();
|
||||
|
||||
/**
|
||||
* The atmospheric pressure forecast.
|
||||
*
|
||||
* @return pressure
|
||||
*/
|
||||
@JsonIgnore
|
||||
DetailedAtmosphericPressure getAtmosphericPressure();
|
||||
|
||||
/**
|
||||
* The wind forecast.
|
||||
*
|
||||
* @return wind
|
||||
*/
|
||||
DetailedWindInfo getWind();
|
||||
|
||||
/**
|
||||
* The weather states.
|
||||
*
|
||||
* @return states
|
||||
*/
|
||||
List<WeatherCondition> getWeatherStates();
|
||||
|
||||
/**
|
||||
* The forecasted cloud cover.
|
||||
*
|
||||
* @return clouds
|
||||
*/
|
||||
CloudCoverage getClouds();
|
||||
|
||||
/**
|
||||
* The precipitation forecast.
|
||||
*
|
||||
* @return precipitation
|
||||
*/
|
||||
@JsonIgnore
|
||||
PrecipitationForecast getHourlyPrecipitation();
|
||||
|
||||
/**
|
||||
* The visibility forecast.
|
||||
*
|
||||
* @return visibility
|
||||
*/
|
||||
Visibility getVisibility();
|
||||
|
||||
/**
|
||||
* The part of day.
|
||||
*
|
||||
* @return part of day
|
||||
*/
|
||||
@JsonIgnore
|
||||
DayTime getPartOfDay();
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.PercentageZeroToOneDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.VisibilityDeserializer;
|
||||
import com.github.prominence.openweathermap.api.enums.DayTime;
|
||||
import com.github.prominence.openweathermap.api.enums.WeatherCondition;
|
||||
import com.github.prominence.openweathermap.api.model.forecast.MetaData;
|
||||
import com.github.prominence.openweathermap.api.model.generic.MainMetrics;
|
||||
import com.github.prominence.openweathermap.api.model.generic.TimeAware;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.CloudCoverage;
|
||||
import com.github.prominence.openweathermap.api.model.generic.clouds.Clouds;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.BasePrecipitation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.PrecipitationForecast;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import com.github.prominence.openweathermap.api.model.generic.visibility.Visibility;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.DetailedWindInfo;
|
||||
import com.github.prominence.openweathermap.api.model.generic.wind.WindModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Represents weather forecast information for a particular timestamp.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"dt_txt"})
|
||||
public class HourlyWeatherForecast implements TimeAware, HourlyWeather, PrecipitationForecast {
|
||||
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("dt")
|
||||
private OffsetDateTime forecastTime;
|
||||
@JsonProperty("main")
|
||||
private MainMetrics mainMetrics;
|
||||
@JsonProperty("weather")
|
||||
private List<WeatherCondition> weatherStates = new ArrayList<>();
|
||||
@JsonProperty("clouds")
|
||||
private Clouds clouds;
|
||||
@JsonProperty("wind")
|
||||
private WindModel windModel;
|
||||
@JsonProperty("rain")
|
||||
private BasePrecipitation rainModel;
|
||||
@JsonProperty("snow")
|
||||
private BasePrecipitation snowModel;
|
||||
@JsonDeserialize(using = VisibilityDeserializer.class)
|
||||
@JsonProperty("visibility")
|
||||
private Visibility visibility;
|
||||
@JsonDeserialize(using = PercentageZeroToOneDeserializer.class)
|
||||
@JsonProperty("pop")
|
||||
private Integer probabilityOfPrecipitation;
|
||||
@JsonProperty("sys")
|
||||
private MetaData sysMeta;
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public TemperatureWithRange getTemperature() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Humidity getHumidity() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedAtmosphericPressure getAtmosphericPressure() {
|
||||
return mainMetrics;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DetailedWindInfo getWind() {
|
||||
return windModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public PrecipitationForecast getHourlyPrecipitation() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getRain() {
|
||||
return Optional.ofNullable(getRainModel()).map(BasePrecipitation::getOneHourLevel).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public BigDecimal getSnow() {
|
||||
return Optional.ofNullable(getSnowModel()).map(BasePrecipitation::getOneHourLevel).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudCoverage getClouds() {
|
||||
return clouds;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public DayTime getPartOfDay() {
|
||||
return Optional.ofNullable(sysMeta).map(MetaData::getPartOfDay).orElse(null);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.hourly;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.EpochSecondsDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocation;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.BaseLocationModel;
|
||||
import com.github.prominence.openweathermap.api.model.generic.location.SunlightStages;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Represents location information.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class LocationModel extends BaseLocationModel implements BaseLocation, SunlightStages {
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunrise")
|
||||
private OffsetDateTime sunriseTime;
|
||||
@JsonDeserialize(using = EpochSecondsDeserializer.class)
|
||||
@JsonProperty("sunset")
|
||||
private OffsetDateTime sunsetTime;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.RequiredPercentageDeserializer;
|
||||
import com.github.prominence.openweathermap.api.deserializer.TemperatureValueDeserializer;
|
||||
import com.github.prominence.openweathermap.api.model.generic.precipitation.Humidity;
|
||||
import com.github.prominence.openweathermap.api.model.generic.pressure.DetailedAtmosphericPressure;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureValue;
|
||||
import com.github.prominence.openweathermap.api.model.generic.temperature.TemperatureWithRange;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Contains Temperature and AtmosphericPressure.
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(value = {"temp_kf"})
|
||||
public class MainMetrics implements TemperatureWithRange, Humidity, DetailedAtmosphericPressure {
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("temp")
|
||||
private TemperatureValue temperature;
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("temp_max")
|
||||
private TemperatureValue max;
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("temp_min")
|
||||
private TemperatureValue min;
|
||||
@JsonDeserialize(using = TemperatureValueDeserializer.class)
|
||||
@JsonProperty("feels_like")
|
||||
private TemperatureValue feelsLike;
|
||||
@JsonDeserialize(using = RequiredPercentageDeserializer.class)
|
||||
@JsonProperty("humidity")
|
||||
private int humidityPercentage;
|
||||
@JsonProperty("pressure")
|
||||
private BigDecimal pressure;
|
||||
@JsonProperty("sea_level")
|
||||
private BigDecimal seaLevel;
|
||||
@JsonProperty("grnd_level")
|
||||
private BigDecimal groundLevel;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Indicates that the implementation keeps track of the forecast time.
|
||||
*/
|
||||
public interface TimeAware {
|
||||
/**
|
||||
* Returns the time when the data was calculated.
|
||||
*
|
||||
* @return timestamp
|
||||
*/
|
||||
OffsetDateTime getForecastTime();
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.clouds;
|
||||
|
||||
public interface CloudCoverage {
|
||||
|
||||
Integer getCoveragePercentage();
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.clouds;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* The Clouds type represents cloudiness value percentage.
|
||||
* Its value can only be an integer in [0, 100] range.
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Clouds implements CloudCoverage {
|
||||
@JsonProperty("all")
|
||||
private Integer coveragePercentage;
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
/**
|
||||
* Contains basic location information.
|
||||
*/
|
||||
public interface BaseLocation extends CoordinateAware {
|
||||
|
||||
/**
|
||||
* The time zone of the location.
|
||||
*
|
||||
* @return time zone
|
||||
*/
|
||||
ZoneOffset getTimeZone();
|
||||
|
||||
/**
|
||||
* The Id of the city.
|
||||
*
|
||||
* @return city Id
|
||||
*/
|
||||
long getCityId();
|
||||
|
||||
/**
|
||||
* The name of the city.
|
||||
*
|
||||
* @return city name
|
||||
*/
|
||||
String getCityName();
|
||||
|
||||
/**
|
||||
* The country code of the location.
|
||||
*
|
||||
* @return country code
|
||||
*/
|
||||
String getCountryCode();
|
||||
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.github.prominence.openweathermap.api.deserializer.ZoneOffsetDeserializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
/**
|
||||
* Represents location information.
|
||||
*/
|
||||
@Data
|
||||
public class BaseLocationModel implements BaseLocation {
|
||||
@JsonProperty("id")
|
||||
private long cityId;
|
||||
@JsonProperty("name")
|
||||
private String cityName;
|
||||
@JsonProperty("coord")
|
||||
private Coordinates coordinates;
|
||||
@JsonProperty("country")
|
||||
private String countryCode;
|
||||
@JsonDeserialize(using = ZoneOffsetDeserializer.class)
|
||||
@JsonProperty("timezone")
|
||||
private ZoneOffset timeZone;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
/**
|
||||
* Indicates that the object can provide coordinate information.
|
||||
*/
|
||||
public interface CoordinateAware {
|
||||
|
||||
/**
|
||||
* The coordinates of the data source.
|
||||
*
|
||||
* @return coordinated
|
||||
*/
|
||||
Coordinates getCoordinates();
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Represents some location by its latitude and longitude.
|
||||
*/
|
||||
@Data
|
||||
public class Coordinates {
|
||||
@JsonProperty("lat")
|
||||
private final double latitude;
|
||||
@JsonProperty("lon")
|
||||
private final double longitude;
|
||||
|
||||
@JsonCreator
|
||||
public Coordinates(@JsonProperty("lat") double latitude, @JsonProperty("lon") 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].");
|
||||
}
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Alexey Zinchenko
|
||||
* Copyright (c) 2021-present 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
|
||||
@@ -20,20 +20,20 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
package com.github.prominence.openweathermap.api.model.generic.location;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents coordinate rectangle by its bottom-left and top-right coordinates.
|
||||
*/
|
||||
public class CoordinateRectangle {
|
||||
public class CoordinatesRectangle {
|
||||
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) {
|
||||
private CoordinatesRectangle(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) {
|
||||
this.longitudeLeft = longitudeLeft;
|
||||
this.latitudeBottom = latitudeBottom;
|
||||
this.longitudeRight = longitudeRight;
|
||||
@@ -41,21 +41,21 @@ public class CoordinateRectangle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for {@link CoordinateRectangle} creation with correctness check.
|
||||
* Method for {@link CoordinatesRectangle} 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) {
|
||||
public static CoordinatesRectangle 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);
|
||||
return new CoordinatesRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,8 +101,8 @@ public class CoordinateRectangle {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof CoordinateRectangle)) return false;
|
||||
CoordinateRectangle rectangle = (CoordinateRectangle) o;
|
||||
if (!(o instanceof CoordinatesRectangle)) return false;
|
||||
CoordinatesRectangle rectangle = (CoordinatesRectangle) o;
|
||||
return Double.compare(rectangle.longitudeLeft, longitudeLeft) == 0 &&
|
||||
Double.compare(rectangle.latitudeBottom, latitudeBottom) == 0 &&
|
||||
Double.compare(rectangle.longitudeRight, longitudeRight) == 0 &&
|
||||
@@ -187,14 +187,14 @@ public class CoordinateRectangle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds {@link CoordinateRectangle} object with correctness check.
|
||||
* @return {@link CoordinateRectangle} built object.
|
||||
* Builds {@link CoordinatesRectangle} object with correctness check.
|
||||
* @return {@link CoordinatesRectangle} built object.
|
||||
*/
|
||||
public CoordinateRectangle build() {
|
||||
public CoordinatesRectangle 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);
|
||||
return new CoordinatesRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2021-present 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.generic.location;
|
||||
|
||||
/**
|
||||
* Location information containing additional details about population.
|
||||
*/
|
||||
public interface DetailedLocationInfo extends BaseLocation {
|
||||
|
||||
/**
|
||||
* The number of people living at this location.
|
||||
*
|
||||
* @return population
|
||||
*/
|
||||
Long getPopulation();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user