mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 19:26:43 +03:00
Compare commits
54 Commits
2.0.0
...
7f0866ffa2
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f0866ffa2 | |||
| 4fdb48986e | |||
| 8ca55b15f7 | |||
| 5ca31780da | |||
| 91a5acdb43 | |||
| 3f5b7f6649 | |||
| 9c2a127703 | |||
| e6833c3007 | |||
| d1bac609e8 | |||
| a17f687976 | |||
| 1ae02e0e49 | |||
| 46602e1f93 | |||
| 2553f13fbe | |||
| 905d3876c3 | |||
| 45f0b494b3 | |||
| 93b6b357c1 | |||
| c0dd184965 | |||
| 08d0aa091d | |||
| 93ae514550 | |||
| 47d52d953a | |||
| 2a15788569 | |||
| 37d7a2b3f5 | |||
| 6790848c32 | |||
| ec988c5f26 | |||
| 7b8d46bb7a | |||
| 6ae281af0d | |||
| 23a1fa5a7b | |||
| 1cac951aaa | |||
| 58e648be42 | |||
| f30bcad5dc | |||
| 5793722181 | |||
| 40462397c1 | |||
| 44b543e65c | |||
| 13b20fc7e9 | |||
| 2a531dd683 | |||
| 1e1054903e | |||
| ff5b6c7a33 | |||
| db1cf858d8 | |||
| c2cc110dab | |||
| d4c2472254 | |||
| 380e3e458b | |||
| 246c07db97 | |||
| f19a627313 | |||
| 6438c323ff | |||
| 1cbff68338 | |||
| 1e08f4f8ae | |||
| bfa15fd9fe | |||
| 3c8b00eae1 | |||
| f2c672b864 | |||
| e594ffb7ad | |||
| 4cfa8ab843 | |||
| 196f9ec289 | |||
| 4998663298 | |||
| f5d202aee3 |
+13
@@ -0,0 +1,13 @@
|
|||||||
|
container:
|
||||||
|
image: gradle:jdk17
|
||||||
|
|
||||||
|
testCoverage_task:
|
||||||
|
gradle_cache:
|
||||||
|
folder: ~/.gradle/caches
|
||||||
|
testCoverage_script: gradle jacocoTestReport && bash <(curl -s https://codecov.io/bash)
|
||||||
|
cleanup_before_cache_script:
|
||||||
|
- rm -rf ~/.gradle/caches/$GRADLE_VERSION/
|
||||||
|
- rm -rf ~/.gradle/caches/transforms-1
|
||||||
|
- rm -rf ~/.gradle/caches/journal-1
|
||||||
|
- rm -rf ~/.gradle/caches/jars-3/*/buildSrc.jar
|
||||||
|
- find ~/.gradle/caches/ -name "*.lock" -type f -delete
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: maven
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
time: "03:00"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
target-branch: dev
|
||||||
@@ -13,10 +13,10 @@ name: "CodeQL"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ dev ]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ master ]
|
branches: [ dev ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '27 20 * * 1'
|
- cron: '27 20 * * 1'
|
||||||
|
|
||||||
|
|||||||
+5
-23
@@ -1,24 +1,6 @@
|
|||||||
# Compiled class file
|
|
||||||
*.class
|
|
||||||
|
|
||||||
# Log file
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# BlueJ files
|
|
||||||
*.ctxt
|
|
||||||
|
|
||||||
# Package Files #
|
|
||||||
*.jar
|
|
||||||
*.war
|
|
||||||
*.nar
|
|
||||||
*.ear
|
|
||||||
*.zip
|
|
||||||
*.tar.gz
|
|
||||||
*.rar
|
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
|
||||||
hs_err_pid*
|
|
||||||
|
|
||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea
|
||||||
target/
|
.gradle
|
||||||
|
build
|
||||||
|
target
|
||||||
|
out
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
language: java
|
|
||||||
|
|
||||||
jdk:
|
|
||||||
- openjdk8
|
|
||||||
- openjdk11
|
|
||||||
|
|
||||||
install: mvn install -DskipTests -Dgpg.skip -B
|
|
||||||
script: mvn test -Dmaven.skip.deploy=true -B
|
|
||||||
|
|
||||||
after_success:
|
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
|
||||||
@@ -1,24 +1,34 @@
|
|||||||
# OpenWeatherMap Java API [![Build Status][ci-shield]][ci-link] [![codecov][codecov-shield]][codecov-link]
|
# OpenWeatherMap Java API [![Build Status][ci-shield]][ci-link] [![codecov][codecov-shield]][codecov-link] [![FOSSA Status][FOSSA-shield]][FOSSA-link]
|
||||||
Java API for OpenWeatherMap services.
|
Java API for OpenWeatherMap services.
|
||||||
|
|
||||||
### Implemented features:
|
### Implemented features:
|
||||||
Free:
|
Free:
|
||||||
* Current weather data
|
* Current weather data
|
||||||
* 5 day / 3-hour forecast
|
* 5 day / 3-hour forecast
|
||||||
|
* One Call API
|
||||||
|
* Air pollution
|
||||||
|
* Geocoding API
|
||||||
|
|
||||||
|
Paid:
|
||||||
|
* Hourly Forecast 4 days
|
||||||
|
* Daily Forecast 16 days
|
||||||
|
* Climatic 30 days
|
||||||
|
|
||||||
|
Other:
|
||||||
|
* Request timeout settings
|
||||||
|
|
||||||
### Will be implemented later:
|
### Will be implemented later:
|
||||||
|
|
||||||
Free:
|
Free:
|
||||||
* One Call API
|
|
||||||
* Air pollution
|
|
||||||
* Geocoding API
|
|
||||||
* Weather Stations
|
* Weather Stations
|
||||||
* Weather Triggers
|
* Weather Triggers
|
||||||
|
|
||||||
Paid:
|
Paid:
|
||||||
* Daily Forecast 16 days
|
* Climatic Forecast 30 days
|
||||||
* Hourly Forecast 4 days
|
* Bulk Downloading
|
||||||
* probably others...
|
* Solar Radiation API
|
||||||
|
* Global Weather Alerts / Push notifications
|
||||||
|
* Road Risk API
|
||||||
|
|
||||||
### Maven coordinates:
|
### Maven coordinates:
|
||||||
|
|
||||||
@@ -26,14 +36,46 @@ Paid:
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<repositories>
|
||||||
|
...
|
||||||
|
<!-- Repository for snapshot versions -->
|
||||||
|
<repository>
|
||||||
|
<id>oss.sonatype.org-snapshot</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
...
|
||||||
|
</repositories>
|
||||||
|
```
|
||||||
|
|
||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.0.0')
|
implementation 'com.github.prominence:openweathermap-api:3.0.0-SNAPSHOT'
|
||||||
|
```
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
repositories {
|
||||||
|
...
|
||||||
|
// Repository for snapshot versions
|
||||||
|
maven {
|
||||||
|
url "https://oss.sonatype.org/content/repositories/snapshots"
|
||||||
|
mavenContent {
|
||||||
|
snapshotsOnly()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
@@ -41,14 +83,22 @@ compile('com.github.prominence:openweathermap-api:2.0.0')
|
|||||||
* [OpenWeatherMap Java API - 1.1](docs/Release_1.1.md)
|
* [OpenWeatherMap Java API - 1.1](docs/Release_1.1.md)
|
||||||
* [OpenWeatherMap Java API - 1.2](docs/Release_1.2.md)
|
* [OpenWeatherMap Java API - 1.2](docs/Release_1.2.md)
|
||||||
* [OpenWeatherMap Java API - 2.0.0](docs/Release_2.0.0.md)
|
* [OpenWeatherMap Java API - 2.0.0](docs/Release_2.0.0.md)
|
||||||
|
* [OpenWeatherMap Java API - 2.0.1](docs/Release_2.0.1.md)
|
||||||
|
* [OpenWeatherMap Java API - 2.1.0](docs/Release_2.1.0.md)
|
||||||
|
* [OpenWeatherMap Java API - 2.1.1](docs/Release_2.1.1.md)
|
||||||
|
* [OpenWeatherMap Java API - 2.2.0](docs/Release_2.2.0.md)
|
||||||
|
* [OpenWeatherMap Java API - 2.3.0](docs/Release_2.3.0.md)
|
||||||
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
|
* [OpenWeatherMap Java API - SNAPSHOT](docs/SNAPSHOT.md)
|
||||||
|
|
||||||
### License
|
### License
|
||||||
MIT
|
MIT
|
||||||
|
|
||||||
[ci-shield]: https://travis-ci.org/Prominence/openweathermap-java-api.svg?branch=dev
|
[ci-shield]: https://api.cirrus-ci.com/github/Prominence/openweathermap-java-api.svg?branch=dev
|
||||||
[ci-link]: https://travis-ci.org/Prominence/openweathermap-java-api
|
[ci-link]: https://api.cirrus-ci.com/github/Prominence/openweathermap-java-api
|
||||||
|
|
||||||
|
|
||||||
[codecov-shield]: https://codecov.io/gh/Prominence/openweathermap-java-api/branch/dev/graph/badge.svg
|
[codecov-shield]: https://codecov.io/gh/Prominence/openweathermap-java-api/branch/dev/graph/badge.svg
|
||||||
[codecov-link]: https://codecov.io/gh/Prominence/openweathermap-java-api
|
[codecov-link]: https://codecov.io/gh/Prominence/openweathermap-java-api
|
||||||
|
|
||||||
|
[FOSSA-shield]: https://app.fossa.com/api/projects/git%2Bgithub.com%2FProminence%2Fopenweathermap-java-api.svg?type=shield
|
||||||
|
[FOSSA-link]: https://app.fossa.com/projects/git%2Bgithub.com%2FProminence%2Fopenweathermap-java-api?ref=badge_shield
|
||||||
|
|||||||
+122
@@ -0,0 +1,122 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java-library'
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'signing'
|
||||||
|
id 'jacoco'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
maven {
|
||||||
|
url = uri('https://repo.maven.apache.org/maven2/')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
|
||||||
|
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'
|
||||||
|
|
||||||
|
annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:0.4.2'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.github.prominence'
|
||||||
|
version = '3.0.0-SNAPSHOT'
|
||||||
|
description = 'Java OpenWeatherMap API'
|
||||||
|
|
||||||
|
configure([tasks.compileJava]) {
|
||||||
|
sourceCompatibility = 17 // for the IDE support
|
||||||
|
options.release = 8
|
||||||
|
|
||||||
|
javaCompiler = javaToolchains.compilerFor {
|
||||||
|
languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ext {
|
||||||
|
isReleaseVersion = !version.endsWith("SNAPSHOT")
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
mavenJava(MavenPublication) {
|
||||||
|
from components.java
|
||||||
|
|
||||||
|
pom {
|
||||||
|
name = 'Java OpenWeatherMap API'
|
||||||
|
description = 'Java API for OpenWeatherMap services.'
|
||||||
|
url = 'https://github.com/Prominence/openweathermap-java-api'
|
||||||
|
|
||||||
|
licenses {
|
||||||
|
license {
|
||||||
|
name = 'MIT License'
|
||||||
|
url = 'https://www.opensource.org/licenses/mit-license.php'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
developers {
|
||||||
|
developer {
|
||||||
|
id = 'Prominence'
|
||||||
|
name = 'Alexey Zinchenko'
|
||||||
|
email = 'alexey.zinchenko@protonmail.com'
|
||||||
|
url = 'https://github.com/prominence'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scm {
|
||||||
|
connection = 'scm:git:git://github.com/Prominence/openweathermap-java-api.git'
|
||||||
|
developerConnection = 'scm:git:git@github.com:prominence/openweathermap-java-api.git'
|
||||||
|
url = 'https://github.com/Prominence/openweathermap-java-api'
|
||||||
|
}
|
||||||
|
issueManagement {
|
||||||
|
url = 'https://github.com/Prominence/openweathermap-java-api/issues'
|
||||||
|
system = 'GitHub Issues'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
credentials {
|
||||||
|
username = project.findProperty('ossrhUsername')
|
||||||
|
password = project.findProperty('ossrhPassword')
|
||||||
|
}
|
||||||
|
|
||||||
|
url = isReleaseVersion ?
|
||||||
|
'https://oss.sonatype.org/service/local/staging/deploy/maven2/' :
|
||||||
|
'https://oss.sonatype.org/content/repositories/snapshots/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signing {
|
||||||
|
sign publishing.publications.mavenJava
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(GenerateModuleMetadata) {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
jacocoTestReport {
|
||||||
|
dependsOn test // tests are required to run before generating the report
|
||||||
|
reports {
|
||||||
|
csv.required = false
|
||||||
|
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:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:1.0')
|
implementation 'com.github.prominence:openweathermap-api:1.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:1.1')
|
implementation 'com.github.prominence:openweathermap-api:1.1'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:1.2')
|
implementation 'com.github.prominence:openweathermap-api:1.2'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.0.0')
|
implementation 'com.github.prominence:openweathermap-api:2.0.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
@@ -79,7 +79,7 @@ final Weather weather = openWeatherClient
|
|||||||
final List<Weather> weatherList = openWeatherClient
|
final List<Weather> weatherList = openWeatherClient
|
||||||
.currentWeather()
|
.currentWeather()
|
||||||
.multiple()
|
.multiple()
|
||||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
.language(Language.GERMAN)
|
.language(Language.GERMAN)
|
||||||
.unitSystem(UnitSystem.IMPERIAL)
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
|
|||||||
@@ -0,0 +1,253 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3-hour forecast
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
implementation 'com.github.prominence:openweathermap-api:2.0.1'
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently, available APIs are:
|
||||||
|
* `currentWeather()`
|
||||||
|
* `forecast5Day3HourStep()`
|
||||||
|
|
||||||
|
Default(more or less) customization points:
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
// response language
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
...
|
||||||
|
// response units of measure
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Available output forms:
|
||||||
|
* `asJava()`
|
||||||
|
* `asJSON()`
|
||||||
|
|
||||||
|
Additional output forms, available for several APIs:
|
||||||
|
* `asXML()`
|
||||||
|
* `asHTML()`
|
||||||
|
|
||||||
|
_All response forms can be in **sync** and **async** variants._
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final String weatherJson = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Weather weather = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final List<Weather> weatherList = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.multiple()
|
||||||
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
|
.language(Language.GERMAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byZipCodeAndCountry("220015", "by")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||||
|
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||||
|
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||||
|
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||||
|
| `toString()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3-hour forecast
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final Forecast forecast = openWeatherClient
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastJson = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("New York", "NY", "US")
|
||||||
|
.language(Language.SPANISH)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
CompletableFuture<String> forecastFuture = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityId(350001514)
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastXml = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byZipCodeInUSA("10005")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.request.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||||
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
A forecast for Minsk with 15 timestamps.
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getState()` | Returns short weather description. Example: `Clear`. |
|
||||||
|
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
||||||
|
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||||
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Language
|
||||||
|
| Constant | Description |
|
||||||
|
|-----------------------------------|-------------------------------|
|
||||||
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
|
| Language.CATALAN | Catalan language. |
|
||||||
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.GERMAN | German language. |
|
||||||
|
| Language.GREEK | Greek language. |
|
||||||
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
|
| Language.FINNISH | Finnish language. |
|
||||||
|
| Language.FRENCH | French language. |
|
||||||
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.CROATIAN | Croatian language. |
|
||||||
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.ITALIAN | Italian language. |
|
||||||
|
| Language.JAPANESE | Japanese language. |
|
||||||
|
| Language.KOREAN | Korean language. |
|
||||||
|
| Language.LATVIAN | Latvian language. |
|
||||||
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.DUTCH | Dutch language. |
|
||||||
|
| Language.POLISH | Polish language. |
|
||||||
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.ROMANIAN | Romanian language. |
|
||||||
|
| Language.RUSSIAN | Russian language. |
|
||||||
|
| Language.SWEDISH | Swedish language. |
|
||||||
|
| Language.SLOVAK | Slovak language. |
|
||||||
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.TURKISH | Turkish language. |
|
||||||
|
| Language.UKRANIAN | Ukrainian language. |
|
||||||
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
|
||||||
|
#### Unit
|
||||||
|
| Constant | Description |
|
||||||
|
|----------------------|------------------------------------------------|
|
||||||
|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||||
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
||||||
|
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||||
|
* junit:junit:4.13.1 (*test*)
|
||||||
@@ -0,0 +1,484 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3-hour forecast
|
||||||
|
* One Call API
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
implementation 'com.github.prominence:openweathermap-api:2.1.0'
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently, available APIs are:
|
||||||
|
* `currentWeather()`
|
||||||
|
* `forecast5Day3HourStep()`
|
||||||
|
* `oneCall()`
|
||||||
|
|
||||||
|
Default(more or less) customization points:
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
// response language
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
...
|
||||||
|
// response units of measure
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Available output forms:
|
||||||
|
* `asJava()`
|
||||||
|
* `asJSON()`
|
||||||
|
|
||||||
|
Additional output forms, available for several APIs:
|
||||||
|
* `asXML()`
|
||||||
|
* `asHTML()`
|
||||||
|
|
||||||
|
_All response forms can be in **sync** and **async** variants._
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final String weatherJson = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Weather weather = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final List<Weather> weatherList = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.multiple()
|
||||||
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
|
.language(Language.GERMAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byZipCodeAndCountry("220015", "by")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||||
|
| `toString()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3-hour forecast
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final Forecast forecast = openWeatherClient
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastJson = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("New York", "NY", "US")
|
||||||
|
.language(Language.SPANISH)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
CompletableFuture<String> forecastFuture = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityId(350001514)
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastXml = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byZipCodeInUSA("10005")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||||
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
A forecast for Minsk with 15 timestamps.
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||||
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
#### One Call API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|--------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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. |
|
||||||
|
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||||
|
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||||
|
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||||
|
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||||
|
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|------------------------------|--------------------------------------------------------|
|
||||||
|
| `getSenderName()` | Returns alert sender name. |
|
||||||
|
| `getEventName()` | Returns alert event name. |
|
||||||
|
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||||
|
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||||
|
| `getDescription()` | Returns alert description. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
|
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||||
|
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Language
|
||||||
|
| Constant | Description |
|
||||||
|
|-----------------------------------|-------------------------------|
|
||||||
|
| Language.AFRIKAANS | Afrikaans language. |
|
||||||
|
| Language.ALBANIAN | ALBANIAN language. |
|
||||||
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||||
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
|
| Language.CATALAN | Catalan language. |
|
||||||
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.DANISH | Danish language. |
|
||||||
|
| Language.GERMAN | German language. |
|
||||||
|
| Language.GREEK | Greek language. |
|
||||||
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.BASQUE | Basque language. |
|
||||||
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
|
| Language.FINNISH | Finnish language. |
|
||||||
|
| Language.FRENCH | French language. |
|
||||||
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.HEBREW | Hebrew language. |
|
||||||
|
| Language.HINDI | Hindi language. |
|
||||||
|
| Language.CROATIAN | Croatian language. |
|
||||||
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.INDONESIAN | Indonesian language. |
|
||||||
|
| Language.ITALIAN | Italian language. |
|
||||||
|
| Language.JAPANESE | Japanese language. |
|
||||||
|
| Language.KOREAN | Korean language. |
|
||||||
|
| Language.LATVIAN | Latvian language. |
|
||||||
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.NORWEGIAN | Norwegian language. |
|
||||||
|
| Language.DUTCH | Dutch language. |
|
||||||
|
| Language.POLISH | Polish language. |
|
||||||
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
||||||
|
| Language.ROMANIAN | Romanian language. |
|
||||||
|
| Language.RUSSIAN | Russian language. |
|
||||||
|
| Language.SWEDISH | Swedish language. |
|
||||||
|
| Language.SLOVAK | Slovak language. |
|
||||||
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.SERBIAN | Serbian language. |
|
||||||
|
| Language.THAI | Thai language. |
|
||||||
|
| Language.TURKISH | Turkish language. |
|
||||||
|
| Language.UKRANIAN | Ukrainian language. |
|
||||||
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
| Language.ZULU | Zulu language. |
|
||||||
|
|
||||||
|
#### Unit
|
||||||
|
| Constant | Description |
|
||||||
|
|----------------------|------------------------------------------------|
|
||||||
|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||||
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
||||||
|
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||||
|
* org.junit.jupiter:junit-jupiter-engine:5.7.1 (*test*)
|
||||||
|
* org.junit.platform:junit-platform-runner:1.7.1 (*test*)
|
||||||
@@ -0,0 +1,486 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3-hour forecast
|
||||||
|
* One Call API
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>2.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
implementation 'com.github.prominence:openweathermap-api:2.1.1'
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently, available APIs are:
|
||||||
|
* `currentWeather()`
|
||||||
|
* `forecast5Day3HourStep()`
|
||||||
|
* `oneCall()`
|
||||||
|
|
||||||
|
Default(more or less) customization points:
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
// response language
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
...
|
||||||
|
// response units of measure
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Available output forms:
|
||||||
|
* `asJava()`
|
||||||
|
* `asJSON()`
|
||||||
|
|
||||||
|
Additional output forms, available for several APIs:
|
||||||
|
* `asXML()`
|
||||||
|
* `asHTML()`
|
||||||
|
|
||||||
|
_All response forms can be in **sync** and **async** variants._
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final String weatherJson = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Weather weather = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final List<Weather> weatherList = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.multiple()
|
||||||
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
|
.language(Language.GERMAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byZipCodeAndCountry("220015", "by")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||||
|
| `toString()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3-hour forecast
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final Forecast forecast = openWeatherClient
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastJson = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("New York", "NY", "US")
|
||||||
|
.language(Language.SPANISH)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
CompletableFuture<String> forecastFuture = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityId(350001514)
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastXml = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byZipCodeInUSA("10005")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||||
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
A forecast for Minsk with 15 timestamps.
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||||
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
#### One Call API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|--------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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. |
|
||||||
|
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||||
|
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||||
|
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||||
|
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||||
|
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|------------------------------|--------------------------------------------------------|
|
||||||
|
| `getSenderName()` | Returns alert sender name. |
|
||||||
|
| `getEventName()` | Returns alert event name. |
|
||||||
|
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||||
|
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||||
|
| `getDescription()` | Returns alert description. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
|
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||||
|
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Language
|
||||||
|
| Constant | Description |
|
||||||
|
|-----------------------------------|-------------------------------|
|
||||||
|
| Language.AFRIKAANS | Afrikaans language. |
|
||||||
|
| Language.ALBANIAN | ALBANIAN language. |
|
||||||
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||||
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
|
| Language.CATALAN | Catalan language. |
|
||||||
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.DANISH | Danish language. |
|
||||||
|
| Language.GERMAN | German language. |
|
||||||
|
| Language.GREEK | Greek language. |
|
||||||
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.BASQUE | Basque language. |
|
||||||
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
|
| Language.FINNISH | Finnish language. |
|
||||||
|
| Language.FRENCH | French language. |
|
||||||
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.HEBREW | Hebrew language. |
|
||||||
|
| Language.HINDI | Hindi language. |
|
||||||
|
| Language.CROATIAN | Croatian language. |
|
||||||
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.INDONESIAN | Indonesian language. |
|
||||||
|
| Language.ITALIAN | Italian language. |
|
||||||
|
| Language.JAPANESE | Japanese language. |
|
||||||
|
| Language.KOREAN | Korean language. |
|
||||||
|
| Language.LATVIAN | Latvian language. |
|
||||||
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.NORWEGIAN | Norwegian language. |
|
||||||
|
| Language.DUTCH | Dutch language. |
|
||||||
|
| Language.POLISH | Polish language. |
|
||||||
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
||||||
|
| Language.ROMANIAN | Romanian language. |
|
||||||
|
| Language.RUSSIAN | Russian language. |
|
||||||
|
| Language.SWEDISH | Swedish language. |
|
||||||
|
| Language.SLOVAK | Slovak language. |
|
||||||
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.SERBIAN | Serbian language. |
|
||||||
|
| Language.THAI | Thai language. |
|
||||||
|
| Language.TURKISH | Turkish language. |
|
||||||
|
| Language.UKRANIAN | Ukrainian language. |
|
||||||
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
| Language.ZULU | Zulu language. |
|
||||||
|
|
||||||
|
#### Unit
|
||||||
|
| Constant | Description |
|
||||||
|
|----------------------|------------------------------------------------|
|
||||||
|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||||
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
||||||
|
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||||
|
* org.junit.jupiter:junit-jupiter-engine:5.7.1 (*test*)
|
||||||
|
* org.junit.platform:junit-platform-runner:1.7.1 (*test*)
|
||||||
@@ -0,0 +1,538 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3-hour forecast
|
||||||
|
* One Call API
|
||||||
|
* Air Pollution
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
implementation 'com.github.prominence:openweathermap-api:2.2.0'
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently, available APIs are:
|
||||||
|
* `currentWeather()`
|
||||||
|
* `forecast5Day3HourStep()`
|
||||||
|
* `oneCall()`
|
||||||
|
* `airPollution()`
|
||||||
|
|
||||||
|
Default(more or less) customization points:
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
// response language
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
...
|
||||||
|
// response units of measure
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Available output forms:
|
||||||
|
* `asJava()`
|
||||||
|
* `asJSON()`
|
||||||
|
|
||||||
|
Additional output forms, available for several APIs:
|
||||||
|
* `asXML()`
|
||||||
|
* `asHTML()`
|
||||||
|
|
||||||
|
_All response forms can be in **sync** and **async** variants._
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final String weatherJson = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Weather weather = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final List<Weather> weatherList = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.multiple()
|
||||||
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
|
.language(Language.GERMAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byZipCodeAndCountry("220015", "by")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||||
|
| `toString()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3-hour forecast
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final Forecast forecast = openWeatherClient
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastJson = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("New York", "NY", "US")
|
||||||
|
.language(Language.SPANISH)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
CompletableFuture<String> forecastFuture = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityId(350001514)
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastXml = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byZipCodeInUSA("10005")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||||
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
A forecast for Minsk with 15 timestamps.
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||||
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
#### One Call API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|--------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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. |
|
||||||
|
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||||
|
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||||
|
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||||
|
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||||
|
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|------------------------------|--------------------------------------------------------|
|
||||||
|
| `getSenderName()` | Returns alert sender name. |
|
||||||
|
| `getEventName()` | Returns alert event name. |
|
||||||
|
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||||
|
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||||
|
| `getDescription()` | Returns alert description. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
|
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||||
|
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
#### Air Pollution API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with air pollution forecast time. |
|
||||||
|
| `getAirQualityIndex()` | Returns `AirQualityIndex` object. |
|
||||||
|
| `getCO()` | Returns carbon monoxide concentration value in μg/m^3.s. |
|
||||||
|
| `getCarbonMonoxide()` | An alias for `getCO()` method. |
|
||||||
|
| `getNO()` | Returns nitrogen monoxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenMonoxide()` | An alias for `getNO()` method. |
|
||||||
|
| `getNO2()` | Returns nitrogen dioxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenDioxide()` | An alias for `getNO2()` method. |
|
||||||
|
| `getO3()` | Returns ozone concentration value in μg/m^3. |
|
||||||
|
| `getOzone()` | An alias for `getO3()` method. |
|
||||||
|
| `getSO2()` | Returns sulphur dioxide concentration value in μg/m^3. |
|
||||||
|
| `getSulphurDioxide()` | An alias for `getSO2()` method. |
|
||||||
|
| `getPM2_5()` | Returns fine particles matter concentration value in μg/m^3. |
|
||||||
|
| `getFineParticlesMatter()` | An alias for `getPM2_5()` method. |
|
||||||
|
| `getPM10()` | Returns coarse particulate matter concentration value in μg/m^3. |
|
||||||
|
| `getCoarseParticulateMatter()`| An alias for `getPM10()` method. |
|
||||||
|
| `getNH3()` | Returns ammonia concentration value in μg/m^3. |
|
||||||
|
| `getAmmonia()` | An alias for `getNH3()` method. |
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Language
|
||||||
|
| Constant | Description |
|
||||||
|
|-----------------------------------|-------------------------------|
|
||||||
|
| Language.AFRIKAANS | Afrikaans language. |
|
||||||
|
| Language.ALBANIAN | ALBANIAN language. |
|
||||||
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||||
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
|
| Language.CATALAN | Catalan language. |
|
||||||
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.DANISH | Danish language. |
|
||||||
|
| Language.GERMAN | German language. |
|
||||||
|
| Language.GREEK | Greek language. |
|
||||||
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.BASQUE | Basque language. |
|
||||||
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
|
| Language.FINNISH | Finnish language. |
|
||||||
|
| Language.FRENCH | French language. |
|
||||||
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.HEBREW | Hebrew language. |
|
||||||
|
| Language.HINDI | Hindi language. |
|
||||||
|
| Language.CROATIAN | Croatian language. |
|
||||||
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.INDONESIAN | Indonesian language. |
|
||||||
|
| Language.ITALIAN | Italian language. |
|
||||||
|
| Language.JAPANESE | Japanese language. |
|
||||||
|
| Language.KOREAN | Korean language. |
|
||||||
|
| Language.LATVIAN | Latvian language. |
|
||||||
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.NORWEGIAN | Norwegian language. |
|
||||||
|
| Language.DUTCH | Dutch language. |
|
||||||
|
| Language.POLISH | Polish language. |
|
||||||
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
||||||
|
| Language.ROMANIAN | Romanian language. |
|
||||||
|
| Language.RUSSIAN | Russian language. |
|
||||||
|
| Language.SWEDISH | Swedish language. |
|
||||||
|
| Language.SLOVAK | Slovak language. |
|
||||||
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.SERBIAN | Serbian language. |
|
||||||
|
| Language.THAI | Thai language. |
|
||||||
|
| Language.TURKISH | Turkish language. |
|
||||||
|
| Language.UKRANIAN | Ukrainian language. |
|
||||||
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
| Language.ZULU | Zulu language. |
|
||||||
|
|
||||||
|
#### Unit
|
||||||
|
| Constant | Description |
|
||||||
|
|----------------------|------------------------------------------------|
|
||||||
|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||||
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
||||||
|
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
||||||
|
* org.junit.jupiter:junit-jupiter-engine:5.7.1 (*test*)
|
||||||
|
* org.junit.platform:junit-platform-runner:1.7.1 (*test*)
|
||||||
@@ -0,0 +1,552 @@
|
|||||||
|
### Implemented features:
|
||||||
|
* Current weather data
|
||||||
|
* 5 day / 3-hour forecast
|
||||||
|
* One Call API
|
||||||
|
* Air Pollution
|
||||||
|
|
||||||
|
|
||||||
|
Other:
|
||||||
|
* Request timeout settings
|
||||||
|
|
||||||
|
### Maven coordinates:
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.prominence</groupId>
|
||||||
|
<artifactId>openweathermap-api</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Gradle coordinates:
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
implementation 'com.github.prominence:openweathermap-api:2.3.0'
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to use:
|
||||||
|
|
||||||
|
Firstly, you need to create the instance of `OpenWeatherMapClient` class:
|
||||||
|
```java
|
||||||
|
OpenWeatherMapClient openWeatherClient = new OpenWeatherMapClient(API_TOKEN);
|
||||||
|
```
|
||||||
|
where `API_TOKEN` is your token([you can get it here](https://home.openweathermap.org/api_keys)) as `String`.
|
||||||
|
|
||||||
|
Currently, available APIs are:
|
||||||
|
* `currentWeather()`
|
||||||
|
* `forecast5Day3HourStep()`
|
||||||
|
* `oneCall()`
|
||||||
|
* `airPollution()`
|
||||||
|
|
||||||
|
Also, it is possible to set timeouts for the requests on `openWeatherClient` object:
|
||||||
|
```java
|
||||||
|
openWeatherClient.setReadTimeout(1000);
|
||||||
|
openWeatherClient.setConnectTimeout(1000);
|
||||||
|
```
|
||||||
|
Timeout settings are passed to the requesters as a copy.
|
||||||
|
|
||||||
|
Default(more or less) customization points:
|
||||||
|
```java
|
||||||
|
...
|
||||||
|
// response language
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
...
|
||||||
|
// response units of measure
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Available output forms:
|
||||||
|
* `asJava()`
|
||||||
|
* `asJSON()`
|
||||||
|
|
||||||
|
Additional output forms, available for several APIs:
|
||||||
|
* `asXML()`
|
||||||
|
* `asHTML()`
|
||||||
|
|
||||||
|
_All response forms can be in **sync** and **async** variants._
|
||||||
|
|
||||||
|
#### Current weather data
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final String weatherJson = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final Weather weather = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final List<Weather> weatherList = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.multiple()
|
||||||
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
|
.language(Language.GERMAN)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> weatherXmlFuture = openWeatherClient
|
||||||
|
.currentWeather()
|
||||||
|
.single()
|
||||||
|
.byZipCodeAndCountry("220015", "by")
|
||||||
|
.language(Language.RUSSIAN)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.weather.Weather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last one hour and/or the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset` and `coordinate`. |
|
||||||
|
| `toString()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
Location: Minsk(BY), Weather: clear sky, -4.22 ℃, 1020.0 hPa, Clouds: 0%
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 5 day / 3-hour forecast
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final Forecast forecast = openWeatherClient
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("Minsk")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastJson = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityName("New York", "NY", "US")
|
||||||
|
.language(Language.SPANISH)
|
||||||
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
|
.count(15)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
CompletableFuture<String> forecastFuture = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byCityId(350001514)
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.count(15)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String forecastXml = getClient()
|
||||||
|
.forecast5Day3HourStep()
|
||||||
|
.byZipCodeInUSA("10005")
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asXML();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getLocation()` | Returns `Location` object. Available fields: `id`, `name`, `countryCode`, `sunrise` and `sunset` time, `zoneOffset`, `coordinate` and `population`. |
|
||||||
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
|
`toString()` output example:
|
||||||
|
```
|
||||||
|
A forecast for Minsk with 15 timestamps.
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.forecast.WeatherForecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
|
| `getWind()` | Returns `Wind` instance that contains wind information: `speed`, `degrees` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. Can be absent in case of no data. |
|
||||||
|
| `getClouds()` | Returns `Clouds` instance that contains information about cloudiness percentage. |
|
||||||
|
| `getForecastTimeISO()` | Returns String with time of data forecasted, ISO, UTC. |
|
||||||
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
#### One Call API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|--------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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. |
|
||||||
|
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||||
|
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||||
|
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||||
|
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getMoonriseTime()` | Returns `LocalDateTime` object with moonrise time. |
|
||||||
|
| `getMoonsetTime()` | Returns `LocalDateTime` object with moonset time. |
|
||||||
|
| `getMoonPhase()` | Returns `MoonPhase` object with `MoonType` info and value. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||||
|
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|------------------------------|--------------------------------------------------------|
|
||||||
|
| `getSenderName()` | Returns alert sender name. |
|
||||||
|
| `getEventName()` | Returns alert event name. |
|
||||||
|
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||||
|
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||||
|
| `getDescription()` | Returns alert description. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
|
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||||
|
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
#### Air Pollution API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with air pollution forecast time. |
|
||||||
|
| `getAirQualityIndex()` | Returns `AirQualityIndex` object. |
|
||||||
|
| `getCO()` | Returns carbon monoxide concentration value in μg/m^3.s. |
|
||||||
|
| `getCarbonMonoxide()` | An alias for `getCO()` method. |
|
||||||
|
| `getNO()` | Returns nitrogen monoxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenMonoxide()` | An alias for `getNO()` method. |
|
||||||
|
| `getNO2()` | Returns nitrogen dioxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenDioxide()` | An alias for `getNO2()` method. |
|
||||||
|
| `getO3()` | Returns ozone concentration value in μg/m^3. |
|
||||||
|
| `getOzone()` | An alias for `getO3()` method. |
|
||||||
|
| `getSO2()` | Returns sulphur dioxide concentration value in μg/m^3. |
|
||||||
|
| `getSulphurDioxide()` | An alias for `getSO2()` method. |
|
||||||
|
| `getPM2_5()` | Returns fine particles matter concentration value in μg/m^3. |
|
||||||
|
| `getFineParticlesMatter()` | An alias for `getPM2_5()` method. |
|
||||||
|
| `getPM10()` | Returns coarse particulate matter concentration value in μg/m^3. |
|
||||||
|
| `getCoarseParticulateMatter()`| An alias for `getPM10()` method. |
|
||||||
|
| `getNH3()` | Returns ammonia concentration value in μg/m^3. |
|
||||||
|
| `getAmmonia()` | An alias for `getNH3()` method. |
|
||||||
|
|
||||||
|
### Constants and options
|
||||||
|
|
||||||
|
#### Language
|
||||||
|
| Constant | Description |
|
||||||
|
|------------------------------|-------------------------------|
|
||||||
|
| Language.AFRIKAANS | Afrikaans language. |
|
||||||
|
| Language.ALBANIAN | ALBANIAN language. |
|
||||||
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||||
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
|
| Language.CATALAN | Catalan language. |
|
||||||
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.DANISH | Danish language. |
|
||||||
|
| Language.GERMAN | German language. |
|
||||||
|
| Language.GREEK | Greek language. |
|
||||||
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.BASQUE | Basque language. |
|
||||||
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
|
| Language.FINNISH | Finnish language. |
|
||||||
|
| Language.FRENCH | French language. |
|
||||||
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.HEBREW | Hebrew language. |
|
||||||
|
| Language.HINDI | Hindi language. |
|
||||||
|
| Language.CROATIAN | Croatian language. |
|
||||||
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.INDONESIAN | Indonesian language. |
|
||||||
|
| Language.ITALIAN | Italian language. |
|
||||||
|
| Language.JAPANESE | Japanese language. |
|
||||||
|
| Language.KOREAN | Korean language. |
|
||||||
|
| Language.LATVIAN | Latvian language. |
|
||||||
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.NORWEGIAN | Norwegian language. |
|
||||||
|
| Language.DUTCH | Dutch language. |
|
||||||
|
| Language.POLISH | Polish language. |
|
||||||
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
||||||
|
| Language.ROMANIAN | Romanian language. |
|
||||||
|
| Language.RUSSIAN | Russian language. |
|
||||||
|
| Language.SWEDISH | Swedish language. |
|
||||||
|
| Language.SLOVAK | Slovak language. |
|
||||||
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.SERBIAN | Serbian language. |
|
||||||
|
| Language.THAI | Thai language. |
|
||||||
|
| Language.TURKISH | Turkish language. |
|
||||||
|
| Language.UKRAINIAN | Ukrainian language. |
|
||||||
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
| Language.ZULU | Zulu language. |
|
||||||
|
|
||||||
|
#### Unit
|
||||||
|
| Constant | Description |
|
||||||
|
|----------------------|------------------------------------------------|
|
||||||
|
| Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
| Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). |
|
||||||
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
* com.fasterxml.jackson.core:jackson-databind:2.13.2.2
|
||||||
|
* org.slf4j:slf4j-api:1.7.36 (*compile*)
|
||||||
|
* org.junit.jupiter:junit-jupiter-engine:5.8.2 (*test*)
|
||||||
|
* org.junit.platform:junit-platform-runner:1.8.2 (*test*)
|
||||||
+353
-19
@@ -1,6 +1,15 @@
|
|||||||
### Implemented features:
|
### Implemented features:
|
||||||
* Current weather data
|
* Current weather data
|
||||||
|
* Hourly forecast
|
||||||
|
* One Call API
|
||||||
|
* Daily forecast
|
||||||
* 5 day / 3-hour forecast
|
* 5 day / 3-hour forecast
|
||||||
|
* Air Pollution
|
||||||
|
* Geocoding API
|
||||||
|
|
||||||
|
|
||||||
|
Other:
|
||||||
|
* Request timeout settings
|
||||||
|
|
||||||
### Maven coordinates:
|
### Maven coordinates:
|
||||||
|
|
||||||
@@ -8,14 +17,46 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.prominence</groupId>
|
<groupId>com.github.prominence</groupId>
|
||||||
<artifactId>openweathermap-api</artifactId>
|
<artifactId>openweathermap-api</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<repositories>
|
||||||
|
...
|
||||||
|
<!-- Repository for snapshot versions -->
|
||||||
|
<repository>
|
||||||
|
<id>oss.sonatype.org-snapshot</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
...
|
||||||
|
</repositories>
|
||||||
|
```
|
||||||
|
|
||||||
### Gradle coordinates:
|
### Gradle coordinates:
|
||||||
|
|
||||||
```groovy
|
```groovy
|
||||||
compile('com.github.prominence:openweathermap-api:2.0.0-SNAPSHOT')
|
implementation 'com.github.prominence:openweathermap-api:3.0.0-SNAPSHOT'
|
||||||
|
```
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
repositories {
|
||||||
|
...
|
||||||
|
// Repository for snapshot versions
|
||||||
|
maven {
|
||||||
|
url "https://oss.sonatype.org/content/repositories/snapshots"
|
||||||
|
mavenContent {
|
||||||
|
snapshotsOnly()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### How to use:
|
### How to use:
|
||||||
@@ -29,6 +70,15 @@ where `API_TOKEN` is your token([you can get it here](https://home.openweatherma
|
|||||||
Currently, available APIs are:
|
Currently, available APIs are:
|
||||||
* `currentWeather()`
|
* `currentWeather()`
|
||||||
* `forecast5Day3HourStep()`
|
* `forecast5Day3HourStep()`
|
||||||
|
* `oneCall()`
|
||||||
|
* `airPollution()`
|
||||||
|
|
||||||
|
Also, it is possible to set timeouts for the requests on `openWeatherClient` object:
|
||||||
|
```java
|
||||||
|
openWeatherClient.setReadTimeout(1000);
|
||||||
|
openWeatherClient.setConnectTimeout(1000);
|
||||||
|
```
|
||||||
|
Timeout settings are passed to the requesters as a copy.
|
||||||
|
|
||||||
Default(more or less) customization points:
|
Default(more or less) customization points:
|
||||||
```java
|
```java
|
||||||
@@ -79,7 +129,7 @@ final Weather weather = openWeatherClient
|
|||||||
final List<Weather> weatherList = openWeatherClient
|
final List<Weather> weatherList = openWeatherClient
|
||||||
.currentWeather()
|
.currentWeather()
|
||||||
.multiple()
|
.multiple()
|
||||||
.byCitiesInCycle(Coordinate.withValues(55.5, 37.5))
|
.byCitiesInCycle(Coordinate.of(55.5, 37.5))
|
||||||
.language(Language.GERMAN)
|
.language(Language.GERMAN)
|
||||||
.unitSystem(UnitSystem.IMPERIAL)
|
.unitSystem(UnitSystem.IMPERIAL)
|
||||||
.retrieve()
|
.retrieve()
|
||||||
@@ -103,10 +153,8 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
|||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
| `getCalculationTime()` | Returns `LocalDateTime` object with data calculation time. |
|
||||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
|
||||||
| `getCalculatedOn()` | Returns `LocalDateTime` object with data calculation time. |
|
|
||||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
| `getAtmosphericPressure()`| Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
@@ -114,7 +162,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. |
|
| `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. |
|
| `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. |
|
| `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()` | Returns informative string for the whole available weather information. |
|
||||||
|
|
||||||
`toString()` output example:
|
`toString()` output example:
|
||||||
@@ -169,11 +217,11 @@ final String forecastXml = getClient()
|
|||||||
|
|
||||||
You are able to set preferable options(via chain methods) and execute appropriate request.
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
`com.github.prominence.openweathermap.api.request.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
`com.github.prominence.openweathermap.api.model.forecast.free.Forecast`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
| Method | Description |
|
| 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. |
|
| `getWeatherForecasts()` | Returns list of `WeatherForecast` objects with forecast information. |
|
||||||
| `toString()` | Returns informative string for the whole available forecast information. |
|
| `toString()` | Returns informative string for the whole available forecast information. |
|
||||||
|
|
||||||
@@ -182,14 +230,12 @@ You are able to set preferable options(via chain methods) and execute appropriat
|
|||||||
A forecast for Minsk with 15 timestamps.
|
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 |
|
| Method | Description |
|
||||||
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `getState()` | Returns short weather description. Example: `Clear`. |
|
|
||||||
| `getDescription()` | Returns weather description. Example: `clear sky`. |
|
|
||||||
| `getWeatherIconUrl()` | Returns a link to weather icon hosted on https://openweathermap.org website. |
|
|
||||||
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
| `getTemperature()` | Returns `Temperature` instance that contains information about temperature. Available fields: `value`, `maxTemperature`, `minTemperature`, `feelsLike` and `unit`. |
|
||||||
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` instance that contains information about atmospheric pressure. Available fields: `value`, `seaLevelValue`, `groundLevelValue` and `unit`. |
|
||||||
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
| `getHumidity()` | Returns `Humidity` instance that contains humidity percentage information. |
|
||||||
@@ -201,44 +247,331 @@ A forecast for Minsk with 15 timestamps.
|
|||||||
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
| `getDayTime()` | Returns enumerations representing the part of day(day, night). |
|
||||||
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
| `toString()` | Returns informative string for the forecast of particular timestamp. |
|
||||||
|
|
||||||
|
#### One Call API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CurrentWeatherData currentWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.exclude(OneCallResultOptions.CURRENT, OneCallResultOptions.MINUTELY)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<CurrentWeatherData> currentWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final HistoricalWeatherData historicalWeatherData = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final String responseJson = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieve()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<HistoricalWeatherData> historicalWeatherDataFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final CompletableFuture<String> responseJsonFuture = openWeatherClient
|
||||||
|
.oneCall()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndTimestamp(Coordinate.of(60.99, 30.9), LocalDateTime.now().minusDays(5).toEpochSecond(ZoneOffset.UTC))
|
||||||
|
.language(Language.ENGLISH)
|
||||||
|
.unitSystem(UnitSystem.METRIC)
|
||||||
|
.retrieveAsync()
|
||||||
|
.asJSON();
|
||||||
|
```
|
||||||
|
|
||||||
|
You are able to set preferable options(via chain methods) and execute appropriate request.
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.CurrentWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|--------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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. |
|
||||||
|
| `getMinutelyList()` | Returns list of `Minutely` objects if available. |
|
||||||
|
| `getHourlyList()` | Returns list of `Houlry` objects if available. |
|
||||||
|
| `getDailyList()` | Returns list of `Daily` objects if available. |
|
||||||
|
| `getAlerts()` | Returns list of `Alert` objects if available. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.Current`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Minutely`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getPrecipitationVolume()` | Returns precipitation volume. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Hourly`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Daily`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|---------------------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getMoonriseTime()` | Returns `LocalDateTime` object with moonrise time. |
|
||||||
|
| `getMoonsetTime()` | Returns `LocalDateTime` object with moonset time. |
|
||||||
|
| `getMoonPhase()` | Returns `MoonPhase` object with `MoonType` info and value. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `DailyTemperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getProbabilityOfPrecipitation()` | Returns probability of precipitation(not percentage). |
|
||||||
|
| `getProbabilityOfPrecipitationPercentage()` | Returns probability of precipitation percentage. |
|
||||||
|
| `getRain()` | Returns `DailyRain` object. Available fields: `value`. |
|
||||||
|
| `getSnow()` | Returns `DailySnow` object. Available fields: `value`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.current.Alert`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|------------------------------|--------------------------------------------------------|
|
||||||
|
| `getSenderName()` | Returns alert sender name. |
|
||||||
|
| `getEventName()` | Returns alert event name. |
|
||||||
|
| `getStartTime()` | Returns `LocalDateTime` when event should start. |
|
||||||
|
| `getEndTime()` | Returns `LocalDateTime` when event should end. |
|
||||||
|
| `getDescription()` | Returns alert description. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeatherData`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | Returns `Coordinate` object. Available fields: `latitude`, `longitude`. |
|
||||||
|
| `getTimezone()` | Returns location timezone object. |
|
||||||
|
| `getTimezoneOffset()` | Returns zone offset. |
|
||||||
|
| `getHistoricalWeather()` | Returns `HistoricalWeather` object with historical weather state. |
|
||||||
|
| `getHourlyList()` | Returns list of `HourlyHistorical` objects. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HistoricalWeather`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getSunriseTime()` | Returns `LocalDateTime` object with sunrise time. |
|
||||||
|
| `getSunsetTime()` | Returns `LocalDateTime` object with sunset time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getUvIndex()` | Returns UV index value. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-----------------------------------|---------------------------------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with weather forecast time. |
|
||||||
|
| `getWeatherState()` | Returns `WeatherState` object with basic weather state information. |
|
||||||
|
| `getTemperature()` | Returns `Temperature` object. Available fields: `value`, `feelsLike`, `dewPoint` and `unit`. |
|
||||||
|
| `getAtmosphericPressure()` | Returns `AtmosphericPressure` object. Available fields: `seaLevelValue`. |
|
||||||
|
| `getHumidity()` | Returns `Humidity` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getClouds()` | Returns `Clouds` object. Available fields: `value` and `unit`. |
|
||||||
|
| `getVisibilityInMetres()` | Returns visibility in metres. |
|
||||||
|
| `getWind()` | Returns `Wind` object. Available fields: `speed`, `degrees`, `gust` and `unit`. |
|
||||||
|
| `getRain()` | Returns `Rain` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
| `getSnow()` | Returns `Snow` object. Available fields: `oneHourLevel` and `unit`. |
|
||||||
|
|
||||||
|
#### Air Pollution API
|
||||||
|
Examples:
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.current()
|
||||||
|
.byCoordinate(Coordinate.of(53.54, 27.34))
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
final AirPollutionDetails airPollutionDetails = openWeatherClient
|
||||||
|
.airPollution()
|
||||||
|
.historical()
|
||||||
|
.byCoordinateAndPeriod(Coordinate.of(53.54, 27.34), 1606223802, 1606482999)
|
||||||
|
.retrieve()
|
||||||
|
.asJava();
|
||||||
|
```
|
||||||
|
|
||||||
|
`com.github.prominence.openweathermap.api.model.air.pollution.AirPollutionDetails`'s useful public methods(setters are not listed):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getCoordinate()` | 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):
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|-------------------------------|---------------------------------------------------------------------------|
|
||||||
|
| `getForecastTime()` | Returns `LocalDateTime` object with air pollution forecast time. |
|
||||||
|
| `getAirQualityIndex()` | Returns `AirQualityIndex` object. |
|
||||||
|
| `getCO()` | Returns carbon monoxide concentration value in μg/m^3.s. |
|
||||||
|
| `getCarbonMonoxide()` | An alias for `getCO()` method. |
|
||||||
|
| `getNO()` | Returns nitrogen monoxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenMonoxide()` | An alias for `getNO()` method. |
|
||||||
|
| `getNO2()` | Returns nitrogen dioxide concentration value in μg/m^3. |
|
||||||
|
| `getNitrogenDioxide()` | An alias for `getNO2()` method. |
|
||||||
|
| `getO3()` | Returns ozone concentration value in μg/m^3. |
|
||||||
|
| `getOzone()` | An alias for `getO3()` method. |
|
||||||
|
| `getSO2()` | Returns sulphur dioxide concentration value in μg/m^3. |
|
||||||
|
| `getSulphurDioxide()` | An alias for `getSO2()` method. |
|
||||||
|
| `getPM2_5()` | Returns fine particles matter concentration value in μg/m^3. |
|
||||||
|
| `getFineParticlesMatter()` | An alias for `getPM2_5()` method. |
|
||||||
|
| `getPM10()` | Returns coarse particulate matter concentration value in μg/m^3. |
|
||||||
|
| `getCoarseParticulateMatter()`| An alias for `getPM10()` method. |
|
||||||
|
| `getNH3()` | Returns ammonia concentration value in μg/m^3. |
|
||||||
|
| `getAmmonia()` | An alias for `getNH3()` method. |
|
||||||
|
|
||||||
### Constants and options
|
### Constants and options
|
||||||
|
|
||||||
#### Language
|
#### Language
|
||||||
| Constant | Description |
|
| Constant | Description |
|
||||||
|-----------------------------------|-------------------------------|
|
|------------------------------|-------------------------------|
|
||||||
|
| Language.AFRIKAANS | Afrikaans language. |
|
||||||
|
| Language.ALBANIAN | ALBANIAN language. |
|
||||||
| Language.ARABIC | Arabic language. |
|
| Language.ARABIC | Arabic language. |
|
||||||
|
| Language.AZERBAIJANI | Azerbaijani language. |
|
||||||
| Language.BULGARIAN | Bulgarian language. |
|
| Language.BULGARIAN | Bulgarian language. |
|
||||||
| Language.CATALAN | Catalan language. |
|
| Language.CATALAN | Catalan language. |
|
||||||
| Language.CZECH | Czech language. |
|
| Language.CZECH | Czech language. |
|
||||||
|
| Language.DANISH | Danish language. |
|
||||||
| Language.GERMAN | German language. |
|
| Language.GERMAN | German language. |
|
||||||
| Language.GREEK | Greek language. |
|
| Language.GREEK | Greek language. |
|
||||||
| Language.ENGLISH | English language. |
|
| Language.ENGLISH | English language. |
|
||||||
|
| Language.BASQUE | Basque language. |
|
||||||
| Language.PERSIAN | Persian (Farsi) language. |
|
| Language.PERSIAN | Persian (Farsi) language. |
|
||||||
| Language.FINNISH | Finnish language. |
|
| Language.FINNISH | Finnish language. |
|
||||||
| Language.FRENCH | French language. |
|
| Language.FRENCH | French language. |
|
||||||
| Language.GALICIAN | Galician language. |
|
| Language.GALICIAN | Galician language. |
|
||||||
|
| Language.HEBREW | Hebrew language. |
|
||||||
|
| Language.HINDI | Hindi language. |
|
||||||
| Language.CROATIAN | Croatian language. |
|
| Language.CROATIAN | Croatian language. |
|
||||||
| Language.HUNGARIAN | Hungarian language. |
|
| Language.HUNGARIAN | Hungarian language. |
|
||||||
|
| Language.INDONESIAN | Indonesian language. |
|
||||||
| Language.ITALIAN | Italian language. |
|
| Language.ITALIAN | Italian language. |
|
||||||
| Language.JAPANESE | Japanese language. |
|
| Language.JAPANESE | Japanese language. |
|
||||||
| Language.KOREAN | Korean language. |
|
| Language.KOREAN | Korean language. |
|
||||||
| Language.LATVIAN | Latvian language. |
|
| Language.LATVIAN | Latvian language. |
|
||||||
| Language.LITHUANIAN | Lithuanian language. |
|
| Language.LITHUANIAN | Lithuanian language. |
|
||||||
| Language.MACEDONIAN | Macedonian language. |
|
| Language.MACEDONIAN | Macedonian language. |
|
||||||
|
| Language.NORWEGIAN | Norwegian language. |
|
||||||
| Language.DUTCH | Dutch language. |
|
| Language.DUTCH | Dutch language. |
|
||||||
| Language.POLISH | Polish language. |
|
| Language.POLISH | Polish language. |
|
||||||
| Language.PORTUGUESE | Portuguese language. |
|
| Language.PORTUGUESE | Portuguese language. |
|
||||||
|
| Language.PORTUGUES_BRAZIL | Português Brasil language. |
|
||||||
| Language.ROMANIAN | Romanian language. |
|
| Language.ROMANIAN | Romanian language. |
|
||||||
| Language.RUSSIAN | Russian language. |
|
| Language.RUSSIAN | Russian language. |
|
||||||
| Language.SWEDISH | Swedish language. |
|
| Language.SWEDISH | Swedish language. |
|
||||||
| Language.SLOVAK | Slovak language. |
|
| Language.SLOVAK | Slovak language. |
|
||||||
| Language.SLOVENIAN | Slovenian language. |
|
| Language.SLOVENIAN | Slovenian language. |
|
||||||
| Language.SPANISH | Spanish language. |
|
| Language.SPANISH | Spanish language. |
|
||||||
|
| Language.SERBIAN | Serbian language. |
|
||||||
|
| Language.THAI | Thai language. |
|
||||||
| Language.TURKISH | Turkish language. |
|
| Language.TURKISH | Turkish language. |
|
||||||
| Language.UKRANIAN | Ukrainian language. |
|
| Language.UKRAINIAN | Ukrainian language. |
|
||||||
| Language.VIETNAMESE | Vietnamese language. |
|
| Language.VIETNAMESE | Vietnamese language. |
|
||||||
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
| Language.CHINESE_SIMPLIFIED | Chinese Simplified language. |
|
||||||
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
| Language.CHINESE_TRADITIONAL | Chinese Traditional language. |
|
||||||
|
| Language.ZULU | Zulu language. |
|
||||||
|
|
||||||
#### Unit
|
#### Unit
|
||||||
| Constant | Description |
|
| Constant | Description |
|
||||||
@@ -248,6 +581,7 @@ A forecast for Minsk with 15 timestamps.
|
|||||||
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). |
|
||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
* com.fasterxml.jackson.core:jackson-databind:2.12.2
|
* com.fasterxml.jackson.core:jackson-databind:2.13.2.2
|
||||||
* org.slf4j:slf4j-api:1.7.30 (*compile*)
|
* org.slf4j:slf4j-api:1.7.36 (*compile*)
|
||||||
* junit:junit:4.13.1 (*test*)
|
* org.junit.jupiter:junit-jupiter-engine:5.8.2 (*test*)
|
||||||
|
* org.junit.platform:junit-platform-runner:1.8.2 (*test*)
|
||||||
Vendored
BIN
Binary file not shown.
+5
@@ -0,0 +1,5 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command;
|
||||||
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
Vendored
+89
@@ -0,0 +1,89 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>com.github.prominence</groupId>
|
|
||||||
<artifactId>openweathermap-api</artifactId>
|
|
||||||
<version>2.0.0</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<name>Java OpenWeatherMap API</name>
|
|
||||||
<description>Java API for OpenWeatherMap services.</description>
|
|
||||||
<url>https://github.com/Prominence/openweathermap-java-api</url>
|
|
||||||
|
|
||||||
<scm>
|
|
||||||
<url>https://github.com/Prominence/openweathermap-java-api</url>
|
|
||||||
<connection>scm:git:git://github.com/Prominence/openweathermap-java-api.git</connection>
|
|
||||||
<developerConnection>scm:git:git@github.com:prominence/openweathermap-java-api.git</developerConnection>
|
|
||||||
</scm>
|
|
||||||
|
|
||||||
<issueManagement>
|
|
||||||
<url>https://github.com/Prominence/openweathermap-java-api/issues</url>
|
|
||||||
<system>GitHub Issues</system>
|
|
||||||
</issueManagement>
|
|
||||||
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>MIT License</name>
|
|
||||||
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
|
||||||
<distribution>repo</distribution>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<email>alexey.zinchenko@protonmail.com</email>
|
|
||||||
<name>Alexey Zinchenko</name>
|
|
||||||
<url>https://github.com/prominence</url>
|
|
||||||
<id>Prominence</id>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
|
|
||||||
<distributionManagement>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>ossrh</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
<repository>
|
|
||||||
<id>ossrh</id>
|
|
||||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
|
||||||
</repository>
|
|
||||||
</distributionManagement>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
<target>8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/test/*</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
|
||||||
<version>1.6.8</version>
|
|
||||||
<extensions>true</extensions>
|
|
||||||
<configuration>
|
|
||||||
<serverId>ossrh</serverId>
|
|
||||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
|
||||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
<version>3.2.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-sources</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar-no-fork</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<configuration>
|
|
||||||
<source>8</source>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-javadocs</id>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
|
||||||
<version>1.6</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>sign-artifacts</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>sign</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.jacoco</groupId>
|
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
|
||||||
<version>0.8.6</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>prepare-agent</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>report</id>
|
|
||||||
<phase>test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<version>2.12.2</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>1.7.30</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.13.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'openweathermap-api'
|
||||||
@@ -23,10 +23,16 @@
|
|||||||
package com.github.prominence.openweathermap.api;
|
package com.github.prominence.openweathermap.api;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
import com.github.prominence.openweathermap.api.annotation.SubscriptionAvailability;
|
||||||
|
import com.github.prominence.openweathermap.api.conf.TimeoutSettings;
|
||||||
|
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.free.FiveDayThreeHourStepForecastRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.forecast.free.FiveDayThreeHourStepForecastRequesterImpl;
|
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.weather.CurrentWeatherRequester;
|
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequesterImpl;
|
|
||||||
|
|
||||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
||||||
|
|
||||||
@@ -36,22 +42,68 @@ import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*;
|
|||||||
*/
|
*/
|
||||||
public class OpenWeatherMapClient {
|
public class OpenWeatherMapClient {
|
||||||
private final String apiKey;
|
private final String apiKey;
|
||||||
|
private final TimeoutSettings timeoutSettings = new TimeoutSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created OpenWeatherMap client object.
|
* Created OpenWeatherMap client object.
|
||||||
* @param apiKey API key obtained on <a href="https://home.openweathermap.org/api_keys">OpwnWeatherMap site</a>.
|
* @param apiKey API key obtained on <a href="https://home.openweathermap.org/api_keys">OpenWeatherMap site</a>.
|
||||||
*/
|
*/
|
||||||
public OpenWeatherMapClient(String apiKey) {
|
public OpenWeatherMapClient(String apiKey) {
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConnectionTimeout(int connectionTimeout) {
|
||||||
|
timeoutSettings.setConnectionTimeout(connectionTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadTimeout(int readTimeout) {
|
||||||
|
timeoutSettings.setReadTimeout(readTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
* Current Weather <a href="https://openweathermap.org/current">API</a>.
|
||||||
* @return requester for retrieving current weather information.
|
* @return requester for retrieving current weather information.
|
||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public CurrentWeatherRequester currentWeather() {
|
public CurrentWeatherRequester currentWeather() {
|
||||||
return new CurrentWeatherRequesterImpl(apiKey);
|
return new CurrentWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 = { DEVELOPER, PROFESSIONAL, ENTERPRISE })
|
||||||
|
public FourDaysHourlyForecastRequester forecastHourly4Days() {
|
||||||
|
return new FourDaysHourlyForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(new RequestSettings(apiKey, timeoutSettings));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,6 +112,21 @@ public class OpenWeatherMapClient {
|
|||||||
*/
|
*/
|
||||||
@SubscriptionAvailability(plans = ALL)
|
@SubscriptionAvailability(plans = ALL)
|
||||||
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() {
|
||||||
return new FiveDayThreeHourStepForecastRequesterImpl(apiKey);
|
return new FiveDayThreeHourStepForecastRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscriptionAvailability(plans = ALL)
|
||||||
|
public GeocodingRequester geocoding() {
|
||||||
|
return new GeocodingRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.conf;
|
||||||
|
|
||||||
|
public class TimeoutSettings {
|
||||||
|
private Integer connectionTimeout;
|
||||||
|
private Integer readTimeout;
|
||||||
|
|
||||||
|
public TimeoutSettings() {
|
||||||
|
this(2000, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeoutSettings(Integer connectionTimeout, Integer readTimeout) {
|
||||||
|
this.connectionTimeout = connectionTimeout;
|
||||||
|
this.readTimeout = readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimeoutSettings(TimeoutSettings from) {
|
||||||
|
this.connectionTimeout = from.connectionTimeout;
|
||||||
|
this.readTimeout = from.readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getConnectionTimeout() {
|
||||||
|
return connectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionTimeout(Integer connectionTimeout) {
|
||||||
|
this.connectionTimeout = connectionTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getReadTimeout() {
|
||||||
|
return readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadTimeout(Integer readTimeout) {
|
||||||
|
this.readTimeout = readTimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.AtmosphericPressure;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class AtmosphericPressureDeserializer extends JsonDeserializer<AtmosphericPressure> {
|
||||||
|
@Override
|
||||||
|
public AtmosphericPressure deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode mainNode = p.getCodec().readTree(p);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Clouds;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CloudsDeserializer extends JsonDeserializer<Clouds> {
|
||||||
|
@Override
|
||||||
|
public Clouds deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode cloudsNode = p.getCodec().readTree(p);
|
||||||
|
|
||||||
|
final JsonNode allValueNode = cloudsNode.get("all");
|
||||||
|
if (allValueNode != null) {
|
||||||
|
return Clouds.withValue((byte) allValueNode.asInt());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class CoordinatesDeserializer extends JsonDeserializer<Coordinates> {
|
||||||
|
@Override
|
||||||
|
public Coordinates deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
JsonNode rootNode = jp.getCodec().readTree(jp);
|
||||||
|
if (rootNode.has("lat") && rootNode.has("lon")) {
|
||||||
|
return Coordinates.of(rootNode.get("lat").asDouble(), rootNode.get("lon").asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
import com.github.prominence.openweathermap.api.model.geocoding.GeocodingRecord;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GeocodingRecordDeserializer extends JsonDeserializer<GeocodingRecord> {
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public GeocodingRecordDeserializer() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeocodingRecord deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
JsonNode rootNode = jp.getCodec().readTree(jp);
|
||||||
|
String name = rootNode.get("name").asText();
|
||||||
|
String country = rootNode.get("country").asText();
|
||||||
|
Map<String, String> localNames = objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("local_names")), new TypeReference<Map<String, String>>() {});
|
||||||
|
Coordinates coordinates = objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Coordinates.class);
|
||||||
|
return new GeocodingRecord(name, localNames, coordinates, country);
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
-15
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,21 +20,22 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.deserializer;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
import com.github.prominence.openweathermap.api.request.RequestTerminator;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Humidity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
public class HumidityDeserializer extends JsonDeserializer<Humidity> {
|
||||||
* The interface Multiple result current weather request terminator.
|
@Override
|
||||||
*/
|
public Humidity deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator<List<Weather>, String> {
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
/**
|
|
||||||
* XML response format.
|
return Humidity.withValue((byte) (rootNode.get("humidity").asInt()));
|
||||||
*
|
}
|
||||||
* @return the XML string
|
|
||||||
*/
|
|
||||||
String asXML();
|
|
||||||
}
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Temperature;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class TemperatureDeserializer extends JsonDeserializer<Temperature> {
|
||||||
|
@Override
|
||||||
|
public Temperature deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode mainNode = p.getCodec().readTree(p);
|
||||||
|
final UnitSystem unitSystem = (UnitSystem) ctxt.findInjectableValue("unitSystem", null, null);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.WeatherState;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class WeatherStateDeserializer extends JsonDeserializer<WeatherState> {
|
||||||
|
@Override
|
||||||
|
public WeatherState deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
JsonNode weatherNode = p.getCodec().readTree(p);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Wind;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class WindDeserializer extends JsonDeserializer<Wind> {
|
||||||
|
@Override
|
||||||
|
public Wind deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode windNode = p.getCodec().readTree(p);
|
||||||
|
final UnitSystem unitSystem = (UnitSystem) ctxt.findInjectableValue("unitSystem", null, null);
|
||||||
|
|
||||||
|
JsonNode speedNode = windNode.get("speed");
|
||||||
|
if (speedNode == null) {
|
||||||
|
speedNode = windNode.get("wind_speed");
|
||||||
|
}
|
||||||
|
double speed = speedNode.asDouble();
|
||||||
|
|
||||||
|
final Wind wind = Wind.withValue(speed, unitSystem.getWindUnit());
|
||||||
|
JsonNode degNode = windNode.get("deg");
|
||||||
|
if (degNode == null) {
|
||||||
|
degNode = windNode.get("wind_deg");
|
||||||
|
}
|
||||||
|
if (degNode != null) {
|
||||||
|
wind.setDegrees(degNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonNode gustNode = windNode.get("gust");
|
||||||
|
if (gustNode == null) {
|
||||||
|
gustNode = windNode.get("wind_gust");
|
||||||
|
}
|
||||||
|
if (gustNode != null) {
|
||||||
|
wind.setGust(gustNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return wind;
|
||||||
|
}
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
import com.github.prominence.openweathermap.api.model.geocoding.ZipCodeGeocodingRecord;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ZipCodeGeocodingDeserializer extends JsonDeserializer<ZipCodeGeocodingRecord> {
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public ZipCodeGeocodingDeserializer() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ZipCodeGeocodingRecord deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
String zip = rootNode.get("zip").asText();
|
||||||
|
String name = rootNode.get("name").asText();
|
||||||
|
String country = rootNode.get("country").asText();
|
||||||
|
|
||||||
|
Coordinates coordinates = objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Coordinates.class);
|
||||||
|
|
||||||
|
return new ZipCodeGeocodingRecord(zip, name, coordinates, country);
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.climatic;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.climatic.AtmosphericPressure;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ClimaticForecastAtmosphericPressureDeserializer extends JsonDeserializer<AtmosphericPressure> {
|
||||||
|
@Override
|
||||||
|
public AtmosphericPressure deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
return (AtmosphericPressure) AtmosphericPressure.withValue(jsonNode.get("pressure").asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.climatic;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Clouds;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ClimaticForecastCloudsDeserializer extends JsonDeserializer<Clouds> {
|
||||||
|
@Override
|
||||||
|
public Clouds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||||
|
if (cloudsNode != null) {
|
||||||
|
return Clouds.withValue((byte) cloudsNode.asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.climatic;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.CoordinatesDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.climatic.Location;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static com.github.prominence.openweathermap.api.utils.JsonDeserializationUtils.parseZoneOffset;
|
||||||
|
|
||||||
|
public class ClimaticForecastLocationDeserializer extends JsonDeserializer<Location> {
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public ClimaticForecastLocationDeserializer() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final Location location = (Location) Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
|
||||||
|
|
||||||
|
final JsonNode timezoneNode = rootNode.get("timezone");
|
||||||
|
if (timezoneNode != null) {
|
||||||
|
location.setZoneOffset(parseZoneOffset(timezoneNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode countryNode = rootNode.get("country");
|
||||||
|
if (countryNode != null) {
|
||||||
|
location.setCountryCode(countryNode.asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
|
if (coordNode != null) {
|
||||||
|
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode populationNode = rootNode.get("population");
|
||||||
|
if (populationNode != null) {
|
||||||
|
location.setPopulation(populationNode.asLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.climatic;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.climatic.Rain;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ClimaticForecastRainDeserializer extends JsonDeserializer<Rain> {
|
||||||
|
@Override
|
||||||
|
public Rain deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final JsonNode rainNode = rootNode.get("rain");
|
||||||
|
if (rainNode != null) {
|
||||||
|
return (Rain) Rain.withValue(rainNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.climatic;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.climatic.Snow;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ClimaticForecastSnowDeserializer extends JsonDeserializer<Snow> {
|
||||||
|
@Override
|
||||||
|
public Snow deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final JsonNode snowNode = rootNode.get("snow");
|
||||||
|
if (snowNode != null) {
|
||||||
|
return (Snow) Snow.withValue(snowNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.climatic;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.climatic.Temperature;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ClimaticForecastTemperatureDeserializer extends JsonDeserializer<Temperature> {
|
||||||
|
@Override
|
||||||
|
public Temperature deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
|
||||||
|
final Temperature temperature = new Temperature();
|
||||||
|
final JsonNode tempNode = rootNode.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 = rootNode.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.forecast.climatic;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Wind;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ClimaticForecastWindDeserializer extends JsonDeserializer<Wind> {
|
||||||
|
@Override
|
||||||
|
public Wind deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode windNode = p.getCodec().readTree(p);
|
||||||
|
final UnitSystem unitSystem = (UnitSystem) ctxt.findInjectableValue("unitSystem", null, null);
|
||||||
|
|
||||||
|
JsonNode speedNode = windNode.get("speed");
|
||||||
|
if (speedNode == null) {
|
||||||
|
speedNode = windNode.get("wind_speed");
|
||||||
|
}
|
||||||
|
double speed = speedNode.asDouble();
|
||||||
|
|
||||||
|
final Wind wind = Wind.withValue(speed, unitSystem.getWindUnit());
|
||||||
|
JsonNode degNode = windNode.get("deg");
|
||||||
|
if (degNode == null) {
|
||||||
|
degNode = windNode.get("wind_deg");
|
||||||
|
}
|
||||||
|
if (degNode != null) {
|
||||||
|
wind.setDegrees(degNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return wind;
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.daily;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.daily.AtmosphericPressure;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DailyForecastAtmosphericPressureDeserializer extends JsonDeserializer<AtmosphericPressure> {
|
||||||
|
@Override
|
||||||
|
public AtmosphericPressure deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
return (AtmosphericPressure) AtmosphericPressure.withValue(jsonNode.get("pressure").asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.daily;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Clouds;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DailyForecastCloudsDeserializer extends JsonDeserializer<Clouds> {
|
||||||
|
@Override
|
||||||
|
public Clouds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final JsonNode cloudsNode = rootNode.get("clouds");
|
||||||
|
if (cloudsNode != null) {
|
||||||
|
return Clouds.withValue((byte) cloudsNode.asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.daily;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.CoordinatesDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.daily.Location;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static com.github.prominence.openweathermap.api.utils.JsonDeserializationUtils.parseZoneOffset;
|
||||||
|
|
||||||
|
public class DailyForecastLocationDeserializer extends JsonDeserializer<Location> {
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public DailyForecastLocationDeserializer() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final Location location = (Location) Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText());
|
||||||
|
|
||||||
|
final JsonNode timezoneNode = rootNode.get("timezone");
|
||||||
|
if (timezoneNode != null) {
|
||||||
|
location.setZoneOffset(parseZoneOffset(timezoneNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode countryNode = rootNode.get("country");
|
||||||
|
if (countryNode != null) {
|
||||||
|
location.setCountryCode(countryNode.asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode coordNode = rootNode.get("coord");
|
||||||
|
if (coordNode != null) {
|
||||||
|
location.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode populationNode = rootNode.get("population");
|
||||||
|
if (populationNode != null) {
|
||||||
|
location.setPopulation(populationNode.asLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.daily;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.daily.Rain;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DailyForecastRainDeserializer extends JsonDeserializer<Rain> {
|
||||||
|
@Override
|
||||||
|
public Rain deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final JsonNode rainNode = rootNode.get("rain");
|
||||||
|
if (rainNode != null) {
|
||||||
|
return (Rain) Rain.withValue(rainNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.daily;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.daily.Snow;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DailyForecastSnowDeserializer extends JsonDeserializer<Snow> {
|
||||||
|
@Override
|
||||||
|
public Snow deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
final JsonNode snowNode = rootNode.get("snow");
|
||||||
|
if (snowNode != null) {
|
||||||
|
return (Snow) Snow.withValue(snowNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.deserializer.forecast.daily;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.daily.Temperature;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DailyForecastTemperatureDeserializer extends JsonDeserializer<Temperature> {
|
||||||
|
@Override
|
||||||
|
public Temperature deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = jsonParser.getCodec().readTree(jsonParser);
|
||||||
|
|
||||||
|
final Temperature temperature = new Temperature();
|
||||||
|
final JsonNode tempNode = rootNode.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 = rootNode.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.forecast.hourly;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.CoordinatesDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.hourly.Location;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
public class HourlyForecastLocationDeserializer extends JsonDeserializer<Location> {
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public HourlyForecastLocationDeserializer() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
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(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.forecast.hourly;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.hourly.Rain;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class HourlyForecastRainDeserializer extends JsonDeserializer<Rain> {
|
||||||
|
@Override
|
||||||
|
public Rain deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rainNode = p.getCodec().readTree(p);
|
||||||
|
final JsonNode oneHourNode = rainNode.get("1h");
|
||||||
|
if (oneHourNode != null) {
|
||||||
|
return Rain.withOneHourLevelValue(oneHourNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.forecast.hourly;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.hourly.Snow;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class HourlyForecastSnowDeserializer extends JsonDeserializer<Snow> {
|
||||||
|
@Override
|
||||||
|
public Snow deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode snowNode = p.getCodec().readTree(p);
|
||||||
|
final JsonNode oneHourNode = snowNode.get("1h");
|
||||||
|
if (oneHourNode != null) {
|
||||||
|
return Snow.withOneHourLevelValue(oneHourNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.onecall;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.current.Alert;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.JsonDeserializationUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AlertDeserializer extends JsonDeserializer<Alert> {
|
||||||
|
@Override
|
||||||
|
public Alert deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode alertNode = p.getCodec().readTree(p);
|
||||||
|
|
||||||
|
Alert alert = new Alert();
|
||||||
|
alert.setSenderName(alertNode.get("sender_name").asText());
|
||||||
|
alert.setEventName(alertNode.get("event").asText());
|
||||||
|
alert.setStartTime(JsonDeserializationUtils.parseDateTime(alertNode.get("start")));
|
||||||
|
alert.setEndTime(JsonDeserializationUtils.parseDateTime(alertNode.get("end")));
|
||||||
|
alert.setDescription(alertNode.get("description").asText());
|
||||||
|
|
||||||
|
final JsonNode tagsNode = alertNode.get("tags");
|
||||||
|
if (tagsNode != null) {
|
||||||
|
List<String> tags = new ArrayList<>();
|
||||||
|
for (JsonNode tagNode : tagsNode) {
|
||||||
|
tags.add(tagNode.asText());
|
||||||
|
}
|
||||||
|
alert.setTags(tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
-16
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,22 +20,21 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.multiple;
|
package com.github.prominence.openweathermap.api.deserializer.onecall;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.AtmosphericPressure;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
public class OneCallAtmosphericPressureDeserializer extends JsonDeserializer<AtmosphericPressure> {
|
||||||
* The interface Multiple result current weather async request terminator.
|
@Override
|
||||||
*/
|
public AtmosphericPressure deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
public interface MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<List<Weather>, String> {
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
/**
|
return AtmosphericPressure.withValue(rootNode.get("pressure").asDouble());
|
||||||
* XML response format.
|
}
|
||||||
*
|
|
||||||
* @return the completable future
|
|
||||||
*/
|
|
||||||
CompletableFuture<String> asXML();
|
|
||||||
}
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.onecall;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.current.DailyRain;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class OneCallDailyRainDeserializer extends JsonDeserializer<DailyRain> {
|
||||||
|
@Override
|
||||||
|
public DailyRain deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
final JsonNode valueNode = rootNode.get("rain");
|
||||||
|
if (valueNode != null) {
|
||||||
|
return DailyRain.withValue(valueNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.onecall;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.current.DailySnow;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class OneCallDailySnowDeserializer extends JsonDeserializer<DailySnow> {
|
||||||
|
@Override
|
||||||
|
public DailySnow deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
|
||||||
|
final JsonNode valueNode = rootNode.get("snow");
|
||||||
|
if (valueNode != null) {
|
||||||
|
return DailySnow.withValue(valueNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.onecall;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.current.DailyTemperature;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class OneCallDailyTemperatureDeserializer extends JsonDeserializer<DailyTemperature> {
|
||||||
|
@Override
|
||||||
|
public DailyTemperature deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
|
||||||
|
final DailyTemperature temperature = new DailyTemperature();
|
||||||
|
final JsonNode tempNode = rootNode.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 = rootNode.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.onecall;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.Rain;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class OneCallRainDeserializer extends JsonDeserializer<Rain> {
|
||||||
|
@Override
|
||||||
|
public Rain deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
final JsonNode rainNode = rootNode.get("rain");
|
||||||
|
if (rainNode != null) {
|
||||||
|
final JsonNode oneHourNode = rainNode.get("1h");
|
||||||
|
if (oneHourNode != null) {
|
||||||
|
return Rain.withOneHourLevelValue(oneHourNode.asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.onecall;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.Rain;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.Snow;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class OneCallSnowDeserializer extends JsonDeserializer<Snow> {
|
||||||
|
@Override
|
||||||
|
public Snow deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
final JsonNode snowNode = rootNode.get("snow");
|
||||||
|
if (snowNode != null) {
|
||||||
|
final JsonNode OneHourNode = snowNode.get("1h");
|
||||||
|
if (OneHourNode != null) {
|
||||||
|
Rain.withOneHourLevelValue(OneHourNode.asDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.onecall;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.Temperature;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class OneCallTemperatureDeserializer extends JsonDeserializer<Temperature> {
|
||||||
|
@Override
|
||||||
|
public Temperature deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
final UnitSystem unitSystem = (UnitSystem) ctxt.findInjectableValue("unitSystem", null, null);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.weather;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.CoordinatesDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Location;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
public class WeatherLocationDeserializer extends JsonDeserializer<Location> {
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public WeatherLocationDeserializer() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rootNode = p.getCodec().readTree(p);
|
||||||
|
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(objectMapper.readValue(objectMapper.treeAsTokens(coordNode), Coordinates.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.weather;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Rain;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class WeatherRainDeserializer extends JsonDeserializer<Rain> {
|
||||||
|
@Override
|
||||||
|
public Rain deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode rainNode = p.getCodec().readTree(p);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.deserializer.weather;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JacksonException;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Snow;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class WeatherSnowDeserializer extends JsonDeserializer<Snow> {
|
||||||
|
@Override
|
||||||
|
public Snow deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JacksonException {
|
||||||
|
final JsonNode snowNode = p.getCodec().readTree(p);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* * Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
* *
|
||||||
|
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* * of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* * in the Software without restriction, including without limitation the rights
|
||||||
|
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* * copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* * furnished to do so, subject to the following conditions:
|
||||||
|
* *
|
||||||
|
* * The above copyright notice and this permission notice shall be included in all
|
||||||
|
* * copies or substantial portions of the Software.
|
||||||
|
* *
|
||||||
|
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* * SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum Air quality index.
|
||||||
|
*/
|
||||||
|
public enum AirQualityIndex {
|
||||||
|
/**
|
||||||
|
* Good air quality index.
|
||||||
|
*/
|
||||||
|
GOOD(1),
|
||||||
|
/**
|
||||||
|
* Fair air quality index.
|
||||||
|
*/
|
||||||
|
FAIR(2),
|
||||||
|
/**
|
||||||
|
* Moderate air quality index.
|
||||||
|
*/
|
||||||
|
MODERATE(3),
|
||||||
|
/**
|
||||||
|
* Poor air quality index.
|
||||||
|
*/
|
||||||
|
POOR(4),
|
||||||
|
/**
|
||||||
|
* Very poor air quality index.
|
||||||
|
*/
|
||||||
|
VERY_POOR(5);
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
AirQualityIndex(int index) {
|
||||||
|
this.value = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets value.
|
||||||
|
*
|
||||||
|
* @return the value
|
||||||
|
*/
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets by index.
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,11 +27,26 @@ package com.github.prominence.openweathermap.api.enums;
|
|||||||
* Usually it could be specified to get response with some fields translated into desired language.
|
* Usually it could be specified to get response with some fields translated into desired language.
|
||||||
*/
|
*/
|
||||||
public enum Language {
|
public enum Language {
|
||||||
|
/**
|
||||||
|
* Afrikaans language.
|
||||||
|
*/
|
||||||
|
AFRIKAANS("af"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Albanian language.
|
||||||
|
*/
|
||||||
|
ALBANIAN("al"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arabic language.
|
* Arabic language.
|
||||||
*/
|
*/
|
||||||
ARABIC("ar"),
|
ARABIC("ar"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Azerbaijani language.
|
||||||
|
*/
|
||||||
|
AZERBAIJANI("az"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulgarian language.
|
* Bulgarian language.
|
||||||
*/
|
*/
|
||||||
@@ -47,6 +62,11 @@ public enum Language {
|
|||||||
*/
|
*/
|
||||||
CZECH("cz"),
|
CZECH("cz"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Danish language
|
||||||
|
*/
|
||||||
|
DANISH("da"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* German language.
|
* German language.
|
||||||
*/
|
*/
|
||||||
@@ -62,6 +82,11 @@ public enum Language {
|
|||||||
*/
|
*/
|
||||||
ENGLISH("en"),
|
ENGLISH("en"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basque language.
|
||||||
|
*/
|
||||||
|
BASQUE("eu"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persian language.
|
* Persian language.
|
||||||
*/
|
*/
|
||||||
@@ -82,6 +107,16 @@ public enum Language {
|
|||||||
*/
|
*/
|
||||||
GALICIAN("gl"),
|
GALICIAN("gl"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hebrew language.
|
||||||
|
*/
|
||||||
|
HEBREW("he"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hindi language.
|
||||||
|
*/
|
||||||
|
HINDI("hi"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Croatian language.
|
* Croatian language.
|
||||||
*/
|
*/
|
||||||
@@ -92,6 +127,11 @@ public enum Language {
|
|||||||
*/
|
*/
|
||||||
HUNGARIAN("hu"),
|
HUNGARIAN("hu"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indonesian language.
|
||||||
|
*/
|
||||||
|
INDONESIAN("id"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Italian language.
|
* Italian language.
|
||||||
*/
|
*/
|
||||||
@@ -122,6 +162,11 @@ public enum Language {
|
|||||||
*/
|
*/
|
||||||
MACEDONIAN("mk"),
|
MACEDONIAN("mk"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Norwegian language.
|
||||||
|
*/
|
||||||
|
NORWEGIAN("no"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dutch language.
|
* Dutch language.
|
||||||
*/
|
*/
|
||||||
@@ -137,6 +182,11 @@ public enum Language {
|
|||||||
*/
|
*/
|
||||||
PORTUGUESE("pt"),
|
PORTUGUESE("pt"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Português Brasil language.
|
||||||
|
*/
|
||||||
|
PORTUGUES_BRAZIL("pt_br"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Romanian language.
|
* Romanian language.
|
||||||
*/
|
*/
|
||||||
@@ -165,7 +215,17 @@ public enum Language {
|
|||||||
/**
|
/**
|
||||||
* Spanish language.
|
* Spanish language.
|
||||||
*/
|
*/
|
||||||
SPANISH("en"),
|
SPANISH("es"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serbian language.
|
||||||
|
*/
|
||||||
|
SERBIAN("sr"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thai language.
|
||||||
|
*/
|
||||||
|
THAI("th"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turkish language.
|
* Turkish language.
|
||||||
@@ -173,9 +233,9 @@ public enum Language {
|
|||||||
TURKISH("tr"),
|
TURKISH("tr"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ukranian language.
|
* Ukrainian language.
|
||||||
*/
|
*/
|
||||||
UKRANIAN("uk"),
|
UKRAINIAN("uk"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vietnamese language.
|
* Vietnamese language.
|
||||||
@@ -190,7 +250,12 @@ public enum Language {
|
|||||||
/**
|
/**
|
||||||
* Chinese traditional language.
|
* Chinese traditional language.
|
||||||
*/
|
*/
|
||||||
CHINESE_TRADITIONAL("zh_tw");
|
CHINESE_TRADITIONAL("zh_tw"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zulu language.
|
||||||
|
*/
|
||||||
|
ZULU("zu");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.enums;
|
||||||
|
|
||||||
|
public enum MoonType {
|
||||||
|
NEW_MOON,
|
||||||
|
WAXING_CRESCENT,
|
||||||
|
FIRST_QUARTER_MOON,
|
||||||
|
WAXING_GIBBOUS,
|
||||||
|
FULL_MOON,
|
||||||
|
WANING_GIBBOUS,
|
||||||
|
LAST_QUARTER_MOON,
|
||||||
|
WANING_CRESCENT,
|
||||||
|
INVALID;
|
||||||
|
|
||||||
|
private static final double precision = 0.000001d;
|
||||||
|
|
||||||
|
public static MoonType valueOf(double numericValue) {
|
||||||
|
if (equals(numericValue, 0) || equals(numericValue, 1)) {
|
||||||
|
return NEW_MOON;
|
||||||
|
} else if (equals(numericValue, 0.25)) {
|
||||||
|
return FIRST_QUARTER_MOON;
|
||||||
|
} else if (equals(numericValue, 0.5)) {
|
||||||
|
return FULL_MOON;
|
||||||
|
} else if (equals(numericValue, 0.75)) {
|
||||||
|
return LAST_QUARTER_MOON;
|
||||||
|
} else if (numericValue > 0 && numericValue < 0.25) {
|
||||||
|
return WAXING_CRESCENT;
|
||||||
|
} else if (numericValue > 0.25 && numericValue < 0.5) {
|
||||||
|
return WAXING_GIBBOUS;
|
||||||
|
} else if (numericValue > 0.5 && numericValue < 0.75) {
|
||||||
|
return WANING_GIBBOUS;
|
||||||
|
} else if (numericValue > 0.75 && numericValue < 1) {
|
||||||
|
return WANING_CRESCENT;
|
||||||
|
}
|
||||||
|
return INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean equals(double d1, double d2) {
|
||||||
|
return Math.abs(d1 - d2) < precision;
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
-15
@@ -20,28 +20,45 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request.weather.single;
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
|
||||||
import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current weather async request terminator interface.
|
* The enum One call result options.
|
||||||
*/
|
*/
|
||||||
public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator<Weather, String> {
|
public enum OneCallResultOptions {
|
||||||
/**
|
/**
|
||||||
* XML response format.
|
* Current one call result options.
|
||||||
*
|
|
||||||
* @return the completable future
|
|
||||||
*/
|
*/
|
||||||
CompletableFuture<String> asXML();
|
CURRENT("current"),
|
||||||
|
/**
|
||||||
|
* Minutely one call result options.
|
||||||
|
*/
|
||||||
|
MINUTELY("minutely"),
|
||||||
|
/**
|
||||||
|
* Hourly one call result options.
|
||||||
|
*/
|
||||||
|
HOURLY("hourly"),
|
||||||
|
/**
|
||||||
|
* Daily one call result options.
|
||||||
|
*/
|
||||||
|
DAILY("daily"),
|
||||||
|
/**
|
||||||
|
* Alerts one call result options.
|
||||||
|
*/
|
||||||
|
ALERTS("alerts");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
OneCallResultOptions(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML response format.
|
* Gets value.
|
||||||
*
|
*
|
||||||
* @return the completable future
|
* @return the value
|
||||||
*/
|
*/
|
||||||
CompletableFuture<String> asHTML();
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+16
-20
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,27 +20,23 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.request;
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
/**
|
public enum ResponseType {
|
||||||
* The interface Request terminator.
|
HTML("html"),
|
||||||
*
|
XML("xml");
|
||||||
* @param <T> the type parameter
|
|
||||||
* @param <S> the type parameter
|
private final String value;
|
||||||
*/
|
|
||||||
public interface RequestTerminator<T, S> {
|
ResponseType(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java object response format.
|
* Returns language's value.
|
||||||
*
|
* @return value.
|
||||||
* @return the java object
|
|
||||||
*/
|
*/
|
||||||
T asJava();
|
public String getValue() {
|
||||||
|
return value;
|
||||||
/**
|
}
|
||||||
* JSON response format.
|
|
||||||
*
|
|
||||||
* @return the JSON string
|
|
||||||
*/
|
|
||||||
S asJSON();
|
|
||||||
}
|
}
|
||||||
@@ -32,6 +32,11 @@ public enum SubscriptionPlan {
|
|||||||
*/
|
*/
|
||||||
FREE,
|
FREE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An alias that represents any of paid plans: startup, developer, professional or enterprise.
|
||||||
|
*/
|
||||||
|
PAID,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Startup subscription plan.
|
* Startup subscription plan.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -52,14 +52,10 @@ public enum UnitSystem {
|
|||||||
* @return wind unit.
|
* @return wind unit.
|
||||||
*/
|
*/
|
||||||
public String getWindUnit() {
|
public String getWindUnit() {
|
||||||
switch (this) {
|
return switch (this) {
|
||||||
case IMPERIAL:
|
case IMPERIAL -> "miles/hour";
|
||||||
return "miles/hour";
|
case STANDARD, METRIC -> "meter/sec";
|
||||||
case STANDARD:
|
};
|
||||||
case METRIC:
|
|
||||||
default:
|
|
||||||
return "meter/sec";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,15 +63,11 @@ public enum UnitSystem {
|
|||||||
* @return temperature unit.
|
* @return temperature unit.
|
||||||
*/
|
*/
|
||||||
public String getTemperatureUnit() {
|
public String getTemperatureUnit() {
|
||||||
switch (this) {
|
return switch (this) {
|
||||||
case METRIC:
|
case METRIC -> "°C";
|
||||||
return "℃";
|
case IMPERIAL -> "°F";
|
||||||
case IMPERIAL:
|
case STANDARD -> "K";
|
||||||
return "℉";
|
};
|
||||||
case STANDARD:
|
|
||||||
default:
|
|
||||||
return "K";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,375 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.enums;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents weather condition and related information.
|
||||||
|
* More details <a href="https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2">here</a>.
|
||||||
|
*/
|
||||||
|
public enum WeatherCondition {
|
||||||
|
// Group 2xx: Thunderstorm
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The thunderstorm with light rain.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_LIGHT_RAIN(200, "Thunderstorm", "thunderstorm with light rain", "11"),
|
||||||
|
/**
|
||||||
|
* The thunderstorm with rain.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_RAIN(201, "Thunderstorm", "thunderstorm with rain", "11"),
|
||||||
|
/**
|
||||||
|
* The thunderstorm with heavy rain.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_HEAVY_RAIN(202, "Thunderstorm", "thunderstorm with heavy rain", "11"),
|
||||||
|
/**
|
||||||
|
* The light thunderstorm.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_LIGHT(210, "Thunderstorm", "light thunderstorm", "11"),
|
||||||
|
/**
|
||||||
|
* The thunderstorm.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM(211, "Thunderstorm", "thunderstorm", "11"),
|
||||||
|
/**
|
||||||
|
* The heavy thunderstorm.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_HEAVY(212, "Thunderstorm", "heavy thunderstorm", "11"),
|
||||||
|
/**
|
||||||
|
* The ragged thunderstorm.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_RAGGED(221, "Thunderstorm", "ragged thunderstorm", "11"),
|
||||||
|
/**
|
||||||
|
* The thunderstorm with light drizzle.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_LIGHT_DRIZZLE(230, "Thunderstorm", "thunderstorm with light drizzle", "11"),
|
||||||
|
/**
|
||||||
|
* The thunderstorm with drizzle.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_DRIZZLE(231, "Thunderstorm", "thunderstorm with drizzle", "11"),
|
||||||
|
/**
|
||||||
|
* The thunderstorm with heavy drizzle.
|
||||||
|
*/
|
||||||
|
THUNDERSTORM_HEAVY_DRIZZLE(232, "Thunderstorm", "thunderstorm with heavy drizzle", "11"),
|
||||||
|
|
||||||
|
// Group 3xx: Drizzle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The light intensity drizzle.
|
||||||
|
*/
|
||||||
|
DRIZZLE_LIGHT(300, "Drizzle", "light intensity drizzle", "09"),
|
||||||
|
/**
|
||||||
|
* The drizzle.
|
||||||
|
*/
|
||||||
|
DRIZZLE(301, "Drizzle", "drizzle", "09"),
|
||||||
|
/**
|
||||||
|
* The heavy intensity drizzle.
|
||||||
|
*/
|
||||||
|
DRIZZLE_HEAVY(302, "Drizzle", "heavy intensity drizzle", "09"),
|
||||||
|
/**
|
||||||
|
* The light intensity drizzle rain.
|
||||||
|
*/
|
||||||
|
DRIZZLE_LIGHT_RAIN(310, "Drizzle", "light intensity drizzle rain", "09"),
|
||||||
|
/**
|
||||||
|
* The drizzle rain.
|
||||||
|
*/
|
||||||
|
DRIZZLE_RAIN(311, "Drizzle", "drizzle rain", "09"),
|
||||||
|
/**
|
||||||
|
* The heavy intensity drizzle rain.
|
||||||
|
*/
|
||||||
|
DRIZZLE_HEAVY_RAIN(312, "Drizzle", "heavy intensity drizzle rain", "09"),
|
||||||
|
/**
|
||||||
|
* The shower rain and drizzle.
|
||||||
|
*/
|
||||||
|
DRIZZLE_SHOWER_RAIN(313, "Drizzle", "shower rain and drizzle", "09"),
|
||||||
|
/**
|
||||||
|
* The heavy shower rain and drizzle.
|
||||||
|
*/
|
||||||
|
DRIZZLE_HEAVY_SHOWER_RAIN(314, "Drizzle", "heavy shower rain and drizzle", "09"),
|
||||||
|
/**
|
||||||
|
* The shower drizzle.
|
||||||
|
*/
|
||||||
|
DRIZZLE_SHOWER(321, "Drizzle", "shower drizzle", "09"),
|
||||||
|
|
||||||
|
// Group 5xx: Rain
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The light rain.
|
||||||
|
*/
|
||||||
|
RAIN_LIGHT(500, "Rain", "light rain", "10"),
|
||||||
|
/**
|
||||||
|
* The moderate rain.
|
||||||
|
*/
|
||||||
|
RAIN_MODERATE(501, "Rain", "moderate rain", "10"),
|
||||||
|
/**
|
||||||
|
* The heavy intensity rain.
|
||||||
|
*/
|
||||||
|
RAIN_HEAVY(502, "Rain", "heavy intensity rain", "10"),
|
||||||
|
/**
|
||||||
|
* The very heavy rain.
|
||||||
|
*/
|
||||||
|
RAIN_VERY_HEAVY(503, "Rain", "very heavy rain", "10"),
|
||||||
|
/**
|
||||||
|
* The very heavy rain.
|
||||||
|
*/
|
||||||
|
RAIN_EXTREME(504, "Rain", "very heavy rain", "10"),
|
||||||
|
/**
|
||||||
|
* The freezing rain.
|
||||||
|
*/
|
||||||
|
RAIN_FREEZING(511, "Rain", "freezing rain", "10"),
|
||||||
|
/**
|
||||||
|
* The light intensity shower rain.
|
||||||
|
*/
|
||||||
|
RAIN_LIGHT_SHOWER(520, "Rain", "light intensity shower rain", "10"),
|
||||||
|
/**
|
||||||
|
* The shower rain.
|
||||||
|
*/
|
||||||
|
RAIN_SHOWER(521, "Rain", "shower rain", "10"),
|
||||||
|
/**
|
||||||
|
* The heavy intensity shower rain.
|
||||||
|
*/
|
||||||
|
RAIN_HEAVY_SHOWER(522, "Rain", "heavy intensity shower rain", "10"),
|
||||||
|
/**
|
||||||
|
* The ragged shower rain.
|
||||||
|
*/
|
||||||
|
RAIN_RAGGED_SHOWER(531, "Rain", "ragged shower rain", "10"),
|
||||||
|
|
||||||
|
// Group 6xx: Snow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The light snow.
|
||||||
|
*/
|
||||||
|
SNOW_LIGHT(600, "Snow", "light snow", "13"),
|
||||||
|
/**
|
||||||
|
* The snow.
|
||||||
|
*/
|
||||||
|
SNOW(601, "Snow", "snow", "13"),
|
||||||
|
/**
|
||||||
|
* The heavy snow.
|
||||||
|
*/
|
||||||
|
SNOW_HEAVY(602, "Snow", "heavy snow", "13"),
|
||||||
|
/**
|
||||||
|
* The sleet.
|
||||||
|
*/
|
||||||
|
SNOW_SLEET(611, "Snow", "sleet", "13"),
|
||||||
|
/**
|
||||||
|
* The light shower sleet.
|
||||||
|
*/
|
||||||
|
SNOW_LIGHT_SHOWER_SLEET(612, "Snow", "light shower sleet", "13"),
|
||||||
|
/**
|
||||||
|
* The shower sleet.
|
||||||
|
*/
|
||||||
|
SNOW_SHOWER_SLEET(613, "Snow", "shower sleet", "13"),
|
||||||
|
/**
|
||||||
|
* The light rain and snow.
|
||||||
|
*/
|
||||||
|
SNOW_LIGHT_RAIN_AND_SNOW(615, "Snow", "light rain and snow", "13"),
|
||||||
|
/**
|
||||||
|
* The rain and snow.
|
||||||
|
*/
|
||||||
|
SNOW_RAIN_AND_SNOW(616, "Snow", "rain and snow", "13"),
|
||||||
|
/**
|
||||||
|
* The light shower snow.
|
||||||
|
*/
|
||||||
|
SNOW_LIGHT_SHOWER_SNOW(620, "Snow", "light shower snow", "13"),
|
||||||
|
/**
|
||||||
|
* The shower snow.
|
||||||
|
*/
|
||||||
|
SNOW_SHOWER_SNOW(621, "Snow", "shower snow", "13"),
|
||||||
|
/**
|
||||||
|
* The heavy shower snow.
|
||||||
|
*/
|
||||||
|
SNOW_HEAVY_SHOWER_SNOW(622, "Snow", "heavy shower snow", "13"),
|
||||||
|
|
||||||
|
// Group 7xx: Atmosphere
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mist.
|
||||||
|
*/
|
||||||
|
MIST(701, "Mist", "mist", "50"),
|
||||||
|
/**
|
||||||
|
* The smoke.
|
||||||
|
*/
|
||||||
|
SMOKE(711, "Smoke", "smoke", "50"),
|
||||||
|
/**
|
||||||
|
* The haze.
|
||||||
|
*/
|
||||||
|
HAZE(721, "Haze", "haze", "50"),
|
||||||
|
/**
|
||||||
|
* The sand/dust whirls.
|
||||||
|
*/
|
||||||
|
DUST_WHIRLS(731, "Dust", "sand/dust whirls", "50"),
|
||||||
|
/**
|
||||||
|
* The fog.
|
||||||
|
*/
|
||||||
|
FOG(741, "Fog", "fog", "50"),
|
||||||
|
/**
|
||||||
|
* The sand.
|
||||||
|
*/
|
||||||
|
SAND(751, "Sand", "sand", "50"),
|
||||||
|
/**
|
||||||
|
* The dust.
|
||||||
|
*/
|
||||||
|
DUST(761, "Dust", "dust", "50"),
|
||||||
|
/**
|
||||||
|
* The volcanic ash.
|
||||||
|
*/
|
||||||
|
ASH(762, "Ash", "volcanic ash", "50"),
|
||||||
|
/**
|
||||||
|
* The squall.
|
||||||
|
*/
|
||||||
|
SQUALL(771, "Squall", "squalls", "50"),
|
||||||
|
/**
|
||||||
|
* The tornado.
|
||||||
|
*/
|
||||||
|
TORNADO(781, "Tornado", "tornado", "50"),
|
||||||
|
|
||||||
|
// Group 800: Clear
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The clear sky.
|
||||||
|
*/
|
||||||
|
CLEAR(800, "Clear", "clear sky", "01"),
|
||||||
|
|
||||||
|
// Group 80x: Clouds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A few clouds: 11-25%.
|
||||||
|
*/
|
||||||
|
CLOUDS_FEW(801, "Clouds", "few clouds: 11-25%", "02"),
|
||||||
|
/**
|
||||||
|
* A scattered clouds: 25-50%.
|
||||||
|
*/
|
||||||
|
CLOUDS_SCATTERED(802, "Clouds", "scattered clouds: 25-50%", "03"),
|
||||||
|
/**
|
||||||
|
* A broken clouds: 51-84%.
|
||||||
|
*/
|
||||||
|
CLOUDS_BROKEN(803, "Clouds", "broken clouds: 51-84%", "04"),
|
||||||
|
/**
|
||||||
|
* An overcast clouds: 85-100%.
|
||||||
|
*/
|
||||||
|
CLOUDS_OVERCAST(804, "Clouds", "overcast clouds: 85-100%", "04");
|
||||||
|
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final String name;
|
||||||
|
private final String description;
|
||||||
|
private final String iconId;
|
||||||
|
|
||||||
|
private WeatherCondition(int id, String name, String description, String iconId) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.iconId = iconId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 day icon id.
|
||||||
|
*
|
||||||
|
* @return the day icon id
|
||||||
|
*/
|
||||||
|
public String getDayIconId() {
|
||||||
|
return iconId + 'd';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets night icon id.
|
||||||
|
*
|
||||||
|
* @return the night icon id
|
||||||
|
*/
|
||||||
|
public String getNightIconId() {
|
||||||
|
return iconId + 'n';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets day icon url.
|
||||||
|
*
|
||||||
|
* @return the day icon url
|
||||||
|
*/
|
||||||
|
public String getDayIconUrl() {
|
||||||
|
return getIconUrl(getDayIconId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets night icon url.
|
||||||
|
*
|
||||||
|
* @return the night icon url
|
||||||
|
*/
|
||||||
|
public String getNightIconUrl() {
|
||||||
|
return getIconUrl(getNightIconId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets icon url.
|
||||||
|
*
|
||||||
|
* @param iconId the icon id
|
||||||
|
* @return the icon url
|
||||||
|
*/
|
||||||
|
public static String getIconUrl(String iconId) {
|
||||||
|
return "http://openweathermap.org/img/w/" + iconId + ".png";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets {@link WeatherCondition} by id.
|
||||||
|
*
|
||||||
|
* @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();
|
||||||
|
return optionalWeatherCondition.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Weather condition(" + id + "): " + name + '(' + description + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.github.prominence.openweathermap.api.model.WeatherState;
|
||||||
|
import com.github.prominence.openweathermap.api.utils.JsonDeserializationUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class AbstractMapper {
|
||||||
|
protected final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
protected LocalDateTime parseDateTime(JsonNode dateTimeNode) {
|
||||||
|
return JsonDeserializationUtils.parseDateTime(dateTimeNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ZoneId parseZoneId(JsonNode zoneIdNode) {
|
||||||
|
return JsonDeserializationUtils.parseZoneId(zoneIdNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ZoneOffset parseZoneOffset(JsonNode zoneOffsetNode) {
|
||||||
|
return JsonDeserializationUtils.parseZoneOffset(zoneOffsetNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<WeatherState> parseWeatherStates(JsonNode weatherArrayNode) throws IOException {
|
||||||
|
List<WeatherState> weatherStateList = new ArrayList<>();
|
||||||
|
if (weatherArrayNode != null && weatherArrayNode.isArray()) {
|
||||||
|
for (JsonNode weatherNode : weatherArrayNode) {
|
||||||
|
weatherStateList.add(objectMapper.readValue(objectMapper.treeAsTokens(weatherNode), WeatherState.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return weatherStateList;
|
||||||
|
}
|
||||||
|
}
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* 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.Coordinates;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation: <a href="https://openweathermap.org/api/air-pollution#fields">https://openweathermap.org/api/air-pollution#fields</a>.
|
||||||
|
*/
|
||||||
|
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 Coordinates parseCoordinate(JsonNode rootNode) {
|
||||||
|
final JsonNode latitudeNode = rootNode.get("lat");
|
||||||
|
final JsonNode longitudeNode = rootNode.get("lon");
|
||||||
|
if (latitudeNode != null && longitudeNode != null) {
|
||||||
|
return Coordinates.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
package com.github.prominence.openweathermap.api.mapper;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.InjectableValues;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.HumidityDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.WeatherStateDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.forecast.climatic.*;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Clouds;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Humidity;
|
||||||
|
import com.github.prominence.openweathermap.api.model.WeatherState;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Wind;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.climatic.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClimaticForecastResponseMapper extends AbstractMapper {
|
||||||
|
|
||||||
|
public ClimaticForecastResponseMapper(UnitSystem unitSystem) {
|
||||||
|
objectMapper.setInjectableValues(new InjectableValues.Std().addValue("unitSystem", unitSystem != null ? unitSystem : UnitSystem.STANDARD));
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(WeatherState.class, new WeatherStateDeserializer());
|
||||||
|
module.addDeserializer(Temperature.class, new ClimaticForecastTemperatureDeserializer());
|
||||||
|
module.addDeserializer(AtmosphericPressure.class, new ClimaticForecastAtmosphericPressureDeserializer());
|
||||||
|
module.addDeserializer(Humidity.class, new HumidityDeserializer());
|
||||||
|
module.addDeserializer(Clouds.class, new ClimaticForecastCloudsDeserializer());
|
||||||
|
module.addDeserializer(Rain.class, new ClimaticForecastRainDeserializer());
|
||||||
|
module.addDeserializer(Snow.class, new ClimaticForecastSnowDeserializer());
|
||||||
|
module.addDeserializer(Wind.class, new ClimaticForecastWindDeserializer());
|
||||||
|
module.addDeserializer(Location.class, new ClimaticForecastLocationDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Forecast mapToForecast(String json) {
|
||||||
|
Forecast forecast;
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
forecast = mapToForecast(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Forecast response", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Forecast mapToForecast(JsonNode root) throws IOException {
|
||||||
|
final Forecast forecast = new Forecast();
|
||||||
|
forecast.setLocation(objectMapper.readValue(objectMapper.treeAsTokens(root.get("city")), Location.class));
|
||||||
|
|
||||||
|
final List<WeatherForecast> forecasts = new ArrayList<>();
|
||||||
|
|
||||||
|
final JsonNode forecastListNode = root.get("list");
|
||||||
|
for (JsonNode forecastNode : forecastListNode) {
|
||||||
|
forecasts.add(parseWeatherForecast(forecastNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
forecast.setWeatherForecasts(forecasts);
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WeatherForecast parseWeatherForecast(JsonNode rootNode) throws IOException {
|
||||||
|
final WeatherForecast weatherForecast = new WeatherForecast();
|
||||||
|
|
||||||
|
weatherForecast.setForecastTime(parseDateTime(rootNode.get("dt")));
|
||||||
|
weatherForecast.setSunriseTime(parseDateTime(rootNode.get("sunrise")));
|
||||||
|
weatherForecast.setSunsetTime(parseDateTime(rootNode.get("sunset")));
|
||||||
|
|
||||||
|
weatherForecast.setWeatherStates(parseWeatherStates(rootNode.get("weather")));
|
||||||
|
|
||||||
|
weatherForecast.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Temperature.class));
|
||||||
|
weatherForecast.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), AtmosphericPressure.class));
|
||||||
|
weatherForecast.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Humidity.class));
|
||||||
|
weatherForecast.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Clouds.class));
|
||||||
|
weatherForecast.setWind(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Wind.class));
|
||||||
|
weatherForecast.setRain(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Rain.class));
|
||||||
|
weatherForecast.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Snow.class));
|
||||||
|
|
||||||
|
return weatherForecast;
|
||||||
|
}
|
||||||
|
}
|
||||||
+112
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* 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.databind.InjectableValues;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.*;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.weather.WeatherLocationDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.weather.WeatherRainDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.weather.WeatherSnowDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Location;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Rain;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Snow;
|
||||||
|
import com.github.prominence.openweathermap.api.model.weather.Weather;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation: <a href="https://openweathermap.org/current#current_JSON">https://openweathermap.org/current#current_JSON</a>.
|
||||||
|
* Ignored internal parameters: "root.cod", "sys.type", "sys.id", "sys.message".
|
||||||
|
*/
|
||||||
|
public class CurrentWeatherResponseMapper extends AbstractMapper {
|
||||||
|
/**
|
||||||
|
* Instantiates a new Current weather response mapper.
|
||||||
|
*
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public CurrentWeatherResponseMapper(UnitSystem unitSystem) {
|
||||||
|
objectMapper.setInjectableValues(new InjectableValues.Std().addValue("unitSystem", unitSystem != null ? unitSystem : UnitSystem.STANDARD));
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(WeatherState.class, new WeatherStateDeserializer());
|
||||||
|
module.addDeserializer(Temperature.class, new TemperatureDeserializer());
|
||||||
|
module.addDeserializer(AtmosphericPressure.class, new AtmosphericPressureDeserializer());
|
||||||
|
module.addDeserializer(Humidity.class, new HumidityDeserializer());
|
||||||
|
module.addDeserializer(Wind.class, new WindDeserializer());
|
||||||
|
module.addDeserializer(Rain.class, new WeatherRainDeserializer());
|
||||||
|
module.addDeserializer(Snow.class, new WeatherSnowDeserializer());
|
||||||
|
module.addDeserializer(Clouds.class, new CloudsDeserializer());
|
||||||
|
module.addDeserializer(Location.class, new WeatherLocationDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets single result.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the weather object
|
||||||
|
*/
|
||||||
|
public Weather mapToWeather(String json) {
|
||||||
|
Weather weather;
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
weather = mapToWeather(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Weather response", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return weather;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Weather mapToWeather(JsonNode rootNode) throws IOException {
|
||||||
|
final JsonNode weatherArrayNode = rootNode.get("weather");
|
||||||
|
final Weather weather = new Weather();
|
||||||
|
|
||||||
|
weather.setWeatherStates(parseWeatherStates(weatherArrayNode));
|
||||||
|
|
||||||
|
weather.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("main")), Temperature.class));
|
||||||
|
weather.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("main")), AtmosphericPressure.class));
|
||||||
|
weather.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("main")), Humidity.class));
|
||||||
|
weather.setWind(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("wind")), Wind.class));
|
||||||
|
if (rootNode.has("rain")) {
|
||||||
|
weather.setRain(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("rain")), Rain.class));
|
||||||
|
}
|
||||||
|
if (rootNode.has("snow")) {
|
||||||
|
weather.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("snow")), Snow.class));
|
||||||
|
}
|
||||||
|
weather.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("clouds")), Clouds.class));
|
||||||
|
weather.setLocation(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Location.class));
|
||||||
|
|
||||||
|
final JsonNode dtNode = rootNode.get("dt");
|
||||||
|
if (dtNode != null) {
|
||||||
|
weather.setCalculationTime(parseDateTime(dtNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
weather.setBase(rootNode.get("base").asText());
|
||||||
|
|
||||||
|
return weather;
|
||||||
|
}
|
||||||
|
}
|
||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* 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.databind.InjectableValues;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.HumidityDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.WeatherStateDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.WindDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.forecast.daily.*;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Clouds;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Humidity;
|
||||||
|
import com.github.prominence.openweathermap.api.model.WeatherState;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Wind;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.daily.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation: <a href="https://openweathermap.org/forecast16#JSON">https://openweathermap.org/forecast16#JSON</a>.
|
||||||
|
*/
|
||||||
|
public class DailyForecastResponseMapper extends AbstractMapper {
|
||||||
|
public DailyForecastResponseMapper(UnitSystem unitSystem) {
|
||||||
|
objectMapper.setInjectableValues(new InjectableValues.Std().addValue("unitSystem", unitSystem != null ? unitSystem : UnitSystem.STANDARD));
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(WeatherState.class, new WeatherStateDeserializer());
|
||||||
|
module.addDeserializer(Temperature.class, new DailyForecastTemperatureDeserializer());
|
||||||
|
module.addDeserializer(AtmosphericPressure.class, new DailyForecastAtmosphericPressureDeserializer());
|
||||||
|
module.addDeserializer(Humidity.class, new HumidityDeserializer());
|
||||||
|
module.addDeserializer(Clouds.class, new DailyForecastCloudsDeserializer());
|
||||||
|
module.addDeserializer(Rain.class, new DailyForecastRainDeserializer());
|
||||||
|
module.addDeserializer(Snow.class, new DailyForecastSnowDeserializer());
|
||||||
|
module.addDeserializer(Wind.class, new WindDeserializer());
|
||||||
|
module.addDeserializer(Location.class, new DailyForecastLocationDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps forecast response into java object.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the forecast
|
||||||
|
*/
|
||||||
|
public Forecast mapToForecast(String json) {
|
||||||
|
Forecast forecast;
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
forecast = mapToForecast(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Forecast response", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Forecast mapToForecast(JsonNode root) throws IOException {
|
||||||
|
final Forecast forecast = new Forecast();
|
||||||
|
forecast.setLocation(objectMapper.readValue(objectMapper.treeAsTokens(root.get("city")), Location.class));
|
||||||
|
|
||||||
|
final List<WeatherForecast> forecasts = new ArrayList<>(root.get("cnt").asInt());
|
||||||
|
|
||||||
|
final JsonNode forecastListNode = root.get("list");
|
||||||
|
for (JsonNode forecastNode : forecastListNode) {
|
||||||
|
forecasts.add(parseWeatherForecast(forecastNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
forecast.setWeatherForecasts(forecasts);
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WeatherForecast parseWeatherForecast(JsonNode rootNode) throws IOException {
|
||||||
|
final WeatherForecast weatherForecast = new WeatherForecast();
|
||||||
|
|
||||||
|
weatherForecast.setForecastTime(parseDateTime(rootNode.get("dt")));
|
||||||
|
weatherForecast.setSunriseTime(parseDateTime(rootNode.get("sunrise")));
|
||||||
|
weatherForecast.setSunsetTime(parseDateTime(rootNode.get("sunset")));
|
||||||
|
|
||||||
|
weatherForecast.setWeatherStates(parseWeatherStates(rootNode.get("weather")));
|
||||||
|
|
||||||
|
weatherForecast.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Temperature.class));
|
||||||
|
weatherForecast.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), AtmosphericPressure.class));
|
||||||
|
weatherForecast.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Humidity.class));
|
||||||
|
weatherForecast.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Clouds.class));
|
||||||
|
weatherForecast.setWind(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Wind.class));
|
||||||
|
weatherForecast.setRain(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Rain.class));
|
||||||
|
weatherForecast.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Snow.class));
|
||||||
|
|
||||||
|
if (rootNode.has("pop")) {
|
||||||
|
weatherForecast.setProbabilityOfPrecipitation(rootNode.get("pop").asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
return weatherForecast;
|
||||||
|
}
|
||||||
|
}
|
||||||
+229
@@ -0,0 +1,229 @@
|
|||||||
|
/*
|
||||||
|
* 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.databind.InjectableValues;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.AtmosphericPressureDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.TemperatureDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.WeatherStateDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.WindDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.free.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation: <a href="https://openweathermap.org/forecast5#JSON">https://openweathermap.org/forecast5#JSON</a>.
|
||||||
|
*/
|
||||||
|
public class FiveDayThreeHourStepForecastResponseMapper {
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast response mapper.
|
||||||
|
*
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public FiveDayThreeHourStepForecastResponseMapper(UnitSystem unitSystem) {
|
||||||
|
objectMapper.setInjectableValues(new InjectableValues.Std().addValue("unitSystem", unitSystem != null ? unitSystem : UnitSystem.STANDARD));
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(WeatherState.class, new WeatherStateDeserializer());
|
||||||
|
module.addDeserializer(Temperature.class, new TemperatureDeserializer());
|
||||||
|
module.addDeserializer(AtmosphericPressure.class, new AtmosphericPressureDeserializer());
|
||||||
|
module.addDeserializer(Wind.class, new WindDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps forecast response into java object.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the forecast
|
||||||
|
*/
|
||||||
|
public Forecast mapToForecast(String json) {
|
||||||
|
|
||||||
|
Forecast forecast;
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
forecast = mapToForecast(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Forecast response", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Forecast mapToForecast(JsonNode root) throws IOException {
|
||||||
|
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");
|
||||||
|
for (JsonNode forecastNode : forecastListNode) {
|
||||||
|
forecasts.add(parseWeatherForecast(forecastNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
forecast.setWeatherForecasts(forecasts);
|
||||||
|
|
||||||
|
return forecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WeatherForecast parseWeatherForecast(JsonNode rootNode) throws IOException {
|
||||||
|
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) throws IOException {
|
||||||
|
if (weatherNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return objectMapper.readValue(objectMapper.treeAsTokens(weatherNode), WeatherState.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Temperature parseTemperature(JsonNode rootNode) throws IOException {
|
||||||
|
return objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Temperature.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtmosphericPressure parsePressure(JsonNode rootNode) throws IOException {
|
||||||
|
return objectMapper.readValue(objectMapper.treeAsTokens(rootNode), AtmosphericPressure.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Humidity parseHumidity(JsonNode rootNode) {
|
||||||
|
return Humidity.withValue((byte) (rootNode.get("humidity").asInt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Wind parseWind(JsonNode root) throws IOException {
|
||||||
|
final JsonNode windNode = root.get("wind");
|
||||||
|
return objectMapper.readValue(objectMapper.treeAsTokens(windNode), Wind.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 Coordinates parseCoordinate(JsonNode rootNode) {
|
||||||
|
final JsonNode latitudeNode = rootNode.get("lat");
|
||||||
|
final JsonNode longitudeNode = rootNode.get("lon");
|
||||||
|
if (latitudeNode != null && longitudeNode != null) {
|
||||||
|
return Coordinates.of(latitudeNode.asDouble(), longitudeNode.asDouble());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.GeocodingRecordDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.ZipCodeGeocodingDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.model.geocoding.GeocodingRecord;
|
||||||
|
import com.github.prominence.openweathermap.api.model.geocoding.ZipCodeGeocodingRecord;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation: <a href="https://openweathermap.org/api/geocoding-api">https://openweathermap.org/api/geocoding-api</a>.
|
||||||
|
*/
|
||||||
|
public class GeocodingResponseMapper {
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
public GeocodingResponseMapper() {
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(GeocodingRecord.class, new GeocodingRecordDeserializer());
|
||||||
|
module.addDeserializer(ZipCodeGeocodingRecord.class, new ZipCodeGeocodingDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GeocodingRecord> mapGeocodingResponse(String json) {
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(json, new TypeReference<List<GeocodingRecord>>() {});
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException("Cannot parse ReverseGeocoding response.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZipCodeGeocodingRecord mapZipCodeGeocodingResponse(String json) {
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(json, ZipCodeGeocodingRecord.class);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new RuntimeException("Cannot parse GeocodingInfo response.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+143
@@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* 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.databind.InjectableValues;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.*;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.forecast.hourly.HourlyForecastLocationDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.forecast.hourly.HourlyForecastRainDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.forecast.hourly.HourlyForecastSnowDeserializer;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
import com.github.prominence.openweathermap.api.model.forecast.hourly.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation: <a href="https://openweathermap.org/api/hourly-forecast#JSON">https://openweathermap.org/api/hourly-forecast#JSON</a>.
|
||||||
|
*/
|
||||||
|
public class HourlyForecastResponseMapper extends AbstractMapper {
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast response mapper.
|
||||||
|
*
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public HourlyForecastResponseMapper(UnitSystem unitSystem) {
|
||||||
|
objectMapper.setInjectableValues(new InjectableValues.Std().addValue("unitSystem", unitSystem != null ? unitSystem : UnitSystem.STANDARD));
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(WeatherState.class, new WeatherStateDeserializer());
|
||||||
|
module.addDeserializer(Temperature.class, new TemperatureDeserializer());
|
||||||
|
module.addDeserializer(AtmosphericPressure.class, new AtmosphericPressureDeserializer());
|
||||||
|
module.addDeserializer(Wind.class, new WindDeserializer());
|
||||||
|
module.addDeserializer(Humidity.class, new HumidityDeserializer());
|
||||||
|
module.addDeserializer(Clouds.class, new CloudsDeserializer());
|
||||||
|
module.addDeserializer(Rain.class, new HourlyForecastRainDeserializer());
|
||||||
|
module.addDeserializer(Snow.class, new HourlyForecastSnowDeserializer());
|
||||||
|
module.addDeserializer(Location.class, new HourlyForecastLocationDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps forecast response into java object.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the forecast
|
||||||
|
*/
|
||||||
|
public HourlyForecast mapToForecast(String json) {
|
||||||
|
HourlyForecast hourlyForecast;
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
hourlyForecast = mapToForecast(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse Forecast response");
|
||||||
|
}
|
||||||
|
|
||||||
|
return hourlyForecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HourlyForecast mapToForecast(JsonNode root) throws IOException {
|
||||||
|
final HourlyForecast hourlyForecast = new HourlyForecast();
|
||||||
|
hourlyForecast.setLocation(objectMapper.readValue(objectMapper.treeAsTokens(root.get("city")), Location.class));
|
||||||
|
|
||||||
|
final List<WeatherForecast> forecasts = new ArrayList<>(root.get("cnt").asInt());
|
||||||
|
|
||||||
|
final JsonNode forecastListNode = root.get("list");
|
||||||
|
for (JsonNode forecastNode : forecastListNode) {
|
||||||
|
forecasts.add(parseWeatherForecast(forecastNode));
|
||||||
|
}
|
||||||
|
|
||||||
|
hourlyForecast.setWeatherForecasts(forecasts);
|
||||||
|
|
||||||
|
return hourlyForecast;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WeatherForecast parseWeatherForecast(JsonNode rootNode) throws IOException {
|
||||||
|
final WeatherForecast weatherForecast = new WeatherForecast();
|
||||||
|
|
||||||
|
final JsonNode weatherArrayNode = rootNode.get("weather");
|
||||||
|
if (weatherArrayNode != null && weatherArrayNode.isArray()) {
|
||||||
|
List<WeatherState> weatherStateList = new ArrayList<>();
|
||||||
|
for (JsonNode weatherNode : weatherArrayNode) {
|
||||||
|
weatherStateList.add(objectMapper.readValue(objectMapper.treeAsTokens(weatherNode), WeatherState.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
weatherForecast.setWeatherStates(weatherStateList);
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode mainNode = rootNode.get("main");
|
||||||
|
weatherForecast.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(mainNode), Temperature.class));
|
||||||
|
weatherForecast.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(mainNode), AtmosphericPressure.class));
|
||||||
|
weatherForecast.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(mainNode), Humidity.class));
|
||||||
|
weatherForecast.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("clouds")), Clouds.class));
|
||||||
|
weatherForecast.setWind(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("wind")), Wind.class));
|
||||||
|
if (rootNode.has("rain")) {
|
||||||
|
weatherForecast.setRain(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("rain")), Rain.class));
|
||||||
|
}
|
||||||
|
if (rootNode.has("snow")) {
|
||||||
|
weatherForecast.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(rootNode.get("snow")), Snow.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode sysNode = rootNode.get("sys");
|
||||||
|
if (sysNode != null) {
|
||||||
|
weatherForecast.setDayTime("d".equals(sysNode.get("pod").asText()) ? DayTime.DAY : DayTime.NIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootNode.has("visibility")) {
|
||||||
|
weatherForecast.setAverageVisibilityInMetres(rootNode.get("visibility").asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootNode.has("pop")) {
|
||||||
|
weatherForecast.setProbabilityOfPrecipitation(rootNode.get("pop").asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
weatherForecast.setForecastTime(parseDateTime(rootNode.get("dt")));
|
||||||
|
weatherForecast.setForecastTimeISO(rootNode.get("dt_txt").asText());
|
||||||
|
|
||||||
|
return weatherForecast;
|
||||||
|
}
|
||||||
|
}
|
||||||
+334
@@ -0,0 +1,334 @@
|
|||||||
|
/*
|
||||||
|
* 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.databind.InjectableValues;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.*;
|
||||||
|
import com.github.prominence.openweathermap.api.deserializer.onecall.*;
|
||||||
|
import com.github.prominence.openweathermap.api.enums.UnitSystem;
|
||||||
|
import com.github.prominence.openweathermap.api.model.*;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.AtmosphericPressure;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.Temperature;
|
||||||
|
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.HistoricalWeatherData;
|
||||||
|
import com.github.prominence.openweathermap.api.model.onecall.historical.HourlyHistorical;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Official API response documentation:
|
||||||
|
* <ul>
|
||||||
|
* <li></li><a href="https://openweathermap.org/api/one-call-api#parameter">https://openweathermap.org/api/one-call-api#parameter</a></li>
|
||||||
|
* <li></li><a href="https://openweathermap.org/api/one-call-api#hist_parameter">https://openweathermap.org/api/one-call-api#hist_parameter</a></li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
public class OneCallWeatherResponseMapper extends AbstractMapper {
|
||||||
|
/**
|
||||||
|
* Instantiates a new forecast response mapper.
|
||||||
|
*
|
||||||
|
* @param unitSystem the unit system
|
||||||
|
*/
|
||||||
|
public OneCallWeatherResponseMapper(UnitSystem unitSystem) {
|
||||||
|
objectMapper.setInjectableValues(new InjectableValues.Std().addValue("unitSystem", unitSystem != null ? unitSystem : UnitSystem.STANDARD));
|
||||||
|
final SimpleModule module = new SimpleModule();
|
||||||
|
module.addDeserializer(Coordinates.class, new CoordinatesDeserializer());
|
||||||
|
module.addDeserializer(AtmosphericPressure.class, new OneCallAtmosphericPressureDeserializer());
|
||||||
|
module.addDeserializer(Temperature.class, new OneCallTemperatureDeserializer());
|
||||||
|
module.addDeserializer(WeatherState.class, new WeatherStateDeserializer());
|
||||||
|
module.addDeserializer(Humidity.class, new HumidityDeserializer());
|
||||||
|
module.addDeserializer(Wind.class, new WindDeserializer());
|
||||||
|
module.addDeserializer(Clouds.class, new CloudsDeserializer());
|
||||||
|
module.addDeserializer(Rain.class, new OneCallRainDeserializer());
|
||||||
|
module.addDeserializer(Snow.class, new OneCallSnowDeserializer());
|
||||||
|
module.addDeserializer(DailyTemperature.class, new OneCallDailyTemperatureDeserializer());
|
||||||
|
module.addDeserializer(DailyRain.class, new OneCallDailyRainDeserializer());
|
||||||
|
module.addDeserializer(DailySnow.class, new OneCallDailySnowDeserializer());
|
||||||
|
module.addDeserializer(Alert.class, new AlertDeserializer());
|
||||||
|
objectMapper.registerModule(module);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps current weather data response into java object.
|
||||||
|
*
|
||||||
|
* @param json the json string
|
||||||
|
* @return the current data object
|
||||||
|
*/
|
||||||
|
public CurrentWeatherData mapToCurrent(String json) {
|
||||||
|
CurrentWeatherData currentData;
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
currentData = mapToCurrent(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse OneCall response", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
HistoricalWeatherData historicalData;
|
||||||
|
try {
|
||||||
|
final JsonNode root = objectMapper.readTree(json);
|
||||||
|
historicalData = mapToHistorical(root);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Cannot parse OneCall response");
|
||||||
|
}
|
||||||
|
|
||||||
|
return historicalData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CurrentWeatherData mapToCurrent(JsonNode rootNode) throws IOException {
|
||||||
|
final CurrentWeatherData currentData = new CurrentWeatherData();
|
||||||
|
currentData.setCoordinate(objectMapper.readValue(objectMapper.treeAsTokens(rootNode), Coordinates.class));
|
||||||
|
currentData.setTimezone(parseZoneId(rootNode.get("timezone")));
|
||||||
|
currentData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
||||||
|
|
||||||
|
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) throws IOException {
|
||||||
|
if (currentNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final Current current = new Current();
|
||||||
|
current.setForecastTime(parseDateTime(currentNode.get("dt")));
|
||||||
|
current.setSunriseTime(parseDateTime(currentNode.get("sunrise")));
|
||||||
|
current.setSunsetTime(parseDateTime(currentNode.get("sunset")));
|
||||||
|
|
||||||
|
current.setWeatherStates(parseWeatherStates(currentNode.get("weather")));
|
||||||
|
|
||||||
|
current.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Temperature.class));
|
||||||
|
current.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), AtmosphericPressure.class));
|
||||||
|
current.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Humidity.class));
|
||||||
|
current.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Clouds.class));
|
||||||
|
|
||||||
|
current.setUvIndex(currentNode.get("uvi").asDouble());
|
||||||
|
final JsonNode visibilityNode = currentNode.get("visibility");
|
||||||
|
if (visibilityNode != null) {
|
||||||
|
current.setVisibilityInMetres(visibilityNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
current.setWind(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Wind.class));
|
||||||
|
current.setRain(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Rain.class));
|
||||||
|
current.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Snow.class));
|
||||||
|
|
||||||
|
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(
|
||||||
|
parseDateTime(minutelyNode.get("dt")),
|
||||||
|
minutelyNode.get("precipitation").asDouble()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return minutelyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Hourly> parseHourlyList(JsonNode hourlyListNode) throws IOException {
|
||||||
|
if (hourlyListNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<Hourly> hourlyList = new ArrayList<>();
|
||||||
|
for (final JsonNode hourlyNode : hourlyListNode) {
|
||||||
|
final Hourly hourly = new Hourly();
|
||||||
|
hourly.setForecastTime(parseDateTime(hourlyNode.get("dt")));
|
||||||
|
|
||||||
|
hourly.setWeatherStates(parseWeatherStates(hourlyNode.get("weather")));
|
||||||
|
|
||||||
|
hourly.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Temperature.class));
|
||||||
|
hourly.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), AtmosphericPressure.class));
|
||||||
|
hourly.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Humidity.class));
|
||||||
|
hourly.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Clouds.class));
|
||||||
|
|
||||||
|
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(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Wind.class));
|
||||||
|
final JsonNode popNode = hourlyNode.get("pop");
|
||||||
|
if (popNode != null) {
|
||||||
|
hourly.setProbabilityOfPrecipitation(popNode.asDouble());
|
||||||
|
}
|
||||||
|
hourly.setRain(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Rain.class));
|
||||||
|
hourly.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Snow.class));
|
||||||
|
|
||||||
|
hourlyList.add(hourly);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hourlyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Daily> parseDailyList(JsonNode dailyListNode) throws IOException {
|
||||||
|
if (dailyListNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<Daily> dailyList = new ArrayList<>();
|
||||||
|
for (final JsonNode dailyNode : dailyListNode) {
|
||||||
|
final Daily daily = new Daily();
|
||||||
|
daily.setForecastTime(parseDateTime(dailyNode.get("dt")));
|
||||||
|
daily.setSunriseTime(parseDateTime(dailyNode.get("sunrise")));
|
||||||
|
daily.setSunsetTime(parseDateTime(dailyNode.get("sunset")));
|
||||||
|
final JsonNode moonriseTimeNode = dailyNode.get("moonrise");
|
||||||
|
if (moonriseTimeNode != null) {
|
||||||
|
daily.setMoonriseTime(parseDateTime(moonriseTimeNode));
|
||||||
|
}
|
||||||
|
final JsonNode moonsetTimeNode = dailyNode.get("moonset");
|
||||||
|
if (moonsetTimeNode != null) {
|
||||||
|
daily.setMoonsetTime(parseDateTime(moonsetTimeNode));
|
||||||
|
}
|
||||||
|
final JsonNode moonPhaseNode = dailyNode.get("moon_phase");
|
||||||
|
if (moonPhaseNode != null) {
|
||||||
|
daily.setMoonPhase(new MoonPhase(moonPhaseNode.asDouble()));
|
||||||
|
}
|
||||||
|
|
||||||
|
daily.setWeatherStates(parseWeatherStates(dailyNode.get("weather")));
|
||||||
|
|
||||||
|
daily.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(dailyNode), DailyTemperature.class));
|
||||||
|
daily.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(dailyNode), AtmosphericPressure.class));
|
||||||
|
daily.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(dailyNode), Humidity.class));
|
||||||
|
daily.setWind(objectMapper.readValue(objectMapper.treeAsTokens(dailyNode), Wind.class));
|
||||||
|
daily.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(dailyNode), Clouds.class));
|
||||||
|
daily.setUvIndex(dailyNode.get("uvi").asDouble());
|
||||||
|
daily.setProbabilityOfPrecipitation(dailyNode.get("pop").asDouble());
|
||||||
|
daily.setRain(objectMapper.readValue(objectMapper.treeAsTokens(dailyNode), DailyRain.class));
|
||||||
|
daily.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(dailyNode), DailySnow.class));
|
||||||
|
|
||||||
|
dailyList.add(daily);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dailyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Alert> parseAlerts(JsonNode alertsNode) throws IOException {
|
||||||
|
if (alertsNode == null || !alertsNode.isArray()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<Alert> alerts = new ArrayList<>();
|
||||||
|
for (final JsonNode alertNode : alertsNode) {
|
||||||
|
alerts.add(objectMapper.readValue(objectMapper.treeAsTokens(alertNode), Alert.class));
|
||||||
|
}
|
||||||
|
return alerts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HistoricalWeatherData mapToHistorical(JsonNode rootNode) throws IOException {
|
||||||
|
final HistoricalWeatherData historicalData = new HistoricalWeatherData();
|
||||||
|
historicalData.setCoordinate(Coordinates.of(rootNode.get("lat").asDouble(), rootNode.get("lon").asDouble()));
|
||||||
|
historicalData.setTimezone(parseZoneId(rootNode.get("timezone")));
|
||||||
|
historicalData.setTimezoneOffset(parseZoneOffset(rootNode.get("timezone_offset")));
|
||||||
|
historicalData.setHistoricalWeather(parseHistoricalWeather(rootNode.get("current")));
|
||||||
|
historicalData.setHourlyList(parseHourlyHistoricalList(rootNode.get("hourly")));
|
||||||
|
|
||||||
|
return historicalData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HistoricalWeather parseHistoricalWeather(JsonNode currentNode) throws IOException {
|
||||||
|
if (currentNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final HistoricalWeather historicalWeather = new HistoricalWeather();
|
||||||
|
historicalWeather.setForecastTime(parseDateTime(currentNode.get("dt")));
|
||||||
|
historicalWeather.setSunriseTime(parseDateTime(currentNode.get("sunrise")));
|
||||||
|
historicalWeather.setSunsetTime(parseDateTime(currentNode.get("sunset")));
|
||||||
|
|
||||||
|
historicalWeather.setWeatherStates(parseWeatherStates(currentNode.get("weather")));
|
||||||
|
|
||||||
|
historicalWeather.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Temperature.class));
|
||||||
|
historicalWeather.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), AtmosphericPressure.class));
|
||||||
|
historicalWeather.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Humidity.class));
|
||||||
|
historicalWeather.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Clouds.class));
|
||||||
|
|
||||||
|
final JsonNode uviNode = currentNode.get("uvi");
|
||||||
|
if (uviNode != null) {
|
||||||
|
historicalWeather.setUvIndex(uviNode.asDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
final JsonNode visibilityNode = currentNode.get("visibility");
|
||||||
|
if (visibilityNode != null) {
|
||||||
|
historicalWeather.setVisibilityInMetres(visibilityNode.asDouble());
|
||||||
|
}
|
||||||
|
historicalWeather.setWind(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Wind.class));
|
||||||
|
historicalWeather.setRain(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Rain.class));
|
||||||
|
historicalWeather.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(currentNode), Snow.class));
|
||||||
|
|
||||||
|
return historicalWeather;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<HourlyHistorical> parseHourlyHistoricalList(JsonNode hourlyListNode) throws IOException {
|
||||||
|
if (hourlyListNode == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<HourlyHistorical> hourlyList = new ArrayList<>();
|
||||||
|
for (final JsonNode hourlyNode : hourlyListNode) {
|
||||||
|
final HourlyHistorical hourly = new HourlyHistorical();
|
||||||
|
hourly.setForecastTime(parseDateTime(hourlyNode.get("dt")));
|
||||||
|
|
||||||
|
hourly.setWeatherStates(parseWeatherStates(hourlyNode.get("weather")));
|
||||||
|
|
||||||
|
hourly.setTemperature(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Temperature.class));
|
||||||
|
hourly.setAtmosphericPressure(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), AtmosphericPressure.class));
|
||||||
|
hourly.setHumidity(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Humidity.class));
|
||||||
|
hourly.setClouds(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Clouds.class));
|
||||||
|
|
||||||
|
final JsonNode visibilityNode = hourlyNode.get("visibility");
|
||||||
|
if (visibilityNode != null) {
|
||||||
|
hourly.setVisibilityInMetres(visibilityNode.asDouble());
|
||||||
|
}
|
||||||
|
hourly.setWind(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Wind.class));
|
||||||
|
hourly.setRain(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Rain.class));
|
||||||
|
hourly.setSnow(objectMapper.readValue(objectMapper.treeAsTokens(hourlyNode), Snow.class));
|
||||||
|
|
||||||
|
hourlyList.add(hourly);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hourlyList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,6 +48,7 @@ public class AtmosphericPressure {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method for {@link AtmosphericPressure} creation with value checking.
|
* Static method for {@link AtmosphericPressure} creation with value checking.
|
||||||
|
*
|
||||||
* @param value atmospheric pressure value.
|
* @param value atmospheric pressure value.
|
||||||
* @return instantiated {@link AtmosphericPressure} object.
|
* @return instantiated {@link AtmosphericPressure} object.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class Clouds {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Static method for {@link Clouds} creation with value checking.
|
* Static method for {@link Clouds} creation with value checking.
|
||||||
|
*
|
||||||
* @param value clouds percentage value.
|
* @param value clouds percentage value.
|
||||||
* @return instantiated {@link Clouds} object.
|
* @return instantiated {@link Clouds} object.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+20
-15
@@ -22,38 +22,40 @@
|
|||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model;
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents some location by its latitude and longitude.
|
* Represents some location by its latitude and longitude.
|
||||||
*/
|
*/
|
||||||
public class Coordinate {
|
public class Coordinates {
|
||||||
|
@JsonProperty("lat")
|
||||||
private double latitude;
|
private double latitude;
|
||||||
|
@JsonProperty("lon")
|
||||||
private double longitude;
|
private double longitude;
|
||||||
|
|
||||||
private Coordinate(double latitude, double longitude) {
|
private Coordinates() {
|
||||||
this.latitude = latitude;
|
|
||||||
this.longitude = longitude;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for {@link Coordinate} creation with correctness check.
|
* Method for {@link Coordinates} creation with correctness check.
|
||||||
|
*
|
||||||
* @param latitude latitude
|
* @param latitude latitude
|
||||||
* @param longitude longitude
|
* @param longitude longitude
|
||||||
* @return coordinate object.
|
* @return coordinate object.
|
||||||
*/
|
*/
|
||||||
public static Coordinate withValues(double latitude, double longitude) {
|
public static Coordinates of(double latitude, double longitude) {
|
||||||
if (latitude < -90 || latitude > 90) {
|
final Coordinates coordinates = new Coordinates();
|
||||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
coordinates.setLatitude(latitude);
|
||||||
}
|
coordinates.setLongitude(longitude);
|
||||||
if (longitude < -180 || longitude > 180) {
|
return coordinates;
|
||||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
|
||||||
}
|
|
||||||
return new Coordinate(latitude, longitude);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets latitude with checks.
|
* Sets latitude with checks.
|
||||||
|
*
|
||||||
* @param latitude latitude value
|
* @param latitude latitude value
|
||||||
*/
|
*/
|
||||||
public void setLatitude(double latitude) {
|
public void setLatitude(double latitude) {
|
||||||
@@ -65,6 +67,7 @@ public class Coordinate {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets longitude with checks.
|
* Sets longitude with checks.
|
||||||
|
*
|
||||||
* @param longitude longitude value
|
* @param longitude longitude value
|
||||||
*/
|
*/
|
||||||
public void setLongitude(double longitude) {
|
public void setLongitude(double longitude) {
|
||||||
@@ -76,6 +79,7 @@ public class Coordinate {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns latitude.
|
* Returns latitude.
|
||||||
|
*
|
||||||
* @return latitude
|
* @return latitude
|
||||||
*/
|
*/
|
||||||
public double getLatitude() {
|
public double getLatitude() {
|
||||||
@@ -84,6 +88,7 @@ public class Coordinate {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns longitude.
|
* Returns longitude.
|
||||||
|
*
|
||||||
* @return longitude
|
* @return longitude
|
||||||
*/
|
*/
|
||||||
public double getLongitude() {
|
public double getLongitude() {
|
||||||
@@ -93,8 +98,8 @@ public class Coordinate {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof Coordinate)) return false;
|
if (!(o instanceof Coordinates)) return false;
|
||||||
Coordinate that = (Coordinate) o;
|
Coordinates that = (Coordinates) o;
|
||||||
return Double.compare(that.latitude, latitude) == 0 &&
|
return Double.compare(that.latitude, latitude) == 0 &&
|
||||||
Double.compare(that.longitude, longitude) == 0;
|
Double.compare(that.longitude, longitude) == 0;
|
||||||
}
|
}
|
||||||
+11
-11
@@ -27,13 +27,13 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* Represents coordinate rectangle by its bottom-left and top-right coordinates.
|
* Represents coordinate rectangle by its bottom-left and top-right coordinates.
|
||||||
*/
|
*/
|
||||||
public class CoordinateRectangle {
|
public class CoordinatesRectangle {
|
||||||
private final double longitudeLeft;
|
private final double longitudeLeft;
|
||||||
private final double latitudeBottom;
|
private final double latitudeBottom;
|
||||||
private final double longitudeRight;
|
private final double longitudeRight;
|
||||||
private final double latitudeTop;
|
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.longitudeLeft = longitudeLeft;
|
||||||
this.latitudeBottom = latitudeBottom;
|
this.latitudeBottom = latitudeBottom;
|
||||||
this.longitudeRight = longitudeRight;
|
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 longitudeLeft left longitude
|
||||||
* @param latitudeBottom bottom latitude
|
* @param latitudeBottom bottom latitude
|
||||||
* @param longitudeRight right longitude
|
* @param longitudeRight right longitude
|
||||||
* @param latitudeTop tip latitude
|
* @param latitudeTop tip latitude
|
||||||
* @return coordinate rectangle object.
|
* @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) {
|
if (latitudeBottom < -90 || latitudeTop < -90 || latitudeBottom > 90 || latitudeTop > 90) {
|
||||||
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0].");
|
||||||
}
|
}
|
||||||
if (longitudeLeft < -180 || longitudeRight < -180 || longitudeLeft > 180 || longitudeRight > 180) {
|
if (longitudeLeft < -180 || longitudeRight < -180 || longitudeLeft > 180 || longitudeRight > 180) {
|
||||||
throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0].");
|
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
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof CoordinateRectangle)) return false;
|
if (!(o instanceof CoordinatesRectangle)) return false;
|
||||||
CoordinateRectangle rectangle = (CoordinateRectangle) o;
|
CoordinatesRectangle rectangle = (CoordinatesRectangle) o;
|
||||||
return Double.compare(rectangle.longitudeLeft, longitudeLeft) == 0 &&
|
return Double.compare(rectangle.longitudeLeft, longitudeLeft) == 0 &&
|
||||||
Double.compare(rectangle.latitudeBottom, latitudeBottom) == 0 &&
|
Double.compare(rectangle.latitudeBottom, latitudeBottom) == 0 &&
|
||||||
Double.compare(rectangle.longitudeRight, longitudeRight) == 0 &&
|
Double.compare(rectangle.longitudeRight, longitudeRight) == 0 &&
|
||||||
@@ -187,14 +187,14 @@ public class CoordinateRectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds {@link CoordinateRectangle} object with correctness check.
|
* Builds {@link CoordinatesRectangle} object with correctness check.
|
||||||
* @return {@link CoordinateRectangle} built object.
|
* @return {@link CoordinatesRectangle} built object.
|
||||||
*/
|
*/
|
||||||
public CoordinateRectangle build() {
|
public CoordinatesRectangle build() {
|
||||||
if (longitudeLeft == null || latitudeBottom == null || longitudeRight == null || latitudeTop == null) {
|
if (longitudeLeft == null || latitudeBottom == null || longitudeRight == null || latitudeTop == null) {
|
||||||
throw new IllegalStateException("Not all fields were set.");
|
throw new IllegalStateException("Not all fields were set.");
|
||||||
}
|
}
|
||||||
return new CoordinateRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
return new CoordinatesRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,7 @@ public class Humidity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link Humidity} object with correctness check.
|
* Creates {@link Humidity} object with correctness check.
|
||||||
|
*
|
||||||
* @param value humidity
|
* @param value humidity
|
||||||
* @return created {@link Humidity} object
|
* @return created {@link Humidity} object
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link Temperature} object with correctness check.
|
* Creates {@link Temperature} object with correctness check.
|
||||||
|
*
|
||||||
* @param value temperature value
|
* @param value temperature value
|
||||||
* @param unit temperature unit
|
* @param unit temperature unit
|
||||||
* @return temperature object
|
* @return temperature object
|
||||||
@@ -54,6 +55,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns temperature value.
|
* Returns temperature value.
|
||||||
|
*
|
||||||
* @return value
|
* @return value
|
||||||
*/
|
*/
|
||||||
public double getValue() {
|
public double getValue() {
|
||||||
@@ -62,6 +64,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets temperature value.
|
* Sets temperature value.
|
||||||
|
*
|
||||||
* @param value temperature
|
* @param value temperature
|
||||||
*/
|
*/
|
||||||
public void setValue(double value) {
|
public void setValue(double value) {
|
||||||
@@ -70,6 +73,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns maximal temperature value.
|
* Returns maximal temperature value.
|
||||||
|
*
|
||||||
* @return maximal temperature value
|
* @return maximal temperature value
|
||||||
*/
|
*/
|
||||||
public Double getMaxTemperature() {
|
public Double getMaxTemperature() {
|
||||||
@@ -78,6 +82,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets maximal temperature value.
|
* Sets maximal temperature value.
|
||||||
|
*
|
||||||
* @param maxTemperature maximal temperature
|
* @param maxTemperature maximal temperature
|
||||||
*/
|
*/
|
||||||
public void setMaxTemperature(Double maxTemperature) {
|
public void setMaxTemperature(Double maxTemperature) {
|
||||||
@@ -86,6 +91,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns minimal temperature value.
|
* Returns minimal temperature value.
|
||||||
|
*
|
||||||
* @return minimal temperature value
|
* @return minimal temperature value
|
||||||
*/
|
*/
|
||||||
public Double getMinTemperature() {
|
public Double getMinTemperature() {
|
||||||
@@ -94,6 +100,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets minimal temperature value.
|
* Sets minimal temperature value.
|
||||||
|
*
|
||||||
* @param minTemperature minimal temperature
|
* @param minTemperature minimal temperature
|
||||||
*/
|
*/
|
||||||
public void setMinTemperature(Double minTemperature) {
|
public void setMinTemperature(Double minTemperature) {
|
||||||
@@ -102,6 +109,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns 'feels like' temperature value.
|
* Returns 'feels like' temperature value.
|
||||||
|
*
|
||||||
* @return 'feels like' temperature value
|
* @return 'feels like' temperature value
|
||||||
*/
|
*/
|
||||||
public Double getFeelsLike() {
|
public Double getFeelsLike() {
|
||||||
@@ -110,6 +118,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets 'feels like' temperature value.
|
* Sets 'feels like' temperature value.
|
||||||
|
*
|
||||||
* @param feelsLike 'feels like' temperature
|
* @param feelsLike 'feels like' temperature
|
||||||
*/
|
*/
|
||||||
public void setFeelsLike(Double feelsLike) {
|
public void setFeelsLike(Double feelsLike) {
|
||||||
@@ -118,6 +127,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns temperature unit.
|
* Returns temperature unit.
|
||||||
|
*
|
||||||
* @return unit
|
* @return unit
|
||||||
*/
|
*/
|
||||||
public String getUnit() {
|
public String getUnit() {
|
||||||
@@ -126,6 +136,7 @@ public class Temperature {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets temperature unit with correctness check.
|
* Sets temperature unit with correctness check.
|
||||||
|
*
|
||||||
* @param unit temperature unit
|
* @param unit temperature unit
|
||||||
*/
|
*/
|
||||||
public void setUnit(String unit) {
|
public void setUnit(String unit) {
|
||||||
@@ -138,8 +149,7 @@ public class Temperature {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (!(o instanceof Temperature)) return false;
|
if (!(o instanceof Temperature that)) return false;
|
||||||
Temperature that = (Temperature) o;
|
|
||||||
return Double.compare(that.value, value) == 0 &&
|
return Double.compare(that.value, value) == 0 &&
|
||||||
Objects.equals(maxTemperature, that.maxTemperature) &&
|
Objects.equals(maxTemperature, that.maxTemperature) &&
|
||||||
Objects.equals(minTemperature, that.minTemperature) &&
|
Objects.equals(minTemperature, that.minTemperature) &&
|
||||||
@@ -154,7 +164,7 @@ public class Temperature {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append("Temperature: ");
|
stringBuilder.append("Temperature: ");
|
||||||
stringBuilder.append(value);
|
stringBuilder.append(value);
|
||||||
stringBuilder.append(' ');
|
stringBuilder.append(' ');
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
* 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 + ").";
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model.weather;
|
package com.github.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ public class Wind {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link Wind} object with correctness check.
|
* Creates {@link Wind} object with correctness check.
|
||||||
|
*
|
||||||
* @param speed the speed
|
* @param speed the speed
|
||||||
* @param unit the unitSystem
|
* @param unit the unitSystem
|
||||||
* @return wind object
|
* @return wind object
|
||||||
@@ -83,6 +84,7 @@ public class Wind {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets gust value.
|
* Gets gust value.
|
||||||
|
*
|
||||||
* @return the gust
|
* @return the gust
|
||||||
*/
|
*/
|
||||||
public Double getGust() {
|
public Double getGust() {
|
||||||
@@ -91,6 +93,7 @@ public class Wind {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets gust value.
|
* Sets gust value.
|
||||||
|
*
|
||||||
* @param gust the gust.
|
* @param gust the gust.
|
||||||
*/
|
*/
|
||||||
public void setGust(double gust) {
|
public void setGust(double gust) {
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* * Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
* *
|
||||||
|
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* * of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* * in the Software without restriction, including without limitation the rights
|
||||||
|
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* * copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* * furnished to do so, subject to the following conditions:
|
||||||
|
* *
|
||||||
|
* * The above copyright notice and this permission notice shall be included in all
|
||||||
|
* * copies or substantial portions of the Software.
|
||||||
|
* *
|
||||||
|
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* * SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Air pollution.
|
||||||
|
*/
|
||||||
|
public class AirPollutionDetails {
|
||||||
|
private Coordinates coordinates;
|
||||||
|
private List<AirPollutionRecord> airPollutionRecords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets coordinate.
|
||||||
|
*
|
||||||
|
* @return the coordinate
|
||||||
|
*/
|
||||||
|
public Coordinates getCoordinate() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets coordinate.
|
||||||
|
*
|
||||||
|
* @param coordinates the coordinate
|
||||||
|
*/
|
||||||
|
public void setCoordinate(Coordinates coordinates) {
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(coordinates, that.coordinates) && Objects.equals(airPollutionRecords, that.airPollutionRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(coordinates, airPollutionRecords);
|
||||||
|
}
|
||||||
|
}
|
||||||
+376
@@ -0,0 +1,376 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* * Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
* *
|
||||||
|
* * Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* * of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* * in the Software without restriction, including without limitation the rights
|
||||||
|
* * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* * copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* * furnished to do so, subject to the following conditions:
|
||||||
|
* *
|
||||||
|
* * The above copyright notice and this permission notice shall be included in all
|
||||||
|
* * copies or substantial portions of the Software.
|
||||||
|
* *
|
||||||
|
* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* * SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.air.pollution;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.enums.AirQualityIndex;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Air pollution record.
|
||||||
|
*/
|
||||||
|
public class AirPollutionRecord {
|
||||||
|
private LocalDateTime forecastTime;
|
||||||
|
private AirQualityIndex airQualityIndex;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(forecastTime, airQualityIndex, CO, NO, NO2, O3, SO2, PM2_5, PM10, NH3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;");
|
||||||
|
}
|
||||||
|
if (NO != null) {
|
||||||
|
stringBuilder
|
||||||
|
.append(" NO(Nitrogen monoxide) = ")
|
||||||
|
.append(NO)
|
||||||
|
.append(" μg/m^3;");
|
||||||
|
}
|
||||||
|
if (NO2 != null) {
|
||||||
|
stringBuilder
|
||||||
|
.append(" NO2(Nitrogen dioxide) = ")
|
||||||
|
.append(NO2)
|
||||||
|
.append(" μg/m^3;");
|
||||||
|
}
|
||||||
|
if (O3 != null) {
|
||||||
|
stringBuilder
|
||||||
|
.append(" O3(Ozone) = ")
|
||||||
|
.append(O3)
|
||||||
|
.append(" μg/m^3;");
|
||||||
|
}
|
||||||
|
if (SO2 != null) {
|
||||||
|
stringBuilder
|
||||||
|
.append(" SO2(Sulphur dioxide) = ")
|
||||||
|
.append(SO2)
|
||||||
|
.append(" μg/m^3;");
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
+98
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast.climatic;
|
||||||
|
|
||||||
|
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 seaLevelValue;
|
||||||
|
|
||||||
|
protected AtmosphericPressure() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method for {@link AtmosphericPressure} creation with value checking.
|
||||||
|
* @param seaLevelValue atmospheric pressure value.
|
||||||
|
* @return instantiated {@link AtmosphericPressure} object.
|
||||||
|
*/
|
||||||
|
public static AtmosphericPressure withValue(double seaLevelValue) {
|
||||||
|
final AtmosphericPressure atmosphericPressure = new AtmosphericPressure();
|
||||||
|
atmosphericPressure.setSeaLevelValue(seaLevelValue);
|
||||||
|
return atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 == null || getClass() != o.getClass()) return false;
|
||||||
|
AtmosphericPressure that = (AtmosphericPressure) o;
|
||||||
|
return Double.compare(that.seaLevelValue, seaLevelValue) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(seaLevelValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pressure: " + seaLevelValue + ' ' + getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.forecast.climatic;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents information about forecast for different timestamps.
|
||||||
|
*/
|
||||||
|
public class Forecast {
|
||||||
|
private Location location;
|
||||||
|
private List<? extends 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<? extends WeatherForecast> getWeatherForecasts() {
|
||||||
|
return weatherForecasts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets list of weather forecasts for different timestamps.
|
||||||
|
* @param weatherForecasts list of forecast information
|
||||||
|
*/
|
||||||
|
public void setWeatherForecasts(List<? extends 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.";
|
||||||
|
}
|
||||||
|
}
|
||||||
+198
@@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.forecast.climatic;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents location information.
|
||||||
|
*/
|
||||||
|
public class Location {
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String countryCode;
|
||||||
|
|
||||||
|
private ZoneOffset zoneOffset;
|
||||||
|
|
||||||
|
private Coordinates coordinates;
|
||||||
|
|
||||||
|
private Long population;
|
||||||
|
|
||||||
|
protected 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 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 Coordinates getCoordinate() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location coordinates.
|
||||||
|
* @param coordinates location coordinates
|
||||||
|
*/
|
||||||
|
public void setCoordinate(Coordinates coordinates) {
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(zoneOffset, location.zoneOffset) &&
|
||||||
|
Objects.equals(coordinates, location.coordinates) &&
|
||||||
|
Objects.equals(population, location.population);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, countryCode, zoneOffset, coordinates, population);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (coordinates != null) {
|
||||||
|
stringBuilder.append(coordinates);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
+97
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.forecast.climatic;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents rain information.
|
||||||
|
*/
|
||||||
|
public class Rain {
|
||||||
|
private static final String DEFAULT_UNIT = "mm";
|
||||||
|
|
||||||
|
private double level;
|
||||||
|
|
||||||
|
protected Rain(double level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Rain} object with correctness check.
|
||||||
|
* @param level rain level value
|
||||||
|
* @return rain object.
|
||||||
|
*/
|
||||||
|
public static Rain withValue(double level) {
|
||||||
|
if (level < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
return new Rain(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns rain level value.
|
||||||
|
* @return rain level value
|
||||||
|
*/
|
||||||
|
public double getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets rain level value with correctness check.
|
||||||
|
* @param level rain level value
|
||||||
|
*/
|
||||||
|
public void setLevel(double level) {
|
||||||
|
if (level < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.level, level) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Rain precipitation volume, mm: " +
|
||||||
|
level + ' ' +
|
||||||
|
getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
+97
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.forecast.climatic;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents snow information.
|
||||||
|
*/
|
||||||
|
public class Snow {
|
||||||
|
private static final String DEFAULT_UNIT = "mm";
|
||||||
|
|
||||||
|
private double level;
|
||||||
|
|
||||||
|
protected Snow(double level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Snow} object with correctness check.
|
||||||
|
* @param threeHourLevel snow level value
|
||||||
|
* @return snow object.
|
||||||
|
*/
|
||||||
|
public static Snow withValue(double threeHourLevel) {
|
||||||
|
if (threeHourLevel < 0) {
|
||||||
|
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||||
|
}
|
||||||
|
return new Snow(threeHourLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns snow level value.
|
||||||
|
* @return snow level value
|
||||||
|
*/
|
||||||
|
public double getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets snow level value with correctness check.
|
||||||
|
* @param level snow level value
|
||||||
|
*/
|
||||||
|
public void setLevel(double level) {
|
||||||
|
if (level < 0) {
|
||||||
|
throw new IllegalArgumentException("Snow level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.level, level) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Snow volume, mm: " +
|
||||||
|
level + ' ' +
|
||||||
|
getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
+263
@@ -0,0 +1,263 @@
|
|||||||
|
/*
|
||||||
|
* 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.climatic;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Daily temperature.
|
||||||
|
*/
|
||||||
|
public class Temperature {
|
||||||
|
private Double morning;
|
||||||
|
private Double morningFeelsLike;
|
||||||
|
private Double day;
|
||||||
|
private Double dayFeelsLike;
|
||||||
|
private Double eve;
|
||||||
|
private Double eveFeelsLike;
|
||||||
|
private Double night;
|
||||||
|
private Double nightFeelsLike;
|
||||||
|
private Double min;
|
||||||
|
private Double max;
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets morning temperature.
|
||||||
|
*
|
||||||
|
* @return the morning
|
||||||
|
*/
|
||||||
|
public Double getMorning() {
|
||||||
|
return morning;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets morning temperature.
|
||||||
|
*
|
||||||
|
* @param morning the morning
|
||||||
|
*/
|
||||||
|
public void setMorning(Double morning) {
|
||||||
|
this.morning = morning;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets morning feels like temperature.
|
||||||
|
*
|
||||||
|
* @return the morning feels like temperature
|
||||||
|
*/
|
||||||
|
public Double getMorningFeelsLike() {
|
||||||
|
return morningFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets morning feels like temperature.
|
||||||
|
*
|
||||||
|
* @param morningFeelsLike the morning feels like temperature
|
||||||
|
*/
|
||||||
|
public void setMorningFeelsLike(Double morningFeelsLike) {
|
||||||
|
this.morningFeelsLike = morningFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets day temperature.
|
||||||
|
*
|
||||||
|
* @return the day temperature
|
||||||
|
*/
|
||||||
|
public Double getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets day temperature.
|
||||||
|
*
|
||||||
|
* @param day the day temperature
|
||||||
|
*/
|
||||||
|
public void setDay(Double day) {
|
||||||
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets day feels like temperature.
|
||||||
|
*
|
||||||
|
* @return the day feels like temperature
|
||||||
|
*/
|
||||||
|
public Double getDayFeelsLike() {
|
||||||
|
return dayFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets day feels like temperature.
|
||||||
|
*
|
||||||
|
* @param dayFeelsLike the day feels like temperature
|
||||||
|
*/
|
||||||
|
public void setDayFeelsLike(Double dayFeelsLike) {
|
||||||
|
this.dayFeelsLike = dayFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets eve temperature.
|
||||||
|
*
|
||||||
|
* @return the eve temperature
|
||||||
|
*/
|
||||||
|
public Double getEve() {
|
||||||
|
return eve;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets eve temperature.
|
||||||
|
*
|
||||||
|
* @param eve the eve temperature
|
||||||
|
*/
|
||||||
|
public void setEve(Double eve) {
|
||||||
|
this.eve = eve;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets eve feels like temperature.
|
||||||
|
*
|
||||||
|
* @return the eve feels like temperature
|
||||||
|
*/
|
||||||
|
public Double getEveFeelsLike() {
|
||||||
|
return eveFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets eve feels like temperature.
|
||||||
|
*
|
||||||
|
* @param eveFeelsLike the eve feels like temperature
|
||||||
|
*/
|
||||||
|
public void setEveFeelsLike(Double eveFeelsLike) {
|
||||||
|
this.eveFeelsLike = eveFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets night temperature.
|
||||||
|
*
|
||||||
|
* @return the night temperature
|
||||||
|
*/
|
||||||
|
public Double getNight() {
|
||||||
|
return night;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets night temperature.
|
||||||
|
*
|
||||||
|
* @param night the night temperature
|
||||||
|
*/
|
||||||
|
public void setNight(Double night) {
|
||||||
|
this.night = night;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets night feels like temperature.
|
||||||
|
*
|
||||||
|
* @return the night feels like temperature
|
||||||
|
*/
|
||||||
|
public Double getNightFeelsLike() {
|
||||||
|
return nightFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets night feels like temperature.
|
||||||
|
*
|
||||||
|
* @param nightFeelsLike the night feels like temperature
|
||||||
|
*/
|
||||||
|
public void setNightFeelsLike(Double nightFeelsLike) {
|
||||||
|
this.nightFeelsLike = nightFeelsLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets min temperature.
|
||||||
|
*
|
||||||
|
* @return the min temperature
|
||||||
|
*/
|
||||||
|
public Double getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets min temperature.
|
||||||
|
*
|
||||||
|
* @param min the min temperature
|
||||||
|
*/
|
||||||
|
public void setMin(Double min) {
|
||||||
|
this.min = min;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets max temperature.
|
||||||
|
*
|
||||||
|
* @return the max temperature
|
||||||
|
*/
|
||||||
|
public Double getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets max temperature.
|
||||||
|
*
|
||||||
|
* @param max the max temperature
|
||||||
|
*/
|
||||||
|
public void setMax(Double max) {
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets unit temperature.
|
||||||
|
*
|
||||||
|
* @return the unit temperature
|
||||||
|
*/
|
||||||
|
public String getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets unit temperature.
|
||||||
|
*
|
||||||
|
* @param unit the unit temperature
|
||||||
|
*/
|
||||||
|
public void setUnit(String unit) {
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Temperature that = (Temperature) o;
|
||||||
|
return Objects.equals(morning, that.morning) &&
|
||||||
|
Objects.equals(morningFeelsLike, that.morningFeelsLike) &&
|
||||||
|
Objects.equals(day, that.day) &&
|
||||||
|
Objects.equals(dayFeelsLike, that.dayFeelsLike) &&
|
||||||
|
Objects.equals(eve, that.eve) &&
|
||||||
|
Objects.equals(eveFeelsLike, that.eveFeelsLike) &&
|
||||||
|
Objects.equals(night, that.night) &&
|
||||||
|
Objects.equals(nightFeelsLike, that.nightFeelsLike) &&
|
||||||
|
Objects.equals(min, that.min) &&
|
||||||
|
Objects.equals(max, that.max) &&
|
||||||
|
Objects.equals(unit, that.unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(morning, morningFeelsLike, day, dayFeelsLike, eve, eveFeelsLike, night, nightFeelsLike, min, max, unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
+295
@@ -0,0 +1,295 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.forecast.climatic;
|
||||||
|
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Clouds;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Humidity;
|
||||||
|
import com.github.prominence.openweathermap.api.model.WeatherState;
|
||||||
|
import com.github.prominence.openweathermap.api.model.Wind;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents weather forecast information for a particular timestamp.
|
||||||
|
*/
|
||||||
|
public class WeatherForecast {
|
||||||
|
private LocalDateTime forecastTime;
|
||||||
|
private LocalDateTime sunriseTime;
|
||||||
|
private LocalDateTime sunsetTime;
|
||||||
|
|
||||||
|
private List<WeatherState> weatherStates;
|
||||||
|
private Temperature temperature;
|
||||||
|
private AtmosphericPressure atmosphericPressure;
|
||||||
|
private Humidity humidity;
|
||||||
|
|
||||||
|
private Wind wind;
|
||||||
|
private Rain rain;
|
||||||
|
private Snow snow;
|
||||||
|
private Clouds clouds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getSunriseTime() {
|
||||||
|
return sunriseTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSunriseTime(LocalDateTime sunriseTime) {
|
||||||
|
this.sunriseTime = sunriseTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getSunsetTime() {
|
||||||
|
return sunsetTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSunsetTime(LocalDateTime sunsetTime) {
|
||||||
|
this.sunsetTime = sunsetTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets weather state.
|
||||||
|
*
|
||||||
|
* @return the weather state
|
||||||
|
*/
|
||||||
|
public List<WeatherState> getWeatherStates() {
|
||||||
|
return weatherStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets weather state.
|
||||||
|
*
|
||||||
|
* @param weatherStates the weather state
|
||||||
|
*/
|
||||||
|
public void setWeatherStates(List<WeatherState> weatherStates) {
|
||||||
|
this.weatherStates = weatherStates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(sunriseTime, that.sunriseTime) &&
|
||||||
|
Objects.equals(sunsetTime, that.sunsetTime) &&
|
||||||
|
Objects.equals(weatherStates, that.weatherStates) &&
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(forecastTime, sunriseTime, sunsetTime, weatherStates, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("Timestamp: ");
|
||||||
|
stringBuilder.append(forecastTime);
|
||||||
|
if (weatherStates != null && weatherStates.size() > 0) {
|
||||||
|
stringBuilder.append(", Weather: ");
|
||||||
|
stringBuilder.append(weatherStates.get(0).getDescription());
|
||||||
|
}
|
||||||
|
if (temperature != null) {
|
||||||
|
stringBuilder.append(", Min temperature: ");
|
||||||
|
stringBuilder.append(temperature.getMin());
|
||||||
|
stringBuilder.append(temperature.getUnit());
|
||||||
|
stringBuilder.append(", Max temperature: ");
|
||||||
|
stringBuilder.append(temperature.getMax());
|
||||||
|
stringBuilder.append(temperature.getUnit());
|
||||||
|
}
|
||||||
|
if (atmosphericPressure != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(atmosphericPressure.getSeaLevelValue());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(atmosphericPressure.getUnit());
|
||||||
|
}
|
||||||
|
if (clouds != null) {
|
||||||
|
stringBuilder.append(", ");
|
||||||
|
stringBuilder.append(clouds);
|
||||||
|
}
|
||||||
|
if (rain != null) {
|
||||||
|
stringBuilder.append(", Rain: ");
|
||||||
|
stringBuilder.append(rain.getLevel());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(rain.getUnit());
|
||||||
|
}
|
||||||
|
if (snow != null) {
|
||||||
|
stringBuilder.append(", Snow: ");
|
||||||
|
stringBuilder.append(snow.getLevel());
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(snow.getUnit());
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 Alexey Zinchenko
|
* Copyright (c) 2022 Alexey Zinchenko
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -20,12 +20,12 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.github.prominence.openweathermap.api.model.forecast;
|
package com.github.prominence.openweathermap.api.model.forecast.climatic;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents wind information.
|
* The type Wind.
|
||||||
*/
|
*/
|
||||||
public class Wind {
|
public class Wind {
|
||||||
private double speed;
|
private double speed;
|
||||||
@@ -44,10 +44,11 @@ public class Wind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link Wind} object with correctness check
|
* Creates {@link Wind} object with correctness check.
|
||||||
* @param speed the wind
|
*
|
||||||
|
* @param speed the speed
|
||||||
* @param unit the unitSystem
|
* @param unit the unitSystem
|
||||||
* @return created wind object
|
* @return wind object
|
||||||
*/
|
*/
|
||||||
public static Wind withValue(double speed, String unit) {
|
public static Wind withValue(double speed, String unit) {
|
||||||
if (speed < 0) {
|
if (speed < 0) {
|
||||||
+98
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Alexey Zinchenko
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.github.prominence.openweathermap.api.model.forecast.daily;
|
||||||
|
|
||||||
|
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 seaLevelValue;
|
||||||
|
|
||||||
|
protected AtmosphericPressure() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method for {@link AtmosphericPressure} creation with value checking.
|
||||||
|
* @param seaLevelValue atmospheric pressure value.
|
||||||
|
* @return instantiated {@link AtmosphericPressure} object.
|
||||||
|
*/
|
||||||
|
public static AtmosphericPressure withValue(double seaLevelValue) {
|
||||||
|
final AtmosphericPressure atmosphericPressure = new AtmosphericPressure();
|
||||||
|
atmosphericPressure.setSeaLevelValue(seaLevelValue);
|
||||||
|
return atmosphericPressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 == null || getClass() != o.getClass()) return false;
|
||||||
|
AtmosphericPressure that = (AtmosphericPressure) o;
|
||||||
|
return Double.compare(that.seaLevelValue, seaLevelValue) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(seaLevelValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Pressure: " + seaLevelValue + ' ' + getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.forecast.daily;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents information about forecast for different timestamps.
|
||||||
|
*/
|
||||||
|
public class Forecast {
|
||||||
|
private Location location;
|
||||||
|
private List<? extends 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<? extends WeatherForecast> getWeatherForecasts() {
|
||||||
|
return weatherForecasts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets list of weather forecasts for different timestamps.
|
||||||
|
* @param weatherForecasts list of forecast information
|
||||||
|
*/
|
||||||
|
public void setWeatherForecasts(List<? extends 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.";
|
||||||
|
}
|
||||||
|
}
|
||||||
+198
@@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
* 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.model.forecast.daily;
|
||||||
|
|
||||||
|
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents location information.
|
||||||
|
*/
|
||||||
|
public class Location {
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String countryCode;
|
||||||
|
|
||||||
|
private ZoneOffset zoneOffset;
|
||||||
|
|
||||||
|
private Coordinates coordinates;
|
||||||
|
|
||||||
|
private Long population;
|
||||||
|
|
||||||
|
protected 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 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 Coordinates getCoordinate() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location coordinates.
|
||||||
|
* @param coordinates location coordinates
|
||||||
|
*/
|
||||||
|
public void setCoordinate(Coordinates coordinates) {
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(zoneOffset, location.zoneOffset) &&
|
||||||
|
Objects.equals(coordinates, location.coordinates) &&
|
||||||
|
Objects.equals(population, location.population);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, countryCode, zoneOffset, coordinates, population);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (coordinates != null) {
|
||||||
|
stringBuilder.append(coordinates);
|
||||||
|
stringBuilder.append(". ");
|
||||||
|
}
|
||||||
|
stringBuilder.append("ID: ");
|
||||||
|
stringBuilder.append(id);
|
||||||
|
stringBuilder.append(", Name: ");
|
||||||
|
stringBuilder.append(name);
|
||||||
|
if (countryCode != null) {
|
||||||
|
stringBuilder.append('(');
|
||||||
|
stringBuilder.append(countryCode);
|
||||||
|
stringBuilder.append(')');
|
||||||
|
}
|
||||||
|
if (population != null) {
|
||||||
|
stringBuilder.append(", Population: ");
|
||||||
|
stringBuilder.append(population);
|
||||||
|
}
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 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.model.forecast.daily;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents rain information.
|
||||||
|
*/
|
||||||
|
public class Rain {
|
||||||
|
private static final String DEFAULT_UNIT = "mm";
|
||||||
|
|
||||||
|
private double level;
|
||||||
|
|
||||||
|
protected Rain(double level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates {@link Rain} object with correctness check.
|
||||||
|
* @param level rain level value
|
||||||
|
* @return rain object.
|
||||||
|
*/
|
||||||
|
public static Rain withValue(double level) {
|
||||||
|
if (level < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
return new Rain(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns rain level value.
|
||||||
|
* @return rain level value
|
||||||
|
*/
|
||||||
|
public double getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets rain level value with correctness check.
|
||||||
|
* @param level rain level value
|
||||||
|
*/
|
||||||
|
public void setLevel(double level) {
|
||||||
|
if (level < 0) {
|
||||||
|
throw new IllegalArgumentException("Rain level value cannot be negative.");
|
||||||
|
}
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.level, level) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Rain precipitation volume, mm: " +
|
||||||
|
level + ' ' +
|
||||||
|
getUnit();
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user