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