From b0cbf1135d9aafe0a1b05370db00014ef5cd002d Mon Sep 17 00:00:00 2001 From: Prominence Date: Tue, 17 Jul 2018 23:45:57 +0300 Subject: [PATCH] Checked visibility. Removed unused exceptions' constructors. Renamed sunruse/sunset methods and variables. Updated documentation. --- README.md | 26 ++++++------ .../api/constants/Accuracy.java | 4 +- .../api/constants/Language.java | 4 +- .../openweathermap/api/constants/System.java | 4 +- .../openweathermap/api/constants/Unit.java | 4 +- .../api/exception/DataNotFoundException.java | 3 -- .../exception/InvalidAuthTokenException.java | 5 +-- .../openweathermap/api/model/Rain.java | 2 +- .../api/model/response/HourlyForecast.java | 4 +- .../api/model/response/Weather.java | 42 +++++++++++-------- .../openweathermap/api/utils/JsonUtils.java | 4 +- .../api/utils/RequestUtils.java | 4 +- 12 files changed, 60 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 8f9b11c..779a3d0 100644 --- a/README.md +++ b/README.md @@ -56,18 +56,18 @@ Available requests: | `getCityId()` | Returns city ID. Example: `625144` for Minsk. | | `getCityName()` | Returns city name. Example: `Minsk`. | | `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. | -| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. | +| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. | | `getBase()` | Returns `String` with some internal information. Example: `cmc stations` - from official documentation. | -| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. | +| `getWeatherInfo()` | Returns `Weather.WeatherInfo` instance that contains information about temperature, pressure and humidity. | | `getWind()` | Returns `Wind` instance that contains information about speed and degree. | | `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. | | `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. | | `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. | | `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. | -| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset times. | +| `getWeatherSystemInfo()` | Returns `Weather.WeatherSystemInfo` instance that contains internal information. There is also an information about country, sunrise and sunset time. | | `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. | | `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. | -| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. | +| `getWeatherDescription()` | An alias for `getWeatherStates.get(0).getDescription()`. | | `getDataCalculationDate()`| Returns data calculation time in `Date` representation. | | `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. | | `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. | @@ -121,20 +121,20 @@ Available requests: | `getCityId()` | Returns city ID. Example: `625144` for Minsk. | | `getCityName()` | Returns city name. Example: `Minsk`. | | `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. | -| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. | +| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. | | `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. | | `getCountry()` | An alias for `getCityInfo().getCountry()`. | -| `getForecasts()` | Returns `List` collection with all forecast information. | +| `getForecasts()` | Returns `List` collection with all forecast information. | | `getAverageTemperature()` | Returns average temperature from forecasts. | | `getMinimumTemperature()` | Returns minimum temperature from forecasts. | | `getMaximumTemperature()` | Returns maximum temperature from forecasts. | -| `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. | -| `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. | +| `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. | +| `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. | | `getAveragePressure()` | Returns average pressure from forecasts. | | `getMinimumPressure()` | Returns minimum pressure from forecasts. | | `getMaximumPressure()` | Returns maximum pressure from forecasts. | -| `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. | -| `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. | +| `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. | +| `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. | | `toString()` | Returns pretty string for the whole available forecast information. | `toString()` output example: @@ -190,13 +190,13 @@ Forecasts: |-----------------------------|------------------------------------------------------------------------------------------------------------------| | `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. | | `getDataCalculationDate()` | Returns data calculation time in `Date` representation. | -| `getMainInfo()` | Returns `HourlyForecast.MainInfo` instance that contains information about temperature, pressure and humidity. | -| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. | +| `getMainInfo()` | Returns `HourlyForecast.MainInfo` instance that contains information about temperature, pressure and humidity. | +| `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. | | `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. | | `getWind()` | Returns `Wind` instance that contains information about speed and degree. | | `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. | | `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. | -| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. | +| `getSystemInfo()` | Returns `HourlyForecast.ForecastSystemInfo` instance with internal information. | | `getDt_txt()` | Returns `String` value that represents data calculation time. | | `toString()` | Returns pretty string for the whole available weather information. | diff --git a/src/main/java/by/prominence/openweathermap/api/constants/Accuracy.java b/src/main/java/by/prominence/openweathermap/api/constants/Accuracy.java index 724aa52..6554cf7 100644 --- a/src/main/java/by/prominence/openweathermap/api/constants/Accuracy.java +++ b/src/main/java/by/prominence/openweathermap/api/constants/Accuracy.java @@ -22,7 +22,9 @@ package by.prominence.openweathermap.api.constants; -public class Accuracy { +public final class Accuracy { + + private Accuracy() {} public static final String LIKE = "like"; public static final String ACCURATE = "accurate"; diff --git a/src/main/java/by/prominence/openweathermap/api/constants/Language.java b/src/main/java/by/prominence/openweathermap/api/constants/Language.java index 72b159e..34417b2 100644 --- a/src/main/java/by/prominence/openweathermap/api/constants/Language.java +++ b/src/main/java/by/prominence/openweathermap/api/constants/Language.java @@ -22,7 +22,9 @@ package by.prominence.openweathermap.api.constants; -public class Language { +public final class Language { + + private Language() {} public static final String ARABIC = "ar"; public static final String BULGARIAN = "bg"; diff --git a/src/main/java/by/prominence/openweathermap/api/constants/System.java b/src/main/java/by/prominence/openweathermap/api/constants/System.java index 48bc03c..96f0848 100644 --- a/src/main/java/by/prominence/openweathermap/api/constants/System.java +++ b/src/main/java/by/prominence/openweathermap/api/constants/System.java @@ -22,7 +22,9 @@ package by.prominence.openweathermap.api.constants; -public class System { +public final class System { + + private System() {} public static final String OPEN_WEATHER_API_VERSION = "2.5"; public static final String OPEN_WEATHER_API_URL = "http://api.openweathermap.org/data/" + OPEN_WEATHER_API_VERSION + "/"; diff --git a/src/main/java/by/prominence/openweathermap/api/constants/Unit.java b/src/main/java/by/prominence/openweathermap/api/constants/Unit.java index bd16609..532dde0 100644 --- a/src/main/java/by/prominence/openweathermap/api/constants/Unit.java +++ b/src/main/java/by/prominence/openweathermap/api/constants/Unit.java @@ -22,7 +22,9 @@ package by.prominence.openweathermap.api.constants; -public class Unit { +public final class Unit { + + private Unit() {} public static final String METRIC_SYSTEM = "metric"; public static final String IMPERIAL_SYSTEM = "imperial"; diff --git a/src/main/java/by/prominence/openweathermap/api/exception/DataNotFoundException.java b/src/main/java/by/prominence/openweathermap/api/exception/DataNotFoundException.java index 4f3149f..00d5e74 100644 --- a/src/main/java/by/prominence/openweathermap/api/exception/DataNotFoundException.java +++ b/src/main/java/by/prominence/openweathermap/api/exception/DataNotFoundException.java @@ -28,7 +28,4 @@ public class DataNotFoundException extends Exception { super("Data for provided parameters wasn't found. Please, check your request."); } - public DataNotFoundException(String message) { - super(message); - } } diff --git a/src/main/java/by/prominence/openweathermap/api/exception/InvalidAuthTokenException.java b/src/main/java/by/prominence/openweathermap/api/exception/InvalidAuthTokenException.java index 61adbe9..1f1c0af 100644 --- a/src/main/java/by/prominence/openweathermap/api/exception/InvalidAuthTokenException.java +++ b/src/main/java/by/prominence/openweathermap/api/exception/InvalidAuthTokenException.java @@ -25,10 +25,7 @@ package by.prominence.openweathermap.api.exception; public class InvalidAuthTokenException extends Exception { public InvalidAuthTokenException() { - super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/. Please, notice that some requests requires non-free subscription plan."); + super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/."); } - public InvalidAuthTokenException(String message) { - super(message); - } } diff --git a/src/main/java/by/prominence/openweathermap/api/model/Rain.java b/src/main/java/by/prominence/openweathermap/api/model/Rain.java index 25050d3..6935f5b 100644 --- a/src/main/java/by/prominence/openweathermap/api/model/Rain.java +++ b/src/main/java/by/prominence/openweathermap/api/model/Rain.java @@ -30,7 +30,7 @@ public class Rain { @JSONField(name = "3h") // Rain volume for the last 3 hours - byte rainVolumeLast3Hrs; + private byte rainVolumeLast3Hrs; public byte getRainVolumeLast3Hrs() { return rainVolumeLast3Hrs; diff --git a/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java b/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java index 6838d00..43c3032 100644 --- a/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java +++ b/src/main/java/by/prominence/openweathermap/api/model/response/HourlyForecast.java @@ -174,10 +174,10 @@ public class HourlyForecast implements OpenWeatherResponse { public static class CityInfo { - // CityInfo ID + // City ID private long id; - // CityInfo name + // City name private String name; @JSONField(name = "coord") diff --git a/src/main/java/by/prominence/openweathermap/api/model/response/Weather.java b/src/main/java/by/prominence/openweathermap/api/model/response/Weather.java index 3dfec55..3398f44 100644 --- a/src/main/java/by/prominence/openweathermap/api/model/response/Weather.java +++ b/src/main/java/by/prominence/openweathermap/api/model/response/Weather.java @@ -424,11 +424,11 @@ public class Weather implements OpenWeatherResponse { @JSONField(name = "sunrise") // Sunrise time, unix, UTC - private long sunrise; + private long sunriseTimestamp; @JSONField(name = "sunset") // Sunset time, unix, UTC - private long sunset; + private long sunsetTimestamp; public short getType() { return type; @@ -462,20 +462,28 @@ public class Weather implements OpenWeatherResponse { this.country = country; } - public long getSunrise() { - return sunrise; + public long getSunriseTimestamp() { + return sunriseTimestamp; } - public void setSunrise(long sunrise) { - this.sunrise = sunrise; + public void setSunriseTimestamp(long sunriseTimestamp) { + this.sunriseTimestamp = sunriseTimestamp; } - public long getSunset() { - return sunset; + public Date getSunriseDate() { + return new Date(sunriseTimestamp * 1000); } - public void setSunset(long sunset) { - this.sunset = sunset; + public long getSunsetTimestamp() { + return sunsetTimestamp; + } + + public void setSunsetTimestamp(long sunsetTimestamp) { + this.sunsetTimestamp = sunsetTimestamp; + } + + public Date getSunsetDate() { + return new Date(sunsetTimestamp * 1000); } @Override @@ -487,14 +495,14 @@ public class Weather implements OpenWeatherResponse { stringBuilder.append(country); stringBuilder.append('\n'); } - if (sunrise > 0) { + if (sunriseTimestamp > 0) { stringBuilder.append("Sunrise: "); - stringBuilder.append(new Date(sunrise * 1000)); + stringBuilder.append(getSunriseDate()); stringBuilder.append('\n'); } - if (sunset > 0) { + if (sunsetTimestamp > 0) { stringBuilder.append("Sunset: "); - stringBuilder.append(new Date(sunset * 1000)); + stringBuilder.append(getSunsetDate()); } return stringBuilder.toString(); @@ -509,14 +517,14 @@ public class Weather implements OpenWeatherResponse { id == that.id && Double.compare(that.message, message) == 0 && Objects.equals(country, that.country) && - Objects.equals(sunrise, that.sunrise) && - Objects.equals(sunset, that.sunset); + Objects.equals(sunriseTimestamp, that.sunriseTimestamp) && + Objects.equals(sunsetTimestamp, that.sunsetTimestamp); } @Override public int hashCode() { - return Objects.hash(type, id, message, country, sunrise, sunset); + return Objects.hash(type, id, message, country, sunriseTimestamp, sunsetTimestamp); } } } diff --git a/src/main/java/by/prominence/openweathermap/api/utils/JsonUtils.java b/src/main/java/by/prominence/openweathermap/api/utils/JsonUtils.java index 70ecfdf..11958f0 100644 --- a/src/main/java/by/prominence/openweathermap/api/utils/JsonUtils.java +++ b/src/main/java/by/prominence/openweathermap/api/utils/JsonUtils.java @@ -29,7 +29,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -public class JsonUtils { +public final class JsonUtils { + + private JsonUtils() {} public static Object parseJson(InputStream inputStream, Class clazz) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); diff --git a/src/main/java/by/prominence/openweathermap/api/utils/RequestUtils.java b/src/main/java/by/prominence/openweathermap/api/utils/RequestUtils.java index 7da78ac..68725f1 100644 --- a/src/main/java/by/prominence/openweathermap/api/utils/RequestUtils.java +++ b/src/main/java/by/prominence/openweathermap/api/utils/RequestUtils.java @@ -30,7 +30,9 @@ import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; -public class RequestUtils { +public final class RequestUtils { + + private RequestUtils() {} public static InputStream executeGetRequest(URL requestUrl) throws InvalidAuthTokenException, DataNotFoundException { InputStream resultStream = null;