From 8ca55b15f7242f71432a87881607a77ca69aa154 Mon Sep 17 00:00:00 2001 From: Prominence Date: Tue, 19 Apr 2022 22:15:19 +0300 Subject: [PATCH] Adjusted to use 17 source and 8 target version. Code refactoring. Docs improvements. --- build.gradle | 12 ++++++++- docs/Release_1.0.md | 2 +- docs/Release_1.1.md | 2 +- docs/Release_1.2.md | 2 +- docs/Release_2.0.0.md | 2 +- docs/Release_2.0.1.md | 2 +- docs/Release_2.1.0.md | 2 +- docs/Release_2.1.1.md | 2 +- docs/Release_2.2.0.md | 2 +- docs/Release_2.3.0.md | 2 +- .../openweathermap/api/enums/UnitSystem.java | 26 +++++++------------ .../api/utils/RequestUtils.java | 21 ++++++--------- 12 files changed, 37 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 48bf2f9..b15edae 100644 --- a/build.gradle +++ b/build.gradle @@ -17,12 +17,22 @@ dependencies { 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' -java.sourceCompatibility = JavaVersion.VERSION_17 + +configure([tasks.compileJava]) { + sourceCompatibility = 17 // for the IDE support + options.release = 8 + + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(17) + } +} ext { isReleaseVersion = !version.endsWith("SNAPSHOT") diff --git a/docs/Release_1.0.md b/docs/Release_1.0.md index a645dc4..098ff6e 100644 --- a/docs/Release_1.0.md +++ b/docs/Release_1.0.md @@ -15,7 +15,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:1.0') +implementation 'com.github.prominence:openweathermap-api:1.0' ``` ### How to use: diff --git a/docs/Release_1.1.md b/docs/Release_1.1.md index b17edc6..b531755 100644 --- a/docs/Release_1.1.md +++ b/docs/Release_1.1.md @@ -18,7 +18,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:1.1') +implementation 'com.github.prominence:openweathermap-api:1.1' ``` ### How to use: diff --git a/docs/Release_1.2.md b/docs/Release_1.2.md index 350cd03..8e3da82 100644 --- a/docs/Release_1.2.md +++ b/docs/Release_1.2.md @@ -18,7 +18,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:1.2') +implementation 'com.github.prominence:openweathermap-api:1.2' ``` ### How to use: diff --git a/docs/Release_2.0.0.md b/docs/Release_2.0.0.md index 491d13d..248548c 100644 --- a/docs/Release_2.0.0.md +++ b/docs/Release_2.0.0.md @@ -15,7 +15,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:2.0.0') +implementation 'com.github.prominence:openweathermap-api:2.0.0' ``` ### How to use: diff --git a/docs/Release_2.0.1.md b/docs/Release_2.0.1.md index 2858a11..eea6ede 100644 --- a/docs/Release_2.0.1.md +++ b/docs/Release_2.0.1.md @@ -15,7 +15,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:2.0.1') +implementation 'com.github.prominence:openweathermap-api:2.0.1' ``` ### How to use: diff --git a/docs/Release_2.1.0.md b/docs/Release_2.1.0.md index b20ea78..1e192d3 100644 --- a/docs/Release_2.1.0.md +++ b/docs/Release_2.1.0.md @@ -16,7 +16,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:2.1.0') +implementation 'com.github.prominence:openweathermap-api:2.1.0' ``` ### How to use: diff --git a/docs/Release_2.1.1.md b/docs/Release_2.1.1.md index 843e369..249cdab 100644 --- a/docs/Release_2.1.1.md +++ b/docs/Release_2.1.1.md @@ -16,7 +16,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:2.1.1') +implementation 'com.github.prominence:openweathermap-api:2.1.1' ``` ### How to use: diff --git a/docs/Release_2.2.0.md b/docs/Release_2.2.0.md index 5d4495f..2e21ddd 100644 --- a/docs/Release_2.2.0.md +++ b/docs/Release_2.2.0.md @@ -17,7 +17,7 @@ ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:2.2.0') +implementation 'com.github.prominence:openweathermap-api:2.2.0' ``` ### How to use: diff --git a/docs/Release_2.3.0.md b/docs/Release_2.3.0.md index d1fe83b..1c3b9f8 100644 --- a/docs/Release_2.3.0.md +++ b/docs/Release_2.3.0.md @@ -21,7 +21,7 @@ Other: ### Gradle coordinates: ```groovy -compile('com.github.prominence:openweathermap-api:2.3.0') +implementation 'com.github.prominence:openweathermap-api:2.3.0' ``` ### How to use: diff --git a/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java b/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java index 8c1ce94..979971c 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java +++ b/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java @@ -52,14 +52,10 @@ public enum UnitSystem { * @return wind unit. */ public String getWindUnit() { - switch (this) { - case IMPERIAL: - return "miles/hour"; - case STANDARD: - case METRIC: - default: - return "meter/sec"; - } + return switch (this) { + case IMPERIAL -> "miles/hour"; + case STANDARD, METRIC -> "meter/sec"; + }; } /** @@ -67,15 +63,11 @@ public enum UnitSystem { * @return temperature unit. */ public String getTemperatureUnit() { - switch (this) { - case METRIC: - return "°C"; - case IMPERIAL: - return "°F"; - case STANDARD: - default: - return "K"; - } + return switch (this) { + case METRIC -> "°C"; + case IMPERIAL -> "°F"; + case STANDARD -> "K"; + }; } /** diff --git a/src/main/java/com/github/prominence/openweathermap/api/utils/RequestUtils.java b/src/main/java/com/github/prominence/openweathermap/api/utils/RequestUtils.java index c20ec6d..cbb39a7 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/utils/RequestUtils.java +++ b/src/main/java/com/github/prominence/openweathermap/api/utils/RequestUtils.java @@ -44,7 +44,7 @@ import java.util.stream.Collectors; */ public final class RequestUtils { - private static final String OWM_URL_BASE = "http://api.openweathermap.org/data/2.5/"; + private static final String OWM_URL_BASE = "https://api.openweathermap.org/data/2.5/"; private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class); @@ -120,18 +120,13 @@ public final class RequestUtils { connection.setRequestMethod("GET"); - switch (connection.getResponseCode()) { - case HttpURLConnection.HTTP_OK: - resultStream = connection.getInputStream(); - break; - case HttpURLConnection.HTTP_UNAUTHORIZED: - throw new InvalidAuthTokenException(); - case HttpURLConnection.HTTP_NOT_FOUND: - case HttpURLConnection.HTTP_BAD_REQUEST: - throw new NoDataFoundException(); - default: - throw new IllegalStateException("Unexpected value: " + connection.getResponseCode()); - } + resultStream = switch (connection.getResponseCode()) { + case HttpURLConnection.HTTP_OK -> connection.getInputStream(); + case HttpURLConnection.HTTP_UNAUTHORIZED -> throw new InvalidAuthTokenException(); + case HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST -> + throw new NoDataFoundException(); + default -> throw new IllegalStateException("Unexpected value: " + connection.getResponseCode()); + }; } catch (IllegalStateException | IOException ex) { logger.error("An error occurred during OpenWeatherMap API response parsing: ", ex); throw new NoDataFoundException(ex);