mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 11:16:44 +03:00
Adjusted to use 17 source and 8 target version. Code refactoring. Docs improvements.
This commit is contained in:
@@ -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";
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user