Adjusted to use 17 source and 8 target version. Code refactoring. Docs improvements.

This commit is contained in:
Prominence 2022-04-19 22:15:19 +03:00
parent 5ca31780da
commit 8ca55b15f7
No known key found for this signature in database
GPG Key ID: B5C2DFCB54798A7B
12 changed files with 37 additions and 40 deletions

View File

@ -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")

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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 "";
}
return switch (this) {
case METRIC -> "°C";
case IMPERIAL -> "°F";
case STANDARD -> "";
};
}
/**

View File

@ -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);