mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-10 11:56:44 +03:00
Improved 'toString' methods(also units were added). Global package renaming and small improvements.
This commit is contained in:
parent
175a092e83
commit
7274327149
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>openweather-api</groupId>
|
<groupId>openweather-api</groupId>
|
||||||
<artifactId>by.prominence.openweater.api</artifactId>
|
<artifactId>by.prominence.openweatermap.api</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api;
|
package by.prominence.openweathermap.api;
|
||||||
|
|
||||||
abstract class AuthenticationTokenBasedRequester {
|
abstract class AuthenticationTokenBasedRequester {
|
||||||
|
|
||||||
@ -20,12 +20,13 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api;
|
package by.prominence.openweathermap.api;
|
||||||
|
|
||||||
import by.prominence.openweather.api.constants.System;
|
import by.prominence.openweathermap.api.constants.System;
|
||||||
import by.prominence.openweather.api.exception.DataNotFoundException;
|
import by.prominence.openweathermap.api.constants.Unit;
|
||||||
import by.prominence.openweather.api.exception.InvalidAuthTokenException;
|
import by.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||||
import by.prominence.openweather.api.model.Coordinates;
|
import by.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||||
|
import by.prominence.openweathermap.api.model.Coordinates;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -34,7 +35,7 @@ import java.util.Map;
|
|||||||
abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
||||||
|
|
||||||
protected String language;
|
protected String language;
|
||||||
protected String unit;
|
protected String unitSystem = Unit.STANDARD_SYSTEM;
|
||||||
protected String accuracy;
|
protected String accuracy;
|
||||||
|
|
||||||
protected BasicRequester(String authToken) {
|
protected BasicRequester(String authToken) {
|
||||||
@ -76,9 +77,9 @@ abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
|||||||
urlBuilder.append(language);
|
urlBuilder.append(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit != null) {
|
if (!Unit.STANDARD_SYSTEM.equals(unitSystem)) {
|
||||||
urlBuilder.append("&units=");
|
urlBuilder.append("&units=");
|
||||||
urlBuilder.append(unit);
|
urlBuilder.append(unitSystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accuracy != null) {
|
if (accuracy != null) {
|
||||||
@ -20,13 +20,14 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api;
|
package by.prominence.openweathermap.api;
|
||||||
|
|
||||||
import by.prominence.openweather.api.exception.DataNotFoundException;
|
import by.prominence.openweathermap.api.constants.Unit;
|
||||||
import by.prominence.openweather.api.exception.InvalidAuthTokenException;
|
import by.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||||
import by.prominence.openweather.api.model.forecast.ForecastResponse;
|
import by.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||||
import by.prominence.openweather.api.utils.JsonUtils;
|
import by.prominence.openweathermap.api.model.forecast.ForecastResponse;
|
||||||
import by.prominence.openweather.api.utils.RequestUtils;
|
import by.prominence.openweathermap.api.utils.JsonUtils;
|
||||||
|
import by.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -51,8 +52,8 @@ public class ForecastRequester extends BasicRequester<ForecastResponse> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForecastRequester setUnit(String unit) {
|
public ForecastRequester setUnitSystem(String unitSystem) {
|
||||||
this.unit = unit;
|
this.unitSystem = unitSystem;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,14 +82,24 @@ public class ForecastRequester extends BasicRequester<ForecastResponse> {
|
|||||||
|
|
||||||
protected ForecastResponse executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
protected ForecastResponse executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
||||||
|
|
||||||
|
ForecastResponse forecastResponse = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
||||||
return (ForecastResponse)JsonUtils.parseJson(requestResult, ForecastResponse.class);
|
forecastResponse = (ForecastResponse)JsonUtils.parseJson(requestResult, ForecastResponse.class);
|
||||||
|
|
||||||
|
char temperatureUnit = Unit.getTemperatureUnit(unitSystem);
|
||||||
|
String windUnit = Unit.getWindUnit(unitSystem);
|
||||||
|
|
||||||
|
forecastResponse.getForecasts().forEach(forecastInfo -> {
|
||||||
|
forecastInfo.getWind().setUnit(windUnit);
|
||||||
|
forecastInfo.getMainInfo().setTemperatureUnit(temperatureUnit);
|
||||||
|
});
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return forecastResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api;
|
package by.prominence.openweathermap.api;
|
||||||
|
|
||||||
public class OpenWeatherMapManager {
|
public class OpenWeatherMapManager {
|
||||||
|
|
||||||
@ -20,13 +20,14 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api;
|
package by.prominence.openweathermap.api;
|
||||||
|
|
||||||
import by.prominence.openweather.api.exception.DataNotFoundException;
|
import by.prominence.openweathermap.api.constants.Unit;
|
||||||
import by.prominence.openweather.api.exception.InvalidAuthTokenException;
|
import by.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||||
import by.prominence.openweather.api.model.weather.WeatherResponse;
|
import by.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||||
import by.prominence.openweather.api.utils.JsonUtils;
|
import by.prominence.openweathermap.api.model.weather.WeatherResponse;
|
||||||
import by.prominence.openweather.api.utils.RequestUtils;
|
import by.prominence.openweathermap.api.utils.JsonUtils;
|
||||||
|
import by.prominence.openweathermap.api.utils.RequestUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -42,8 +43,8 @@ public class WeatherRequester extends BasicRequester<WeatherResponse> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WeatherRequester setUnit(String unit) {
|
public WeatherRequester setUnitSystem(String unitSystem) {
|
||||||
this.unit = unit;
|
this.unitSystem = unitSystem;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,14 +59,19 @@ public class WeatherRequester extends BasicRequester<WeatherResponse> {
|
|||||||
|
|
||||||
protected WeatherResponse executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
protected WeatherResponse executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
||||||
|
|
||||||
|
WeatherResponse weatherResponse = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
||||||
return (WeatherResponse)JsonUtils.parseJson(requestResult, WeatherResponse.class);
|
weatherResponse = (WeatherResponse)JsonUtils.parseJson(requestResult, WeatherResponse.class);
|
||||||
|
|
||||||
|
weatherResponse.getWind().setUnit(Unit.getWindUnit(unitSystem));
|
||||||
|
weatherResponse.getWeatherInfo().setTemperatureUnit(Unit.getTemperatureUnit(unitSystem));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return weatherResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.constants;
|
package by.prominence.openweathermap.api.constants;
|
||||||
|
|
||||||
public class Accuracy {
|
public class Accuracy {
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.constants;
|
package by.prominence.openweathermap.api.constants;
|
||||||
|
|
||||||
public class Language {
|
public class Language {
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.constants;
|
package by.prominence.openweathermap.api.constants;
|
||||||
|
|
||||||
public class System {
|
public class System {
|
||||||
|
|
||||||
@ -20,12 +20,35 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.constants;
|
package by.prominence.openweathermap.api.constants;
|
||||||
|
|
||||||
public class Unit {
|
public class Unit {
|
||||||
|
|
||||||
public static final String METRIC = "metric";
|
public static final String METRIC_SYSTEM = "metric";
|
||||||
public static final String IMPERIAL = "imperial";
|
public static final String IMPERIAL_SYSTEM = "imperial";
|
||||||
public static final String STANDARD = null;
|
public static final String STANDARD_SYSTEM = "standard";
|
||||||
|
|
||||||
|
public static String getWindUnit(String type) {
|
||||||
|
switch (type) {
|
||||||
|
case IMPERIAL_SYSTEM:
|
||||||
|
return "miles/hour";
|
||||||
|
case STANDARD_SYSTEM:
|
||||||
|
case METRIC_SYSTEM:
|
||||||
|
default:
|
||||||
|
return "meter/sec";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char getTemperatureUnit(String type) {
|
||||||
|
switch (type) {
|
||||||
|
case METRIC_SYSTEM:
|
||||||
|
return '℃';
|
||||||
|
case IMPERIAL_SYSTEM:
|
||||||
|
return '℉';
|
||||||
|
case STANDARD_SYSTEM:
|
||||||
|
default:
|
||||||
|
return 'K';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.exception;
|
package by.prominence.openweathermap.api.exception;
|
||||||
|
|
||||||
public class DataNotFoundException extends Exception {
|
public class DataNotFoundException extends Exception {
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.exception;
|
package by.prominence.openweathermap.api.exception;
|
||||||
|
|
||||||
public class InvalidAuthTokenException extends Exception {
|
public class InvalidAuthTokenException extends Exception {
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model;
|
package by.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -42,9 +42,7 @@ public class Clouds {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Clouds{" +
|
return "Cloudiness: " + cloudiness + "%";
|
||||||
"cloudiness=" + cloudiness + "%" +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model;
|
package by.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -58,10 +58,7 @@ public class Coordinates {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Coordinates{" +
|
return "latitude=" + latitude + ", longitude=" + longitude;
|
||||||
"latitude=" + latitude +
|
|
||||||
", longitude=" + longitude +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model;
|
package by.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
public interface OpenWeatherResponse {
|
public interface OpenWeatherResponse {
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model;
|
package by.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -40,11 +40,13 @@ public class Rain {
|
|||||||
this.rainVolumeLast3Hrs = rainVolumeLast3Hrs;
|
this.rainVolumeLast3Hrs = rainVolumeLast3Hrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUnit() {
|
||||||
|
return "mm";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Rain{" +
|
return "Rain(last 3 hrs): " + rainVolumeLast3Hrs + ' ' + getUnit();
|
||||||
"rainVolumeLast3Hrs=" + rainVolumeLast3Hrs +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model;
|
package by.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -40,11 +40,13 @@ public class Snow {
|
|||||||
this.snowVolumeLast3Hrs = snowVolumeLast3Hrs;
|
this.snowVolumeLast3Hrs = snowVolumeLast3Hrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUnit() {
|
||||||
|
return "mm";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Snow{" +
|
return "Snow(last 3 hrs): " + snowVolumeLast3Hrs + ' ' + getUnit();
|
||||||
"snowVolumeLast3Hrs=" + snowVolumeLast3Hrs +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model;
|
package by.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -90,12 +90,7 @@ public class Weather {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Weather{" +
|
return "Weather: " + description;
|
||||||
"conditionId=" + conditionId +
|
|
||||||
", weatherGroup='" + weatherGroup + '\'' +
|
|
||||||
", description='" + description + '\'' +
|
|
||||||
", iconId='" + iconId + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model;
|
package by.prominence.openweathermap.api.model;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -32,6 +32,8 @@ public class Wind {
|
|||||||
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||||
private float speed;
|
private float speed;
|
||||||
|
|
||||||
|
private String unit;
|
||||||
|
|
||||||
@JSONField(name = "deg")
|
@JSONField(name = "deg")
|
||||||
// Wind direction, degrees (meteorological)
|
// Wind direction, degrees (meteorological)
|
||||||
private short degrees;
|
private short degrees;
|
||||||
@ -44,6 +46,14 @@ public class Wind {
|
|||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUnit() {
|
||||||
|
return unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnit(String unit) {
|
||||||
|
this.unit = unit;
|
||||||
|
}
|
||||||
|
|
||||||
public short getDegrees() {
|
public short getDegrees() {
|
||||||
return degrees;
|
return degrees;
|
||||||
}
|
}
|
||||||
@ -54,10 +64,7 @@ public class Wind {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Wind{" +
|
return "Wind: " + speed + ' ' + unit + ", " + degrees + " degrees";
|
||||||
"speed=" + speed +
|
|
||||||
", degrees=" + degrees +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,9 +20,9 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.forecast;
|
package by.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
import by.prominence.openweather.api.model.Coordinates;
|
import by.prominence.openweathermap.api.model.Coordinates;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -75,12 +75,7 @@ public class City {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "City{" +
|
return "City: " + name + "(" + id + "). Coordinates: " + coordinates + '\n' + "Country: " + country;
|
||||||
"id=" + id +
|
|
||||||
", name='" + name + '\'' +
|
|
||||||
", coordinates=" + coordinates +
|
|
||||||
", country='" + country + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,9 +20,9 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.forecast;
|
package by.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
import by.prominence.openweather.api.model.*;
|
import by.prominence.openweathermap.api.model.*;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -129,17 +129,35 @@ public class ForecastInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "\nForecastInfo{" +
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
"dataCalculationTime=" + new Date(dataCalculationTime * 1000) +
|
stringBuilder.append("Time: ");
|
||||||
", mainInfo=" + mainInfo +
|
stringBuilder.append(new Date(dataCalculationTime * 1000));
|
||||||
", weathers=" + weathers +
|
stringBuilder.append(" — ");
|
||||||
", clouds=" + clouds +
|
if (weathers.size() == 1) {
|
||||||
", wind=" + wind +
|
stringBuilder.append(weathers.get(0));
|
||||||
", snow=" + snow +
|
} else {
|
||||||
", rain=" + rain +
|
stringBuilder.append(weathers);
|
||||||
", systemInfo=" + systemInfo +
|
}
|
||||||
", dt_text='" + dt_txt + '\'' +
|
stringBuilder.append(". ");
|
||||||
'}';
|
stringBuilder.append(mainInfo);
|
||||||
|
if (clouds != null) {
|
||||||
|
stringBuilder.append(". ");
|
||||||
|
stringBuilder.append(clouds);
|
||||||
|
}
|
||||||
|
if (wind != null) {
|
||||||
|
stringBuilder.append(". ");
|
||||||
|
stringBuilder.append(wind);
|
||||||
|
}
|
||||||
|
if (snow != null) {
|
||||||
|
stringBuilder.append(". ");
|
||||||
|
stringBuilder.append(snow);
|
||||||
|
}
|
||||||
|
if (rain != null) {
|
||||||
|
stringBuilder.append(". ");
|
||||||
|
stringBuilder.append(rain);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,9 +20,9 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.forecast;
|
package by.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
import by.prominence.openweather.api.model.OpenWeatherResponse;
|
import by.prominence.openweathermap.api.model.OpenWeatherResponse;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -85,13 +85,14 @@ public class ForecastResponse implements OpenWeatherResponse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ForecastResponse{" +
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
"responseCode=" + responseCode +
|
stringBuilder.append(city);
|
||||||
", message=" + message +
|
stringBuilder.append("\nForecasts: ");
|
||||||
", cnt=" + cnt +
|
forecasts.forEach(forecastInfo -> {
|
||||||
", forecasts=" + forecasts +
|
stringBuilder.append("\n\t");
|
||||||
", city=" + city +
|
stringBuilder.append(forecastInfo);
|
||||||
'}';
|
});
|
||||||
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.forecast;
|
package by.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.forecast;
|
package by.prominence.openweathermap.api.model.forecast;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -60,6 +60,8 @@ public class MainInfo {
|
|||||||
// Internal parameter
|
// Internal parameter
|
||||||
private float temperatureCoefficient;
|
private float temperatureCoefficient;
|
||||||
|
|
||||||
|
private char temperatureUnit;
|
||||||
|
|
||||||
public float getTemperature() {
|
public float getTemperature() {
|
||||||
return temperature;
|
return temperature;
|
||||||
}
|
}
|
||||||
@ -124,18 +126,54 @@ public class MainInfo {
|
|||||||
this.temperatureCoefficient = temperatureCoefficient;
|
this.temperatureCoefficient = temperatureCoefficient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public char getTemperatureUnit() {
|
||||||
|
return temperatureUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemperatureUnit(char temperatureUnit) {
|
||||||
|
this.temperatureUnit = temperatureUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPressureUnit() {
|
||||||
|
return "hPa";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MainInfo{" +
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
"temperature=" + temperature +
|
stringBuilder.append("Temperature: ");
|
||||||
", minimumTemperature=" + minimumTemperature +
|
stringBuilder.append(temperature);
|
||||||
", maximumTemperature=" + maximumTemperature +
|
stringBuilder.append(' ');
|
||||||
", pressure=" + pressure +
|
stringBuilder.append(temperatureUnit);
|
||||||
", seaLevelPressure=" + seaLevelPressure +
|
stringBuilder.append(". Minimum temperature: ");
|
||||||
", groundLevelPressure=" + groundLevelPressure +
|
stringBuilder.append(minimumTemperature);
|
||||||
", humidity=" + humidity + "%" +
|
stringBuilder.append(' ');
|
||||||
", temperatureCoefficient=" + temperatureCoefficient +
|
stringBuilder.append(temperatureUnit);
|
||||||
'}';
|
stringBuilder.append(". Maximum temperature: ");
|
||||||
|
stringBuilder.append(maximumTemperature);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(temperatureUnit);
|
||||||
|
stringBuilder.append(". Pressure: ");
|
||||||
|
stringBuilder.append(pressure);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(getPressureUnit());
|
||||||
|
if (seaLevelPressure > 0) {
|
||||||
|
stringBuilder.append(". Sea-level pressure: ");
|
||||||
|
stringBuilder.append(seaLevelPressure);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(getPressureUnit());
|
||||||
|
}
|
||||||
|
if (groundLevelPressure > 0) {
|
||||||
|
stringBuilder.append(". Ground-level pressure: ");
|
||||||
|
stringBuilder.append(groundLevelPressure);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(getPressureUnit());
|
||||||
|
}
|
||||||
|
stringBuilder.append(". Humidity: ");
|
||||||
|
stringBuilder.append(humidity);
|
||||||
|
stringBuilder.append('%');
|
||||||
|
|
||||||
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.weather;
|
package by.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -58,6 +58,8 @@ public class WeatherInfo {
|
|||||||
// Atmospheric pressure on the ground level, hPa
|
// Atmospheric pressure on the ground level, hPa
|
||||||
private short groundLevelPressure;
|
private short groundLevelPressure;
|
||||||
|
|
||||||
|
private char temperatureUnit;
|
||||||
|
|
||||||
public float getTemperature() {
|
public float getTemperature() {
|
||||||
return temperature;
|
return temperature;
|
||||||
}
|
}
|
||||||
@ -114,17 +116,56 @@ public class WeatherInfo {
|
|||||||
this.groundLevelPressure = groundLevelPressure;
|
this.groundLevelPressure = groundLevelPressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public char getTemperatureUnit() {
|
||||||
|
return temperatureUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemperatureUnit(char temperatureUnit) {
|
||||||
|
this.temperatureUnit = temperatureUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPressureUnit() {
|
||||||
|
return "hPa";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "WeatherInfo{" +
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
"temperature=" + temperature +
|
stringBuilder.append("Temperature: ");
|
||||||
", pressure=" + pressure +
|
stringBuilder.append(temperature);
|
||||||
", humidity=" + humidity + "%" +
|
stringBuilder.append(' ');
|
||||||
", minimumTemperature=" + minimumTemperature +
|
stringBuilder.append(temperatureUnit);
|
||||||
", maximumTemperature=" + maximumTemperature +
|
stringBuilder.append(". Minimum temparature: ");
|
||||||
", seaLevelPressure=" + seaLevelPressure +
|
stringBuilder.append(minimumTemperature);
|
||||||
", groundLevelPressure=" + groundLevelPressure +
|
stringBuilder.append(' ');
|
||||||
'}';
|
stringBuilder.append(temperatureUnit);
|
||||||
|
stringBuilder.append(". Maximum temperature: ");
|
||||||
|
stringBuilder.append(maximumTemperature);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(temperatureUnit);
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
stringBuilder.append("Humidity: ");
|
||||||
|
stringBuilder.append(humidity);
|
||||||
|
stringBuilder.append("%");
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
stringBuilder.append("Pressure: ");
|
||||||
|
stringBuilder.append(pressure);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(getPressureUnit());
|
||||||
|
if (seaLevelPressure > 0) {
|
||||||
|
stringBuilder.append(". Sea-level pressure: ");
|
||||||
|
stringBuilder.append(seaLevelPressure);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(getPressureUnit());
|
||||||
|
}
|
||||||
|
if (groundLevelPressure > 0) {
|
||||||
|
stringBuilder.append(". Ground-level pressure: ");
|
||||||
|
stringBuilder.append(groundLevelPressure);
|
||||||
|
stringBuilder.append(' ');
|
||||||
|
stringBuilder.append(getPressureUnit());
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,9 +20,9 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.weather;
|
package by.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
import by.prominence.openweather.api.model.*;
|
import by.prominence.openweathermap.api.model.*;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -175,20 +175,40 @@ public class WeatherResponse implements OpenWeatherResponse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "WeatherResponse{" +
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
"cityId=" + cityId +
|
stringBuilder.append("City: ");
|
||||||
",\n cityName='" + cityName + '\'' +
|
stringBuilder.append(cityName);
|
||||||
",\n coordinates=" + coordinates +
|
stringBuilder.append('(');
|
||||||
",\n weather=" + weather +
|
stringBuilder.append(cityId);
|
||||||
",\n base='" + base + '\'' +
|
stringBuilder.append("). ");
|
||||||
",\n weatherInfo=" + weatherInfo +
|
stringBuilder.append("Coordinates: ");
|
||||||
",\n wind=" + wind +
|
stringBuilder.append(coordinates);
|
||||||
",\n clouds=" + clouds +
|
stringBuilder.append('\n');
|
||||||
",\n rain=" + rain +
|
stringBuilder.append(weatherSystemInfo);
|
||||||
",\n snow=" + snow +
|
stringBuilder.append('\n');
|
||||||
",\n dataCalculationTime=" + new Date(dataCalculationTime * 1000) +
|
if (weather.size() == 1) {
|
||||||
",\n weatherSystemInfo=" + weatherSystemInfo +
|
stringBuilder.append(weather.get(0));
|
||||||
",\n responseCode=" + responseCode +
|
} else {
|
||||||
'}';
|
stringBuilder.append(weather);
|
||||||
|
}
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
stringBuilder.append(weatherInfo);
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
stringBuilder.append(wind);
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
stringBuilder.append(clouds);
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
if (rain != null) {
|
||||||
|
stringBuilder.append(rain);
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
}
|
||||||
|
if (snow != null) {
|
||||||
|
stringBuilder.append(snow);
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
}
|
||||||
|
stringBuilder.append("Data calculation time: ");
|
||||||
|
stringBuilder.append(new Date(dataCalculationTime * 1000));
|
||||||
|
|
||||||
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.model.weather;
|
package by.prominence.openweathermap.api.model.weather;
|
||||||
|
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
|
||||||
@ -103,14 +103,24 @@ public class WeatherSystemInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "WeatherSystemInfo{" +
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
"type=" + type +
|
|
||||||
", id=" + id +
|
if (country != null) {
|
||||||
", message=" + message +
|
stringBuilder.append("Country: ");
|
||||||
", country='" + country + '\'' +
|
stringBuilder.append(country);
|
||||||
", sunrise=" + new Date(sunrise * 1000) +
|
stringBuilder.append('\n');
|
||||||
", sunset=" + new Date(sunset * 1000) +
|
}
|
||||||
'}';
|
if (sunrise > 0) {
|
||||||
|
stringBuilder.append("Sunrise: ");
|
||||||
|
stringBuilder.append(new Date(sunrise * 1000));
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
}
|
||||||
|
if (sunset > 0) {
|
||||||
|
stringBuilder.append("Sunset: ");
|
||||||
|
stringBuilder.append(new Date(sunset * 1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -20,7 +20,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.utils;
|
package by.prominence.openweathermap.api.utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class 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));
|
||||||
|
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuilder result = new StringBuilder();
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
result.append(line);
|
result.append(line);
|
||||||
@ -20,10 +20,10 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package by.prominence.openweather.api.utils;
|
package by.prominence.openweathermap.api.utils;
|
||||||
|
|
||||||
import by.prominence.openweather.api.exception.DataNotFoundException;
|
import by.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||||
import by.prominence.openweather.api.exception.InvalidAuthTokenException;
|
import by.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
Loading…
x
Reference in New Issue
Block a user