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

This commit is contained in:
2022-04-19 22:15:19 +03:00
parent 5ca31780da
commit 8ca55b15f7
12 changed files with 37 additions and 40 deletions
@@ -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 -> "";
};
}
/**
@@ -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);