Checked visibility. Removed unused exceptions' constructors. Renamed sunruse/sunset methods and variables. Updated documentation.

This commit is contained in:
Prominence 2018-07-17 23:45:57 +03:00
parent c5cbf79efb
commit b0cbf1135d
12 changed files with 60 additions and 46 deletions

View File

@ -56,18 +56,18 @@ Available requests:
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. | | `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. | | `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. | | `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. | | `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. | | `getWind()` | Returns `Wind` instance that contains information about speed and degree. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. | | `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getRain()` | Returns `Rain` instance that contains information about rain volume for the last 3 hours. | | `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. | | `getSnow()` | Returns `Snow` instance that contains information about snow volume for the last 3 hours. |
| `getDataCalculationTime()`| Returns `long` value that represents data calculation timestamp. | | `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. | | `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getWeatherSystemInfo().getCountry()`. | | `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. | | `getDataCalculationDate()`| Returns data calculation time in `Date` representation. |
| `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. | | `getTemperature()` | An alias for `getWeatherInfo().getTemperature()`. |
| `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. | | `getTemperatureUnit()` | An alias for `getWeatherInfo().getTemperatureUnit()`. |
@ -121,20 +121,20 @@ Available requests:
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. | | `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. | | `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. | | `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. | | `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. | | `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.ForecastInfo>` collection with all forecast information. | | `getForecasts()` | Returns `List<HourlyForecast.ForecastInfo>` collection with all forecast information. |
| `getAverageTemperature()` | Returns average temperature from forecasts. | | `getAverageTemperature()` | Returns average temperature from forecasts. |
| `getMinimumTemperature()` | Returns minimum temperature from forecasts. | | `getMinimumTemperature()` | Returns minimum temperature from forecasts. |
| `getMaximumTemperature()` | Returns maximum temperature from forecasts. | | `getMaximumTemperature()` | Returns maximum temperature from forecasts. |
| `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. | | `getByMinimumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is minimal. |
| `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. | | `getByMaximumTemperature()` | Returns `HourlyForecast.ForecastInfo` for the time where temperature is maximal. |
| `getAveragePressure()` | Returns average pressure from forecasts. | | `getAveragePressure()` | Returns average pressure from forecasts. |
| `getMinimumPressure()` | Returns minimum pressure from forecasts. | | `getMinimumPressure()` | Returns minimum pressure from forecasts. |
| `getMaximumPressure()` | Returns maximum pressure from forecasts. | | `getMaximumPressure()` | Returns maximum pressure from forecasts. |
| `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. | | `getByMinimumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is minimal. |
| `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. | | `getByMaximumPressure()` | Returns `HourlyForecast.ForecastInfo` for the time where pressure is maximal. |
| `toString()` | Returns pretty string for the whole available forecast information. | | `toString()` | Returns pretty string for the whole available forecast information. |
`toString()` output example: `toString()` output example:
@ -190,13 +190,13 @@ Forecasts:
|-----------------------------|------------------------------------------------------------------------------------------------------------------| |-----------------------------|------------------------------------------------------------------------------------------------------------------|
| `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. | | `getDataCalculationTime()` | Returns `long` value that represents data calculation timestamp. |
| `getDataCalculationDate()` | Returns data calculation time in `Date` representation. | | `getDataCalculationDate()` | Returns data calculation time in `Date` representation. |
| `getMainInfo()` | Returns `HourlyForecast.MainInfo` instance that contains information about temperature, pressure and humidity. | | `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. | | `getWeatherStates()` | Returns list of `WeatherState` instances with the only `getDescription` useful method. |
| `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. | | `getClouds()` | Returns `Clouds` instance that contains *cloudiness* percentage information. |
| `getWind()` | Returns `Wind` instance that contains information about speed and degree. | | `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. | | `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. | | `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. | | `getDt_txt()` | Returns `String` value that represents data calculation time. |
| `toString()` | Returns pretty string for the whole available weather information. | | `toString()` | Returns pretty string for the whole available weather information. |

View File

@ -22,7 +22,9 @@
package by.prominence.openweathermap.api.constants; 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 LIKE = "like";
public static final String ACCURATE = "accurate"; public static final String ACCURATE = "accurate";

View File

@ -22,7 +22,9 @@
package by.prominence.openweathermap.api.constants; 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 ARABIC = "ar";
public static final String BULGARIAN = "bg"; public static final String BULGARIAN = "bg";

View File

@ -22,7 +22,9 @@
package by.prominence.openweathermap.api.constants; 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_VERSION = "2.5";
public static final String OPEN_WEATHER_API_URL = "http://api.openweathermap.org/data/" + OPEN_WEATHER_API_VERSION + "/"; public static final String OPEN_WEATHER_API_URL = "http://api.openweathermap.org/data/" + OPEN_WEATHER_API_VERSION + "/";

View File

@ -22,7 +22,9 @@
package by.prominence.openweathermap.api.constants; 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 METRIC_SYSTEM = "metric";
public static final String IMPERIAL_SYSTEM = "imperial"; public static final String IMPERIAL_SYSTEM = "imperial";

View File

@ -28,7 +28,4 @@ public class DataNotFoundException extends Exception {
super("Data for provided parameters wasn't found. Please, check your request."); super("Data for provided parameters wasn't found. Please, check your request.");
} }
public DataNotFoundException(String message) {
super(message);
}
} }

View File

@ -25,10 +25,7 @@ package by.prominence.openweathermap.api.exception;
public class InvalidAuthTokenException extends Exception { public class InvalidAuthTokenException extends Exception {
public InvalidAuthTokenException() { 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);
}
} }

View File

@ -30,7 +30,7 @@ public class Rain {
@JSONField(name = "3h") @JSONField(name = "3h")
// Rain volume for the last 3 hours // Rain volume for the last 3 hours
byte rainVolumeLast3Hrs; private byte rainVolumeLast3Hrs;
public byte getRainVolumeLast3Hrs() { public byte getRainVolumeLast3Hrs() {
return rainVolumeLast3Hrs; return rainVolumeLast3Hrs;

View File

@ -174,10 +174,10 @@ public class HourlyForecast implements OpenWeatherResponse {
public static class CityInfo { public static class CityInfo {
// CityInfo ID // City ID
private long id; private long id;
// CityInfo name // City name
private String name; private String name;
@JSONField(name = "coord") @JSONField(name = "coord")

View File

@ -424,11 +424,11 @@ public class Weather implements OpenWeatherResponse {
@JSONField(name = "sunrise") @JSONField(name = "sunrise")
// Sunrise time, unix, UTC // Sunrise time, unix, UTC
private long sunrise; private long sunriseTimestamp;
@JSONField(name = "sunset") @JSONField(name = "sunset")
// Sunset time, unix, UTC // Sunset time, unix, UTC
private long sunset; private long sunsetTimestamp;
public short getType() { public short getType() {
return type; return type;
@ -462,20 +462,28 @@ public class Weather implements OpenWeatherResponse {
this.country = country; this.country = country;
} }
public long getSunrise() { public long getSunriseTimestamp() {
return sunrise; return sunriseTimestamp;
} }
public void setSunrise(long sunrise) { public void setSunriseTimestamp(long sunriseTimestamp) {
this.sunrise = sunrise; this.sunriseTimestamp = sunriseTimestamp;
} }
public long getSunset() { public Date getSunriseDate() {
return sunset; return new Date(sunriseTimestamp * 1000);
} }
public void setSunset(long sunset) { public long getSunsetTimestamp() {
this.sunset = sunset; return sunsetTimestamp;
}
public void setSunsetTimestamp(long sunsetTimestamp) {
this.sunsetTimestamp = sunsetTimestamp;
}
public Date getSunsetDate() {
return new Date(sunsetTimestamp * 1000);
} }
@Override @Override
@ -487,14 +495,14 @@ public class Weather implements OpenWeatherResponse {
stringBuilder.append(country); stringBuilder.append(country);
stringBuilder.append('\n'); stringBuilder.append('\n');
} }
if (sunrise > 0) { if (sunriseTimestamp > 0) {
stringBuilder.append("Sunrise: "); stringBuilder.append("Sunrise: ");
stringBuilder.append(new Date(sunrise * 1000)); stringBuilder.append(getSunriseDate());
stringBuilder.append('\n'); stringBuilder.append('\n');
} }
if (sunset > 0) { if (sunsetTimestamp > 0) {
stringBuilder.append("Sunset: "); stringBuilder.append("Sunset: ");
stringBuilder.append(new Date(sunset * 1000)); stringBuilder.append(getSunsetDate());
} }
return stringBuilder.toString(); return stringBuilder.toString();
@ -509,14 +517,14 @@ public class Weather implements OpenWeatherResponse {
id == that.id && id == that.id &&
Double.compare(that.message, message) == 0 && Double.compare(that.message, message) == 0 &&
Objects.equals(country, that.country) && Objects.equals(country, that.country) &&
Objects.equals(sunrise, that.sunrise) && Objects.equals(sunriseTimestamp, that.sunriseTimestamp) &&
Objects.equals(sunset, that.sunset); Objects.equals(sunsetTimestamp, that.sunsetTimestamp);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(type, id, message, country, sunrise, sunset); return Objects.hash(type, id, message, country, sunriseTimestamp, sunsetTimestamp);
} }
} }
} }

View File

@ -29,7 +29,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
public class JsonUtils { public final class JsonUtils {
private JsonUtils() {}
public static Object parseJson(InputStream inputStream, Class clazz) throws IOException { public static Object parseJson(InputStream inputStream, Class clazz) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

View File

@ -30,7 +30,9 @@ import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
public class RequestUtils { public final class RequestUtils {
private RequestUtils() {}
public static InputStream executeGetRequest(URL requestUrl) throws InvalidAuthTokenException, DataNotFoundException { public static InputStream executeGetRequest(URL requestUrl) throws InvalidAuthTokenException, DataNotFoundException {
InputStream resultStream = null; InputStream resultStream = null;