mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-09 19:46:41 +03:00
Implemented DailyForecast requesting. Added 'lombok' dependency. Some refactoring...
This commit is contained in:
parent
61eea0b8f6
commit
d86b228c6e
@ -127,7 +127,7 @@ 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 `CityInfo` instance that contains information about city. |
|
||||
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
|
||||
| `getCountry()` | An alias for `getCityInfo().getCountry()`. |
|
||||
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |
|
||||
|
||||
7
pom.xml
7
pom.xml
@ -136,6 +136,13 @@
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.44</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -30,6 +30,7 @@ import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
||||
|
||||
@ -86,10 +87,24 @@ abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
|
||||
urlBuilder.append(accuracy);
|
||||
}
|
||||
|
||||
Map<String, String> additionalParameters = getAdditionalParameters();
|
||||
if (additionalParameters != null) {
|
||||
additionalParameters.forEach((key, value) -> {
|
||||
urlBuilder.append("&");
|
||||
urlBuilder.append(key);
|
||||
urlBuilder.append("=");
|
||||
urlBuilder.append(value);
|
||||
});
|
||||
}
|
||||
|
||||
return new URL(urlBuilder.toString());
|
||||
}
|
||||
|
||||
protected Map<String, String> getAdditionalParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract String getRequestType();
|
||||
protected abstract T executeRequest(String requestSpecificParamsString) throws InvalidAuthTokenException, DataNotFoundException;
|
||||
protected abstract T executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api;
|
||||
|
||||
import com.github.prominence.openweathermap.api.constants.Unit;
|
||||
import com.github.prominence.openweathermap.api.exception.DataNotFoundException;
|
||||
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
|
||||
import com.github.prominence.openweathermap.api.model.response.DailyForecast;
|
||||
import com.github.prominence.openweathermap.api.utils.JsonUtils;
|
||||
import com.github.prominence.openweathermap.api.utils.RequestUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DailyForecastRequester extends BasicRequester<DailyForecast> {
|
||||
|
||||
int amountOfDays = -1;
|
||||
|
||||
protected DailyForecastRequester(String authToken) {
|
||||
super(authToken);
|
||||
}
|
||||
|
||||
public DailyForecastRequester setAmountOfDays(int amountOfDays) {
|
||||
this.amountOfDays = amountOfDays;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRequestType() {
|
||||
return "forecast/daily";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getAdditionalParameters() {
|
||||
Map<String, String> additionalParameters = null;
|
||||
if (amountOfDays != -1) {
|
||||
additionalParameters = new HashMap<>();
|
||||
additionalParameters.put("cnt", String.valueOf(amountOfDays));
|
||||
}
|
||||
|
||||
return additionalParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DailyForecast executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException {
|
||||
DailyForecast forecastResponse = null;
|
||||
|
||||
try {
|
||||
InputStream requestResult = RequestUtils.executeGetRequest(buildURL(requestSpecificParameters));
|
||||
forecastResponse = (DailyForecast)JsonUtils.parseJson(requestResult, DailyForecast.class);
|
||||
|
||||
char temperatureUnit = Unit.getTemperatureUnit(unitSystem);
|
||||
String windUnit = Unit.getWindUnit(unitSystem);
|
||||
|
||||
forecastResponse.getForecasts().forEach(forecastInfo -> {
|
||||
forecastInfo.setWindUnit(windUnit);
|
||||
forecastInfo.getTemperature().setTemperatureUnit(temperatureUnit);
|
||||
});
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return forecastResponse;
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,11 @@ public class OpenWeatherMapManager {
|
||||
return new WeatherRequester(authToken);
|
||||
}
|
||||
|
||||
public HourlyForecastRequester getForecastRequester() {
|
||||
public HourlyForecastRequester getHourlyForecastRequester() {
|
||||
return new HourlyForecastRequester(authToken);
|
||||
}
|
||||
|
||||
public DailyForecastRequester getDailyForecastRequester() {
|
||||
return new DailyForecastRequester(authToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ package com.github.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/.");
|
||||
super("Check your authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class CityInfo {
|
||||
|
||||
// City ID
|
||||
@Getter
|
||||
@Setter
|
||||
private long id;
|
||||
|
||||
// City name
|
||||
@Getter
|
||||
@Setter
|
||||
private String name;
|
||||
|
||||
@JSONField(name = "coord")
|
||||
@Getter
|
||||
@Setter
|
||||
private Coordinates coordinates;
|
||||
|
||||
// Country code (GB, JP etc.)
|
||||
@Getter
|
||||
@Setter
|
||||
private String country;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "City: " + name + "(" + id + "). Coordinates: " + coordinates + '\n' + "Country: " + country;
|
||||
}
|
||||
|
||||
}
|
||||
@ -23,39 +23,21 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class Clouds {
|
||||
|
||||
@JSONField(name = "all")
|
||||
// Cloudiness, %
|
||||
@Getter
|
||||
@Setter
|
||||
private byte cloudiness;
|
||||
|
||||
public byte getCloudiness() {
|
||||
return cloudiness;
|
||||
}
|
||||
|
||||
public void setCloudiness(byte cloudiness) {
|
||||
this.cloudiness = cloudiness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cloudiness: " + cloudiness + "%";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Clouds clouds = (Clouds) o;
|
||||
return cloudiness == clouds.cloudiness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(cloudiness);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,55 +23,29 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public class Coordinates {
|
||||
|
||||
@JSONField(name = "lat")
|
||||
// City geo location, latitude
|
||||
@Getter
|
||||
@Setter
|
||||
private float latitude;
|
||||
|
||||
@JSONField(name = "lon")
|
||||
// City geo location, longitude
|
||||
@Getter
|
||||
@Setter
|
||||
private float longitude;
|
||||
|
||||
public Coordinates(float latitude, float longitude) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public float getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(float latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public float getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(float longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "latitude=" + latitude + ", longitude=" + longitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Coordinates that = (Coordinates) o;
|
||||
return Double.compare(that.latitude, latitude) == 0 &&
|
||||
Double.compare(that.longitude, longitude) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(latitude, longitude);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,23 +23,19 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class Rain {
|
||||
|
||||
@JSONField(name = "3h")
|
||||
// Rain volume for the last 3 hours
|
||||
@Getter
|
||||
@Setter
|
||||
private byte rainVolumeLast3Hrs;
|
||||
|
||||
public byte getRainVolumeLast3Hrs() {
|
||||
return rainVolumeLast3Hrs;
|
||||
}
|
||||
|
||||
public void setRainVolumeLast3Hrs(byte rainVolumeLast3Hrs) {
|
||||
this.rainVolumeLast3Hrs = rainVolumeLast3Hrs;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return "mm";
|
||||
}
|
||||
@ -48,18 +44,4 @@ public class Rain {
|
||||
public String toString() {
|
||||
return "Rain(last 3 hrs): " + rainVolumeLast3Hrs + ' ' + getUnit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Rain rain = (Rain) o;
|
||||
return rainVolumeLast3Hrs == rain.rainVolumeLast3Hrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(rainVolumeLast3Hrs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,23 +23,19 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class Snow {
|
||||
|
||||
@JSONField(name = "all")
|
||||
// Snow volume for the last 3 hours
|
||||
@Getter
|
||||
@Setter
|
||||
private byte snowVolumeLast3Hrs;
|
||||
|
||||
public byte getSnowVolumeLast3Hrs() {
|
||||
return snowVolumeLast3Hrs;
|
||||
}
|
||||
|
||||
public void setSnowVolumeLast3Hrs(byte snowVolumeLast3Hrs) {
|
||||
this.snowVolumeLast3Hrs = snowVolumeLast3Hrs;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return "mm";
|
||||
}
|
||||
@ -48,18 +44,4 @@ public class Snow {
|
||||
public String toString() {
|
||||
return "Snow(last 3 hrs): " + snowVolumeLast3Hrs + ' ' + getUnit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Snow snow = (Snow) o;
|
||||
return snowVolumeLast3Hrs == snow.snowVolumeLast3Hrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(snowVolumeLast3Hrs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,61 +23,40 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class WeatherState {
|
||||
|
||||
@JSONField(name = "id")
|
||||
// Weather condition id
|
||||
@Getter
|
||||
@Setter
|
||||
long conditionId;
|
||||
|
||||
@JSONField(name = "main")
|
||||
// Group of weather parameters (Rain, Snow, Extreme etc.)
|
||||
@Getter
|
||||
@Setter
|
||||
String weatherGroup;
|
||||
|
||||
@JSONField(name = "description")
|
||||
// Weather condition within the group
|
||||
@Getter
|
||||
@Setter
|
||||
String description;
|
||||
|
||||
@JSONField(name = "icon")
|
||||
// Weather icon id
|
||||
@Getter
|
||||
@Setter
|
||||
String iconId;
|
||||
|
||||
public long getConditionId() {
|
||||
return conditionId;
|
||||
}
|
||||
|
||||
public void setConditionId(long conditionId) {
|
||||
this.conditionId = conditionId;
|
||||
}
|
||||
|
||||
public String getWeatherGroup() {
|
||||
return weatherGroup;
|
||||
}
|
||||
|
||||
public void setWeatherGroup(String weatherGroup) {
|
||||
this.weatherGroup = weatherGroup;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public void setIconId(String iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
public URL getWeatherIconUrl() {
|
||||
URL iconUrl = null;
|
||||
try {
|
||||
@ -92,21 +71,4 @@ public class WeatherState {
|
||||
public String toString() {
|
||||
return "Weather: " + description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WeatherState weatherState = (WeatherState) o;
|
||||
return conditionId == weatherState.conditionId &&
|
||||
Objects.equals(weatherGroup, weatherState.weatherGroup) &&
|
||||
Objects.equals(description, weatherState.description) &&
|
||||
Objects.equals(iconId, weatherState.iconId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(conditionId, weatherGroup, description, iconId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,62 +23,31 @@
|
||||
package com.github.prominence.openweathermap.api.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class Wind {
|
||||
|
||||
@JSONField(name = "speed")
|
||||
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
|
||||
@Getter
|
||||
@Setter
|
||||
private float speed;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String unit;
|
||||
|
||||
@JSONField(name = "deg")
|
||||
// Wind direction, degrees (meteorological)
|
||||
@Getter
|
||||
@Setter
|
||||
private short degrees;
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public short getDegrees() {
|
||||
return degrees;
|
||||
}
|
||||
|
||||
public void setDegrees(short degrees) {
|
||||
this.degrees = degrees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wind: " + speed + ' ' + unit + ", " + degrees + " degrees";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Wind wind = (Wind) o;
|
||||
return Float.compare(wind.speed, speed) == 0 &&
|
||||
degrees == wind.degrees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(speed, degrees);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Alexey Zinchenko
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.prominence.openweathermap.api.model.response;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.github.prominence.openweathermap.api.model.CityInfo;
|
||||
import com.github.prominence.openweathermap.api.model.Coordinates;
|
||||
import com.github.prominence.openweathermap.api.model.OpenWeatherResponse;
|
||||
import com.github.prominence.openweathermap.api.model.WeatherState;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class DailyForecast implements OpenWeatherResponse {
|
||||
|
||||
@JSONField(name = "city")
|
||||
@Getter
|
||||
@Setter
|
||||
private CityInfo cityInfo;
|
||||
|
||||
// Internal parameter
|
||||
@Getter
|
||||
@Setter
|
||||
private String cod;
|
||||
|
||||
// Internal parameter
|
||||
@Getter
|
||||
@Setter
|
||||
private double message;
|
||||
|
||||
// Number of lines returned by this API call
|
||||
@Getter
|
||||
@Setter
|
||||
private byte cnt;
|
||||
|
||||
@JSONField(name = "list")
|
||||
@Getter
|
||||
@Setter
|
||||
private List<Forecast> forecasts;
|
||||
|
||||
public String getCityName() {
|
||||
return cityInfo.getName();
|
||||
}
|
||||
|
||||
public long getCityId() {
|
||||
return cityInfo.getId();
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return cityInfo.getCountry();
|
||||
}
|
||||
|
||||
public Coordinates getCoordinates() {
|
||||
return cityInfo.getCoordinates();
|
||||
}
|
||||
|
||||
public short getResponseCode() {
|
||||
return Short.parseShort(cod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(cityInfo);
|
||||
builder.append("\nForecasts: ");
|
||||
forecasts.forEach(forecast -> {
|
||||
builder.append("\n\t");
|
||||
builder.append(forecast);
|
||||
});
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
public static class Forecast {
|
||||
|
||||
@JSONField(name = "dt")
|
||||
// Time of data calculation, unix, UTC
|
||||
@Getter
|
||||
@Setter
|
||||
private long dataCalculationTime;
|
||||
|
||||
@JSONField(name = "temp")
|
||||
@Getter
|
||||
@Setter
|
||||
private Temperature temperature;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private float pressure;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private byte humidity;
|
||||
|
||||
@JSONField(name = "weather")
|
||||
@Getter
|
||||
@Setter
|
||||
private List<WeatherState> weatherStates;
|
||||
|
||||
@JSONField(name = "speed")
|
||||
@Getter
|
||||
@Setter
|
||||
private float windSpeed;
|
||||
|
||||
@JSONField(name = "deg")
|
||||
// Wind direction, degrees (meteorological)
|
||||
@Getter
|
||||
@Setter
|
||||
private short windDegrees;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String windUnit;
|
||||
|
||||
@JSONField(name = "clouds")
|
||||
@Getter
|
||||
@Setter
|
||||
private byte cloudiness;
|
||||
|
||||
public String getPressureUnit() {
|
||||
return "hPa";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(temperature);
|
||||
builder.append(", Pressure: ");
|
||||
builder.append(pressure);
|
||||
builder.append(' ');
|
||||
builder.append(getPressureUnit());
|
||||
builder.append("; Humidity: ");
|
||||
builder.append(humidity);
|
||||
builder.append("%; Weather: ");
|
||||
if (weatherStates.size() == 1) {
|
||||
builder.append(weatherStates.get(0));
|
||||
} else {
|
||||
builder.append(weatherStates);
|
||||
}
|
||||
builder.append("; Wind: ");
|
||||
builder.append(windSpeed);
|
||||
builder.append(' ');
|
||||
builder.append(windUnit);
|
||||
builder.append(", ");
|
||||
builder.append(windDegrees);
|
||||
builder.append(" degrees; Cloudiness: ");
|
||||
builder.append(cloudiness);
|
||||
builder.append('%');
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
public static class Temperature {
|
||||
|
||||
@JSONField(name = "day")
|
||||
@Getter
|
||||
@Setter
|
||||
private float dayTemperature;
|
||||
|
||||
@JSONField(name = "min")
|
||||
@Getter
|
||||
@Setter
|
||||
private float minTemperature;
|
||||
|
||||
@JSONField(name = "max")
|
||||
@Getter
|
||||
@Setter
|
||||
private float maxTemperature;
|
||||
|
||||
@JSONField(name = "night")
|
||||
@Getter
|
||||
@Setter
|
||||
private float nightTemperature;
|
||||
|
||||
@JSONField(name = "eve")
|
||||
@Getter
|
||||
@Setter
|
||||
private float eveningTemperature;
|
||||
|
||||
@JSONField(name = "morn")
|
||||
@Getter
|
||||
@Setter
|
||||
private float morningTemperature;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private char temperatureUnit;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("Temperature: [");
|
||||
builder.append("Day temperature: ");
|
||||
builder.append(dayTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(getTemperatureUnit());
|
||||
builder.append("; Night temperature: ");
|
||||
builder.append(nightTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(getTemperatureUnit());
|
||||
builder.append("; Morning temperature: ");
|
||||
builder.append(morningTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(getTemperatureUnit());
|
||||
builder.append("; Evening temperature: ");
|
||||
builder.append(eveningTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(getTemperatureUnit());
|
||||
builder.append("; Minimum temperature: ");
|
||||
builder.append(minTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(getTemperatureUnit());
|
||||
builder.append("; Maximum temperature: ");
|
||||
builder.append(maxTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(getTemperatureUnit());
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,82 +24,56 @@ package com.github.prominence.openweathermap.api.model.response;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.github.prominence.openweathermap.api.model.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class HourlyForecast implements OpenWeatherResponse {
|
||||
|
||||
@JSONField(name = "cod")
|
||||
@Getter
|
||||
@Setter
|
||||
private short responseCode;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double message;
|
||||
|
||||
// Number of lines returned by this API call
|
||||
@Getter
|
||||
@Setter
|
||||
private short cnt;
|
||||
|
||||
@JSONField(name = "list")
|
||||
@Getter
|
||||
@Setter
|
||||
private List<Forecast> forecasts;
|
||||
|
||||
@JSONField(name = "city")
|
||||
@Getter
|
||||
@Setter
|
||||
private CityInfo cityInfo;
|
||||
|
||||
public short getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public void setResponseCode(short responseCode) {
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public double getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(double message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public short getCnt() {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
public void setCnt(short cnt) {
|
||||
this.cnt = cnt;
|
||||
}
|
||||
|
||||
public List<Forecast> getForecasts() {
|
||||
return forecasts;
|
||||
}
|
||||
|
||||
public void setForecasts(List<Forecast> forecasts) {
|
||||
this.forecasts = forecasts;
|
||||
}
|
||||
|
||||
public CityInfo getCityInfo() {
|
||||
return cityInfo;
|
||||
}
|
||||
|
||||
public void setCityInfo(CityInfo cityInfo) {
|
||||
this.cityInfo = cityInfo;
|
||||
}
|
||||
|
||||
public String getCityName() {
|
||||
return cityInfo.name;
|
||||
return cityInfo.getName();
|
||||
}
|
||||
|
||||
public long getCityId() {
|
||||
return cityInfo.id;
|
||||
return cityInfo.getId();
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return cityInfo.country;
|
||||
return cityInfo.getCountry();
|
||||
}
|
||||
|
||||
public Coordinates getCoordinates() {
|
||||
return cityInfo.coordinates;
|
||||
return cityInfo.getCoordinates();
|
||||
}
|
||||
|
||||
public float getAverageTemperature() {
|
||||
@ -144,464 +118,199 @@ public class HourlyForecast implements OpenWeatherResponse {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(cityInfo);
|
||||
stringBuilder.append("\nForecasts: ");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(cityInfo);
|
||||
builder.append("\nForecasts: ");
|
||||
forecasts.forEach(forecast -> {
|
||||
stringBuilder.append("\n\t");
|
||||
stringBuilder.append(forecast);
|
||||
builder.append("\n\t");
|
||||
builder.append(forecast);
|
||||
});
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
HourlyForecast that = (HourlyForecast) o;
|
||||
return responseCode == that.responseCode &&
|
||||
Double.compare(that.message, message) == 0 &&
|
||||
cnt == that.cnt &&
|
||||
Objects.equals(forecasts, that.forecasts) &&
|
||||
Objects.equals(cityInfo, that.cityInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(responseCode, message, cnt, forecasts, cityInfo);
|
||||
}
|
||||
|
||||
public static class CityInfo {
|
||||
|
||||
// City ID
|
||||
private long id;
|
||||
|
||||
// City name
|
||||
private String name;
|
||||
|
||||
@JSONField(name = "coord")
|
||||
private Coordinates coordinates;
|
||||
|
||||
// Country code (GB, JP etc.)
|
||||
private String country;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "City: " + name + "(" + id + "). Coordinates: " + coordinates + '\n' + "Country: " + country;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CityInfo cityInfo = (CityInfo) o;
|
||||
return id == cityInfo.id &&
|
||||
Objects.equals(name, cityInfo.name) &&
|
||||
Objects.equals(coordinates, cityInfo.coordinates) &&
|
||||
Objects.equals(country, cityInfo.country);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(id, name, coordinates, country);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
public static class Forecast {
|
||||
|
||||
@JSONField(name = "dt")
|
||||
// Time of data calculation, unix, UTC
|
||||
@Getter
|
||||
@Setter
|
||||
private long dataCalculationTime;
|
||||
|
||||
@JSONField(name = "main")
|
||||
@Getter
|
||||
@Setter
|
||||
private WeatherInfo weatherInfo;
|
||||
|
||||
@JSONField(name = "weather")
|
||||
@Getter
|
||||
@Setter
|
||||
private List<WeatherState> weatherStates;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Clouds clouds;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Wind wind;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Snow snow;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Rain rain;
|
||||
|
||||
@JSONField(name = "sys")
|
||||
@Getter
|
||||
@Setter
|
||||
private ForecastSystemInfo systemInfo;
|
||||
|
||||
// Data/time of calculation, UTC
|
||||
@Getter
|
||||
@Setter
|
||||
private String dt_txt;
|
||||
|
||||
public long getDataCalculationTime() {
|
||||
return dataCalculationTime;
|
||||
}
|
||||
|
||||
public void setDataCalculationTime(long dataCalculationTime) {
|
||||
this.dataCalculationTime = dataCalculationTime;
|
||||
}
|
||||
|
||||
public Date getDataCalculationDate() {
|
||||
return new Date(dataCalculationTime * 1000);
|
||||
}
|
||||
|
||||
public WeatherInfo getWeatherInfo() {
|
||||
return weatherInfo;
|
||||
}
|
||||
|
||||
public void setWeatherInfo(WeatherInfo weatherInfo) {
|
||||
this.weatherInfo = weatherInfo;
|
||||
}
|
||||
|
||||
public List<WeatherState> getWeatherStates() {
|
||||
return weatherStates;
|
||||
}
|
||||
|
||||
public void setWeatherStates(List<WeatherState> weatherStates) {
|
||||
this.weatherStates = weatherStates;
|
||||
}
|
||||
|
||||
public Clouds getClouds() {
|
||||
return clouds;
|
||||
}
|
||||
|
||||
public void setClouds(Clouds clouds) {
|
||||
this.clouds = clouds;
|
||||
}
|
||||
|
||||
public Wind getWind() {
|
||||
return wind;
|
||||
}
|
||||
|
||||
public void setWind(Wind wind) {
|
||||
this.wind = wind;
|
||||
}
|
||||
|
||||
public Snow getSnow() {
|
||||
return snow;
|
||||
}
|
||||
|
||||
public void setSnow(Snow snow) {
|
||||
this.snow = snow;
|
||||
}
|
||||
|
||||
public Rain getRain() {
|
||||
return rain;
|
||||
}
|
||||
|
||||
public void setRain(Rain rain) {
|
||||
this.rain = rain;
|
||||
}
|
||||
|
||||
public ForecastSystemInfo getSystemInfo() {
|
||||
return systemInfo;
|
||||
}
|
||||
|
||||
public void setSystemInfo(ForecastSystemInfo systemInfo) {
|
||||
this.systemInfo = systemInfo;
|
||||
}
|
||||
|
||||
public String getDt_txt() {
|
||||
return dt_txt;
|
||||
}
|
||||
|
||||
public void setDt_txt(String dt_txt) {
|
||||
this.dt_txt = dt_txt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("Time: ");
|
||||
stringBuilder.append(new Date(dataCalculationTime * 1000));
|
||||
stringBuilder.append(". ");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Time: ");
|
||||
builder.append(new Date(dataCalculationTime * 1000));
|
||||
builder.append("; ");
|
||||
if (weatherStates.size() == 1) {
|
||||
stringBuilder.append(weatherStates.get(0));
|
||||
builder.append(weatherStates.get(0));
|
||||
} else {
|
||||
stringBuilder.append(weatherStates);
|
||||
builder.append(weatherStates);
|
||||
}
|
||||
stringBuilder.append(". ");
|
||||
stringBuilder.append(weatherInfo);
|
||||
builder.append("; ");
|
||||
builder.append(weatherInfo);
|
||||
if (clouds != null) {
|
||||
stringBuilder.append(". ");
|
||||
stringBuilder.append(clouds);
|
||||
builder.append("; ");
|
||||
builder.append(clouds);
|
||||
}
|
||||
if (wind != null) {
|
||||
stringBuilder.append(". ");
|
||||
stringBuilder.append(wind);
|
||||
builder.append("; ");
|
||||
builder.append(wind);
|
||||
}
|
||||
if (snow != null) {
|
||||
stringBuilder.append(". ");
|
||||
stringBuilder.append(snow);
|
||||
builder.append("; ");
|
||||
builder.append(snow);
|
||||
}
|
||||
if (rain != null) {
|
||||
stringBuilder.append(". ");
|
||||
stringBuilder.append(rain);
|
||||
builder.append("; ");
|
||||
builder.append(rain);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Forecast that = (Forecast) o;
|
||||
return dataCalculationTime == that.dataCalculationTime &&
|
||||
Objects.equals(weatherInfo, that.weatherInfo) &&
|
||||
Objects.equals(weatherStates, that.weatherStates) &&
|
||||
Objects.equals(clouds, that.clouds) &&
|
||||
Objects.equals(wind, that.wind) &&
|
||||
Objects.equals(snow, that.snow) &&
|
||||
Objects.equals(rain, that.rain) &&
|
||||
Objects.equals(systemInfo, that.systemInfo) &&
|
||||
Objects.equals(dt_txt, that.dt_txt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(dataCalculationTime, weatherInfo, weatherStates, clouds, wind, snow, rain, systemInfo, dt_txt);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ForecastSystemInfo {
|
||||
|
||||
private String pod;
|
||||
|
||||
public String getPod() {
|
||||
return pod;
|
||||
}
|
||||
|
||||
public void setPod(String pod) {
|
||||
this.pod = pod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ForecastSystemInfo{" +
|
||||
"pod='" + pod + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ForecastSystemInfo that = (ForecastSystemInfo) o;
|
||||
return Objects.equals(pod, that.pod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(pod);
|
||||
}
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
public static class WeatherInfo {
|
||||
|
||||
@JSONField(name = "temp")
|
||||
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
@Getter
|
||||
@Setter
|
||||
private float temperature;
|
||||
|
||||
@JSONField(name = "temp_min")
|
||||
// Minimum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and
|
||||
// megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
@Getter
|
||||
@Setter
|
||||
private float minimumTemperature;
|
||||
|
||||
@JSONField(name = "temp_max")
|
||||
// Maximum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and
|
||||
// megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
@Getter
|
||||
@Setter
|
||||
private float maximumTemperature;
|
||||
|
||||
// Atmospheric pressure on the sea level by default, hPa
|
||||
@Getter
|
||||
@Setter
|
||||
private float pressure;
|
||||
|
||||
@JSONField(name = "sea_level")
|
||||
// Atmospheric pressure on the sea level, hPa
|
||||
@Getter
|
||||
@Setter
|
||||
private float seaLevelPressure;
|
||||
|
||||
@JSONField(name = "grnd_level")
|
||||
// Atmospheric pressure on the ground level, hPa
|
||||
@Getter
|
||||
@Setter
|
||||
private float groundLevelPressure;
|
||||
|
||||
// Humidity, %
|
||||
@Getter
|
||||
@Setter
|
||||
private byte humidity;
|
||||
|
||||
@JSONField(name = "temp_kf")
|
||||
// Internal parameter
|
||||
@Getter
|
||||
@Setter
|
||||
private float temperatureCoefficient;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private char temperatureUnit;
|
||||
|
||||
public float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public float getMinimumTemperature() {
|
||||
return minimumTemperature;
|
||||
}
|
||||
|
||||
public void setMinimumTemperature(float minimumTemperature) {
|
||||
this.minimumTemperature = minimumTemperature;
|
||||
}
|
||||
|
||||
public float getMaximumTemperature() {
|
||||
return maximumTemperature;
|
||||
}
|
||||
|
||||
public void setMaximumTemperature(float maximumTemperature) {
|
||||
this.maximumTemperature = maximumTemperature;
|
||||
}
|
||||
|
||||
public float getPressure() {
|
||||
return pressure;
|
||||
}
|
||||
|
||||
public void setPressure(float pressure) {
|
||||
this.pressure = pressure;
|
||||
}
|
||||
|
||||
public float getSeaLevelPressure() {
|
||||
return seaLevelPressure;
|
||||
}
|
||||
|
||||
public void setSeaLevelPressure(float seaLevelPressure) {
|
||||
this.seaLevelPressure = seaLevelPressure;
|
||||
}
|
||||
|
||||
public float getGroundLevelPressure() {
|
||||
return groundLevelPressure;
|
||||
}
|
||||
|
||||
public void setGroundLevelPressure(float groundLevelPressure) {
|
||||
this.groundLevelPressure = groundLevelPressure;
|
||||
}
|
||||
|
||||
public byte getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
public void setHumidity(byte humidity) {
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public float getTemperatureCoefficient() {
|
||||
return temperatureCoefficient;
|
||||
}
|
||||
|
||||
public void setTemperatureCoefficient(float temperatureCoefficient) {
|
||||
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() {
|
||||
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());
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Temperature: ");
|
||||
builder.append(temperature);
|
||||
builder.append(' ');
|
||||
builder.append(temperatureUnit);
|
||||
builder.append("; Minimum temperature: ");
|
||||
builder.append(minimumTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(temperatureUnit);
|
||||
builder.append("; Maximum temperature: ");
|
||||
builder.append(maximumTemperature);
|
||||
builder.append(' ');
|
||||
builder.append(temperatureUnit);
|
||||
builder.append("; Pressure: ");
|
||||
builder.append(pressure);
|
||||
builder.append(' ');
|
||||
builder.append(getPressureUnit());
|
||||
if (seaLevelPressure > 0) {
|
||||
stringBuilder.append(". Sea-level pressure: ");
|
||||
stringBuilder.append(seaLevelPressure);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(getPressureUnit());
|
||||
builder.append("; Sea-level pressure: ");
|
||||
builder.append(seaLevelPressure);
|
||||
builder.append(' ');
|
||||
builder.append(getPressureUnit());
|
||||
}
|
||||
if (groundLevelPressure > 0) {
|
||||
stringBuilder.append(". Ground-level pressure: ");
|
||||
stringBuilder.append(groundLevelPressure);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(getPressureUnit());
|
||||
builder.append("; Ground-level pressure: ");
|
||||
builder.append(groundLevelPressure);
|
||||
builder.append(' ');
|
||||
builder.append(getPressureUnit());
|
||||
}
|
||||
stringBuilder.append(". Humidity: ");
|
||||
stringBuilder.append(humidity);
|
||||
stringBuilder.append('%');
|
||||
builder.append("; Humidity: ");
|
||||
builder.append(humidity);
|
||||
builder.append('%');
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WeatherInfo weatherInfo = (WeatherInfo) o;
|
||||
return Float.compare(weatherInfo.temperature, temperature) == 0 &&
|
||||
Float.compare(weatherInfo.minimumTemperature, minimumTemperature) == 0 &&
|
||||
Float.compare(weatherInfo.maximumTemperature, maximumTemperature) == 0 &&
|
||||
Float.compare(weatherInfo.pressure, pressure) == 0 &&
|
||||
Float.compare(weatherInfo.seaLevelPressure, seaLevelPressure) == 0 &&
|
||||
Float.compare(weatherInfo.groundLevelPressure, groundLevelPressure) == 0 &&
|
||||
humidity == weatherInfo.humidity &&
|
||||
Float.compare(weatherInfo.temperatureCoefficient, temperatureCoefficient) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(temperature, minimumTemperature, maximumTemperature, pressure, seaLevelPressure, groundLevelPressure, humidity, temperatureCoefficient);
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,151 +24,76 @@ package com.github.prominence.openweathermap.api.model.response;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.github.prominence.openweathermap.api.model.*;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class Weather implements OpenWeatherResponse {
|
||||
|
||||
@JSONField(name = "id")
|
||||
@Getter
|
||||
@Setter
|
||||
private long cityId;
|
||||
|
||||
@JSONField(name = "name")
|
||||
@Getter
|
||||
@Setter
|
||||
private String cityName;
|
||||
|
||||
@JSONField(name = "coord")
|
||||
@Getter
|
||||
@Setter
|
||||
private Coordinates coordinates;
|
||||
|
||||
@JSONField(name = "weather")
|
||||
@Getter
|
||||
@Setter
|
||||
private List<WeatherState> weatherStates;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String base;
|
||||
|
||||
@JSONField(name = "main")
|
||||
@Getter
|
||||
@Setter
|
||||
private WeatherInfo weatherInfo;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Wind wind;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Clouds clouds;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Rain rain;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Snow snow;
|
||||
|
||||
@JSONField(name = "dt")
|
||||
@Getter
|
||||
@Setter
|
||||
private long dataCalculationTime;
|
||||
|
||||
@JSONField(name = "sys")
|
||||
@Getter
|
||||
@Setter
|
||||
private WeatherSystemInfo weatherSystemInfo;
|
||||
|
||||
@JSONField(name = "cod")
|
||||
@Getter
|
||||
@Setter
|
||||
private short responseCode;
|
||||
|
||||
public long getCityId() {
|
||||
return cityId;
|
||||
}
|
||||
|
||||
public void setCityId(long cityId) {
|
||||
this.cityId = cityId;
|
||||
}
|
||||
|
||||
public String getCityName() {
|
||||
return cityName;
|
||||
}
|
||||
|
||||
public void setCityName(String cityName) {
|
||||
this.cityName = cityName;
|
||||
}
|
||||
|
||||
public Coordinates getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public void setCoordinates(Coordinates coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
public List<WeatherState> getWeatherStates() {
|
||||
return weatherStates;
|
||||
}
|
||||
|
||||
public void setWeatherStates(List<WeatherState> weatherStates) {
|
||||
this.weatherStates = weatherStates;
|
||||
}
|
||||
|
||||
public String getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public void setBase(String base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public WeatherInfo getWeatherInfo() {
|
||||
return weatherInfo;
|
||||
}
|
||||
|
||||
public void setWeatherInfo(WeatherInfo weatherInfo) {
|
||||
this.weatherInfo = weatherInfo;
|
||||
}
|
||||
|
||||
public Wind getWind() {
|
||||
return wind;
|
||||
}
|
||||
|
||||
public void setWind(Wind wind) {
|
||||
this.wind = wind;
|
||||
}
|
||||
|
||||
public Clouds getClouds() {
|
||||
return clouds;
|
||||
}
|
||||
|
||||
public void setClouds(Clouds clouds) {
|
||||
this.clouds = clouds;
|
||||
}
|
||||
|
||||
public Rain getRain() {
|
||||
return rain;
|
||||
}
|
||||
|
||||
public void setRain(Rain rain) {
|
||||
this.rain = rain;
|
||||
}
|
||||
|
||||
public Snow getSnow() {
|
||||
return snow;
|
||||
}
|
||||
|
||||
public void setSnow(Snow snow) {
|
||||
this.snow = snow;
|
||||
}
|
||||
|
||||
public long getDataCalculationTime() {
|
||||
return dataCalculationTime;
|
||||
}
|
||||
|
||||
public void setDataCalculationTime(long dataCalculationTime) {
|
||||
this.dataCalculationTime = dataCalculationTime;
|
||||
}
|
||||
|
||||
public WeatherSystemInfo getWeatherSystemInfo() {
|
||||
return weatherSystemInfo;
|
||||
}
|
||||
|
||||
public void setWeatherSystemInfo(WeatherSystemInfo weatherSystemInfo) {
|
||||
this.weatherSystemInfo = weatherSystemInfo;
|
||||
}
|
||||
|
||||
public short getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public void setResponseCode(short responseCode) {
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return weatherSystemInfo.country;
|
||||
}
|
||||
@ -211,8 +136,7 @@ public class Weather implements OpenWeatherResponse {
|
||||
stringBuilder.append(cityName);
|
||||
stringBuilder.append('(');
|
||||
stringBuilder.append(cityId);
|
||||
stringBuilder.append("). ");
|
||||
stringBuilder.append("Coordinates: ");
|
||||
stringBuilder.append("); Coordinates: ");
|
||||
stringBuilder.append(coordinates);
|
||||
stringBuilder.append('\n');
|
||||
stringBuilder.append(weatherSystemInfo);
|
||||
@ -243,103 +167,56 @@ public class Weather implements OpenWeatherResponse {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
public static class WeatherInfo {
|
||||
@JSONField(name = "temp")
|
||||
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
@Getter
|
||||
@Setter
|
||||
private float temperature;
|
||||
|
||||
@JSONField(name = "pressure")
|
||||
// Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
|
||||
@Getter
|
||||
@Setter
|
||||
private short pressure;
|
||||
|
||||
@JSONField(name = "humidity")
|
||||
// Humidity, %
|
||||
@Getter
|
||||
@Setter
|
||||
private byte humidity;
|
||||
|
||||
@JSONField(name = "temp_min")
|
||||
// Minimum temperature at the moment. This is deviation from current temp that is possible for large cities
|
||||
// and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
@Getter
|
||||
@Setter
|
||||
private float minimumTemperature;
|
||||
|
||||
@JSONField(name = "temp_max")
|
||||
// Maximum temperature at the moment. This is deviation from current temp that is possible for large cities
|
||||
// and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
|
||||
@Getter
|
||||
@Setter
|
||||
private float maximumTemperature;
|
||||
|
||||
@JSONField(name = "sea_level")
|
||||
// Atmospheric pressure on the sea level, hPa
|
||||
@Getter
|
||||
@Setter
|
||||
private short seaLevelPressure;
|
||||
|
||||
@JSONField(name = "grnd_level")
|
||||
// Atmospheric pressure on the ground level, hPa
|
||||
@Getter
|
||||
@Setter
|
||||
private short groundLevelPressure;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private char temperatureUnit;
|
||||
|
||||
public float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public short getPressure() {
|
||||
return pressure;
|
||||
}
|
||||
|
||||
public void setPressure(short pressure) {
|
||||
this.pressure = pressure;
|
||||
}
|
||||
|
||||
public byte getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
public void setHumidity(byte humidity) {
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public float getMinimumTemperature() {
|
||||
return minimumTemperature;
|
||||
}
|
||||
|
||||
public void setMinimumTemperature(float minimumTemperature) {
|
||||
this.minimumTemperature = minimumTemperature;
|
||||
}
|
||||
|
||||
public float getMaximumTemperature() {
|
||||
return maximumTemperature;
|
||||
}
|
||||
|
||||
public void setMaximumTemperature(float maximumTemperature) {
|
||||
this.maximumTemperature = maximumTemperature;
|
||||
}
|
||||
|
||||
public short getSeaLevelPressure() {
|
||||
return seaLevelPressure;
|
||||
}
|
||||
|
||||
public void setSeaLevelPressure(short seaLevelPressure) {
|
||||
this.seaLevelPressure = seaLevelPressure;
|
||||
}
|
||||
|
||||
public short getGroundLevelPressure() {
|
||||
return groundLevelPressure;
|
||||
}
|
||||
|
||||
public void setGroundLevelPressure(short groundLevelPressure) {
|
||||
this.groundLevelPressure = groundLevelPressure;
|
||||
}
|
||||
|
||||
public char getTemperatureUnit() {
|
||||
return temperatureUnit;
|
||||
}
|
||||
|
||||
public void setTemperatureUnit(char temperatureUnit) {
|
||||
this.temperatureUnit = temperatureUnit;
|
||||
}
|
||||
|
||||
public String getPressureUnit() {
|
||||
return "hPa";
|
||||
}
|
||||
@ -351,11 +228,11 @@ public class Weather implements OpenWeatherResponse {
|
||||
stringBuilder.append(temperature);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(temperatureUnit);
|
||||
stringBuilder.append(". Minimum temparature: ");
|
||||
stringBuilder.append("; Minimum temparature: ");
|
||||
stringBuilder.append(minimumTemperature);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(temperatureUnit);
|
||||
stringBuilder.append(". Maximum temperature: ");
|
||||
stringBuilder.append("; Maximum temperature: ");
|
||||
stringBuilder.append(maximumTemperature);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(temperatureUnit);
|
||||
@ -369,13 +246,13 @@ public class Weather implements OpenWeatherResponse {
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(getPressureUnit());
|
||||
if (seaLevelPressure > 0) {
|
||||
stringBuilder.append(". Sea-level pressure: ");
|
||||
stringBuilder.append("; Sea-level pressure: ");
|
||||
stringBuilder.append(seaLevelPressure);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(getPressureUnit());
|
||||
}
|
||||
if (groundLevelPressure > 0) {
|
||||
stringBuilder.append(". Ground-level pressure: ");
|
||||
stringBuilder.append("; Ground-level pressure: ");
|
||||
stringBuilder.append(groundLevelPressure);
|
||||
stringBuilder.append(' ');
|
||||
stringBuilder.append(getPressureUnit());
|
||||
@ -383,105 +260,49 @@ public class Weather implements OpenWeatherResponse {
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WeatherInfo that = (WeatherInfo) o;
|
||||
return Float.compare(that.temperature, temperature) == 0 &&
|
||||
pressure == that.pressure &&
|
||||
humidity == that.humidity &&
|
||||
Float.compare(that.minimumTemperature, minimumTemperature) == 0 &&
|
||||
Float.compare(that.maximumTemperature, maximumTemperature) == 0 &&
|
||||
seaLevelPressure == that.seaLevelPressure &&
|
||||
groundLevelPressure == that.groundLevelPressure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(temperature, pressure, humidity, minimumTemperature, maximumTemperature, seaLevelPressure, groundLevelPressure);
|
||||
}
|
||||
}
|
||||
|
||||
public static class WeatherSystemInfo {
|
||||
@JSONField(name = "type")
|
||||
// Internal parameter
|
||||
@Getter
|
||||
@Setter
|
||||
private short type;
|
||||
|
||||
@JSONField(name = "id")
|
||||
// Internal parameter
|
||||
@Getter
|
||||
@Setter
|
||||
private long id;
|
||||
|
||||
@JSONField(name = "message")
|
||||
// Internal parameter
|
||||
@Getter
|
||||
@Setter
|
||||
private double message;
|
||||
|
||||
@JSONField(name = "country")
|
||||
// Country code (GB, JP etc.)
|
||||
@Getter
|
||||
@Setter
|
||||
private String country;
|
||||
|
||||
@JSONField(name = "sunrise")
|
||||
// Sunrise time, unix, UTC
|
||||
@Getter
|
||||
@Setter
|
||||
private long sunriseTimestamp;
|
||||
|
||||
@JSONField(name = "sunset")
|
||||
// Sunset time, unix, UTC
|
||||
@Getter
|
||||
@Setter
|
||||
private long sunsetTimestamp;
|
||||
|
||||
public short getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(short type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public double getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(double message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public long getSunriseTimestamp() {
|
||||
return sunriseTimestamp;
|
||||
}
|
||||
|
||||
public void setSunriseTimestamp(long sunriseTimestamp) {
|
||||
this.sunriseTimestamp = sunriseTimestamp;
|
||||
}
|
||||
|
||||
public Date getSunriseDate() {
|
||||
return new Date(sunriseTimestamp * 1000);
|
||||
}
|
||||
|
||||
public long getSunsetTimestamp() {
|
||||
return sunsetTimestamp;
|
||||
}
|
||||
|
||||
public void setSunsetTimestamp(long sunsetTimestamp) {
|
||||
this.sunsetTimestamp = sunsetTimestamp;
|
||||
}
|
||||
|
||||
public Date getSunsetDate() {
|
||||
return new Date(sunsetTimestamp * 1000);
|
||||
}
|
||||
@ -507,24 +328,5 @@ public class Weather implements OpenWeatherResponse {
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WeatherSystemInfo that = (WeatherSystemInfo) o;
|
||||
return type == that.type &&
|
||||
id == that.id &&
|
||||
Double.compare(that.message, message) == 0 &&
|
||||
Objects.equals(country, that.country) &&
|
||||
Objects.equals(sunriseTimestamp, that.sunriseTimestamp) &&
|
||||
Objects.equals(sunsetTimestamp, that.sunsetTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(type, id, message, country, sunriseTimestamp, sunsetTimestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user