Implemented DailyForecast requesting. Added 'lombok' dependency. Some refactoring...

This commit is contained in:
Prominence 2018-07-25 00:19:43 +03:00
parent 61eea0b8f6
commit d86b228c6e
16 changed files with 650 additions and 867 deletions

View File

@ -127,7 +127,7 @@ Available requests:
| `getCityId()` | Returns city ID. Example: `625144` for Minsk. | | `getCityId()` | Returns city ID. Example: `625144` for Minsk. |
| `getCityName()` | Returns city name. Example: `Minsk`. | | `getCityName()` | Returns city name. Example: `Minsk`. |
| `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. | | `getCoordinates()` | Returns `Coordinates` instance that contains *latitude* and *longitude* information. |
| `getCityInfo()` | Returns `HourlyForecast.CityInfo` instance that contains information about city. | | `getCityInfo()` | Returns `CityInfo` instance that contains information about city. |
| `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. | | `getResponseCode()` | Returns OpenWeatherMap response code. Internal information. |
| `getCountry()` | An alias for `getCityInfo().getCountry()`. | | `getCountry()` | An alias for `getCityInfo().getCountry()`. |
| `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. | | `getForecasts()` | Returns `List<HourlyForecast.Forecast>` collection with all forecast information. |

View File

@ -136,6 +136,13 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.44</version> <version>1.2.44</version>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -30,6 +30,7 @@ import com.github.prominence.openweathermap.api.model.Coordinates;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Map;
abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester { abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
@ -86,10 +87,24 @@ abstract class BasicRequester<T> extends AuthenticationTokenBasedRequester {
urlBuilder.append(accuracy); 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()); return new URL(urlBuilder.toString());
} }
protected Map<String, String> getAdditionalParameters() {
return null;
}
protected abstract String getRequestType(); protected abstract String getRequestType();
protected abstract T executeRequest(String requestSpecificParamsString) throws InvalidAuthTokenException, DataNotFoundException; protected abstract T executeRequest(String requestSpecificParameters) throws InvalidAuthTokenException, DataNotFoundException;
} }

View File

@ -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;
}
}

View File

@ -34,7 +34,11 @@ public class OpenWeatherMapManager {
return new WeatherRequester(authToken); return new WeatherRequester(authToken);
} }
public HourlyForecastRequester getForecastRequester() { public HourlyForecastRequester getHourlyForecastRequester() {
return new HourlyForecastRequester(authToken); return new HourlyForecastRequester(authToken);
} }
public DailyForecastRequester getDailyForecastRequester() {
return new DailyForecastRequester(authToken);
}
} }

View File

@ -25,7 +25,7 @@ package com.github.prominence.openweathermap.api.exception;
public class InvalidAuthTokenException extends Exception { public class InvalidAuthTokenException extends Exception {
public InvalidAuthTokenException() { public InvalidAuthTokenException() {
super("Check you authentication token! You can get it here: https://home.openweathermap.org/api_keys/."); super("Check your authentication token! You can get it here: https://home.openweathermap.org/api_keys/.");
} }
} }

View File

@ -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;
}
}

View File

@ -23,39 +23,21 @@
package com.github.prominence.openweathermap.api.model; package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects; @EqualsAndHashCode
public class Clouds { public class Clouds {
@JSONField(name = "all") @JSONField(name = "all")
// Cloudiness, % // Cloudiness, %
@Getter
@Setter
private byte cloudiness; private byte cloudiness;
public byte getCloudiness() {
return cloudiness;
}
public void setCloudiness(byte cloudiness) {
this.cloudiness = cloudiness;
}
@Override @Override
public String toString() { public String toString() {
return "Cloudiness: " + cloudiness + "%"; 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);
}
} }

View File

@ -23,55 +23,29 @@
package com.github.prominence.openweathermap.api.model; package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField; 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 { public class Coordinates {
@JSONField(name = "lat") @JSONField(name = "lat")
// City geo location, latitude // City geo location, latitude
@Getter
@Setter
private float latitude; private float latitude;
@JSONField(name = "lon") @JSONField(name = "lon")
// City geo location, longitude // City geo location, longitude
@Getter
@Setter
private float longitude; 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 @Override
public String toString() { public String toString() {
return "latitude=" + latitude + ", longitude=" + longitude; 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);
}
} }

View File

@ -23,23 +23,19 @@
package com.github.prominence.openweathermap.api.model; package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects; @EqualsAndHashCode
public class Rain { public class Rain {
@JSONField(name = "3h") @JSONField(name = "3h")
// Rain volume for the last 3 hours // Rain volume for the last 3 hours
@Getter
@Setter
private byte rainVolumeLast3Hrs; private byte rainVolumeLast3Hrs;
public byte getRainVolumeLast3Hrs() {
return rainVolumeLast3Hrs;
}
public void setRainVolumeLast3Hrs(byte rainVolumeLast3Hrs) {
this.rainVolumeLast3Hrs = rainVolumeLast3Hrs;
}
public String getUnit() { public String getUnit() {
return "mm"; return "mm";
} }
@ -48,18 +44,4 @@ public class Rain {
public String toString() { public String toString() {
return "Rain(last 3 hrs): " + rainVolumeLast3Hrs + ' ' + getUnit(); 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);
}
} }

View File

@ -23,23 +23,19 @@
package com.github.prominence.openweathermap.api.model; package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects; @EqualsAndHashCode
public class Snow { public class Snow {
@JSONField(name = "all") @JSONField(name = "all")
// Snow volume for the last 3 hours // Snow volume for the last 3 hours
@Getter
@Setter
private byte snowVolumeLast3Hrs; private byte snowVolumeLast3Hrs;
public byte getSnowVolumeLast3Hrs() {
return snowVolumeLast3Hrs;
}
public void setSnowVolumeLast3Hrs(byte snowVolumeLast3Hrs) {
this.snowVolumeLast3Hrs = snowVolumeLast3Hrs;
}
public String getUnit() { public String getUnit() {
return "mm"; return "mm";
} }
@ -48,18 +44,4 @@ public class Snow {
public String toString() { public String toString() {
return "Snow(last 3 hrs): " + snowVolumeLast3Hrs + ' ' + getUnit(); 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);
}
} }

View File

@ -23,61 +23,40 @@
package com.github.prominence.openweathermap.api.model; package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Objects;
@EqualsAndHashCode
public class WeatherState { public class WeatherState {
@JSONField(name = "id") @JSONField(name = "id")
// Weather condition id // Weather condition id
@Getter
@Setter
long conditionId; long conditionId;
@JSONField(name = "main") @JSONField(name = "main")
// Group of weather parameters (Rain, Snow, Extreme etc.) // Group of weather parameters (Rain, Snow, Extreme etc.)
@Getter
@Setter
String weatherGroup; String weatherGroup;
@JSONField(name = "description") @JSONField(name = "description")
// Weather condition within the group // Weather condition within the group
@Getter
@Setter
String description; String description;
@JSONField(name = "icon") @JSONField(name = "icon")
// Weather icon id // Weather icon id
@Getter
@Setter
String iconId; 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() { public URL getWeatherIconUrl() {
URL iconUrl = null; URL iconUrl = null;
try { try {
@ -92,21 +71,4 @@ public class WeatherState {
public String toString() { public String toString() {
return "Weather: " + description; 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);
}
} }

View File

@ -23,62 +23,31 @@
package com.github.prominence.openweathermap.api.model; package com.github.prominence.openweathermap.api.model;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects; @EqualsAndHashCode
public class Wind { public class Wind {
@JSONField(name = "speed") @JSONField(name = "speed")
// Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour. // Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour.
@Getter
@Setter
private float speed; private float speed;
@Getter
@Setter
private String unit; private String unit;
@JSONField(name = "deg") @JSONField(name = "deg")
// Wind direction, degrees (meteorological) // Wind direction, degrees (meteorological)
@Getter
@Setter
private short degrees; 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 @Override
public String toString() { public String toString() {
return "Wind: " + speed + ' ' + unit + ", " + degrees + " degrees"; 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);
}
} }

View File

@ -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();
}
}
}
}

View File

@ -24,82 +24,56 @@ package com.github.prominence.openweathermap.api.model.response;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.github.prominence.openweathermap.api.model.*; 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.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
@EqualsAndHashCode
public class HourlyForecast implements OpenWeatherResponse { public class HourlyForecast implements OpenWeatherResponse {
@JSONField(name = "cod") @JSONField(name = "cod")
@Getter
@Setter
private short responseCode; private short responseCode;
@Getter
@Setter
private double message; private double message;
// Number of lines returned by this API call // Number of lines returned by this API call
@Getter
@Setter
private short cnt; private short cnt;
@JSONField(name = "list") @JSONField(name = "list")
@Getter
@Setter
private List<Forecast> forecasts; private List<Forecast> forecasts;
@JSONField(name = "city") @JSONField(name = "city")
@Getter
@Setter
private CityInfo cityInfo; 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() { public String getCityName() {
return cityInfo.name; return cityInfo.getName();
} }
public long getCityId() { public long getCityId() {
return cityInfo.id; return cityInfo.getId();
} }
public String getCountry() { public String getCountry() {
return cityInfo.country; return cityInfo.getCountry();
} }
public Coordinates getCoordinates() { public Coordinates getCoordinates() {
return cityInfo.coordinates; return cityInfo.getCoordinates();
} }
public float getAverageTemperature() { public float getAverageTemperature() {
@ -144,464 +118,199 @@ public class HourlyForecast implements OpenWeatherResponse {
@Override @Override
public String toString() { public String toString() {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder builder = new StringBuilder();
stringBuilder.append(cityInfo); builder.append(cityInfo);
stringBuilder.append("\nForecasts: "); builder.append("\nForecasts: ");
forecasts.forEach(forecast -> { forecasts.forEach(forecast -> {
stringBuilder.append("\n\t"); builder.append("\n\t");
stringBuilder.append(forecast); builder.append(forecast);
}); });
return stringBuilder.toString(); return builder.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);
}
} }
@EqualsAndHashCode
public static class Forecast { public static class Forecast {
@JSONField(name = "dt") @JSONField(name = "dt")
// Time of data calculation, unix, UTC // Time of data calculation, unix, UTC
@Getter
@Setter
private long dataCalculationTime; private long dataCalculationTime;
@JSONField(name = "main") @JSONField(name = "main")
@Getter
@Setter
private WeatherInfo weatherInfo; private WeatherInfo weatherInfo;
@JSONField(name = "weather") @JSONField(name = "weather")
@Getter
@Setter
private List<WeatherState> weatherStates; private List<WeatherState> weatherStates;
@Getter
@Setter
private Clouds clouds; private Clouds clouds;
@Getter
@Setter
private Wind wind; private Wind wind;
@Getter
@Setter
private Snow snow; private Snow snow;
@Getter
@Setter
private Rain rain; private Rain rain;
@JSONField(name = "sys") @JSONField(name = "sys")
@Getter
@Setter
private ForecastSystemInfo systemInfo; private ForecastSystemInfo systemInfo;
// Data/time of calculation, UTC // Data/time of calculation, UTC
@Getter
@Setter
private String dt_txt; private String dt_txt;
public long getDataCalculationTime() {
return dataCalculationTime;
}
public void setDataCalculationTime(long dataCalculationTime) {
this.dataCalculationTime = dataCalculationTime;
}
public Date getDataCalculationDate() { public Date getDataCalculationDate() {
return new Date(dataCalculationTime * 1000); 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 @Override
public String toString() { public String toString() {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder builder = new StringBuilder();
stringBuilder.append("Time: "); builder.append("Time: ");
stringBuilder.append(new Date(dataCalculationTime * 1000)); builder.append(new Date(dataCalculationTime * 1000));
stringBuilder.append(". "); builder.append("; ");
if (weatherStates.size() == 1) { if (weatherStates.size() == 1) {
stringBuilder.append(weatherStates.get(0)); builder.append(weatherStates.get(0));
} else { } else {
stringBuilder.append(weatherStates); builder.append(weatherStates);
} }
stringBuilder.append(". "); builder.append("; ");
stringBuilder.append(weatherInfo); builder.append(weatherInfo);
if (clouds != null) { if (clouds != null) {
stringBuilder.append(". "); builder.append("; ");
stringBuilder.append(clouds); builder.append(clouds);
} }
if (wind != null) { if (wind != null) {
stringBuilder.append(". "); builder.append("; ");
stringBuilder.append(wind); builder.append(wind);
} }
if (snow != null) { if (snow != null) {
stringBuilder.append(". "); builder.append("; ");
stringBuilder.append(snow); builder.append(snow);
} }
if (rain != null) { if (rain != null) {
stringBuilder.append(". "); builder.append("; ");
stringBuilder.append(rain); builder.append(rain);
} }
return stringBuilder.toString(); return builder.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);
} }
@Data
public static class ForecastSystemInfo { public static class ForecastSystemInfo {
private String pod; 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 { public static class WeatherInfo {
@JSONField(name = "temp") @JSONField(name = "temp")
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit. // Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float temperature; private float temperature;
@JSONField(name = "temp_min") @JSONField(name = "temp_min")
// Minimum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and // 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. // megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float minimumTemperature; private float minimumTemperature;
@JSONField(name = "temp_max") @JSONField(name = "temp_max")
// Maximum temperature at the moment of calculation. This is deviation from 'temp' that is possible for large cities and // 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. // megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float maximumTemperature; private float maximumTemperature;
// Atmospheric pressure on the sea level by default, hPa // Atmospheric pressure on the sea level by default, hPa
@Getter
@Setter
private float pressure; private float pressure;
@JSONField(name = "sea_level") @JSONField(name = "sea_level")
// Atmospheric pressure on the sea level, hPa // Atmospheric pressure on the sea level, hPa
@Getter
@Setter
private float seaLevelPressure; private float seaLevelPressure;
@JSONField(name = "grnd_level") @JSONField(name = "grnd_level")
// Atmospheric pressure on the ground level, hPa // Atmospheric pressure on the ground level, hPa
@Getter
@Setter
private float groundLevelPressure; private float groundLevelPressure;
// Humidity, % // Humidity, %
@Getter
@Setter
private byte humidity; private byte humidity;
@JSONField(name = "temp_kf") @JSONField(name = "temp_kf")
// Internal parameter // Internal parameter
@Getter
@Setter
private float temperatureCoefficient; private float temperatureCoefficient;
@Getter
@Setter
private char temperatureUnit; 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() { public String getPressureUnit() {
return "hPa"; return "hPa";
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder builder = new StringBuilder();
stringBuilder.append("Temperature: "); builder.append("Temperature: ");
stringBuilder.append(temperature); builder.append(temperature);
stringBuilder.append(' '); builder.append(' ');
stringBuilder.append(temperatureUnit); builder.append(temperatureUnit);
stringBuilder.append(". Minimum temperature: "); builder.append("; Minimum temperature: ");
stringBuilder.append(minimumTemperature); builder.append(minimumTemperature);
stringBuilder.append(' '); builder.append(' ');
stringBuilder.append(temperatureUnit); builder.append(temperatureUnit);
stringBuilder.append(". Maximum temperature: "); builder.append("; Maximum temperature: ");
stringBuilder.append(maximumTemperature); builder.append(maximumTemperature);
stringBuilder.append(' '); builder.append(' ');
stringBuilder.append(temperatureUnit); builder.append(temperatureUnit);
stringBuilder.append(". Pressure: "); builder.append("; Pressure: ");
stringBuilder.append(pressure); builder.append(pressure);
stringBuilder.append(' '); builder.append(' ');
stringBuilder.append(getPressureUnit()); builder.append(getPressureUnit());
if (seaLevelPressure > 0) { if (seaLevelPressure > 0) {
stringBuilder.append(". Sea-level pressure: "); builder.append("; Sea-level pressure: ");
stringBuilder.append(seaLevelPressure); builder.append(seaLevelPressure);
stringBuilder.append(' '); builder.append(' ');
stringBuilder.append(getPressureUnit()); builder.append(getPressureUnit());
} }
if (groundLevelPressure > 0) { if (groundLevelPressure > 0) {
stringBuilder.append(". Ground-level pressure: "); builder.append("; Ground-level pressure: ");
stringBuilder.append(groundLevelPressure); builder.append(groundLevelPressure);
stringBuilder.append(' '); builder.append(' ');
stringBuilder.append(getPressureUnit()); builder.append(getPressureUnit());
} }
stringBuilder.append(". Humidity: "); builder.append("; Humidity: ");
stringBuilder.append(humidity); builder.append(humidity);
stringBuilder.append('%'); builder.append('%');
return stringBuilder.toString(); return builder.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);
} }
} }
} }

View File

@ -24,151 +24,76 @@ package com.github.prominence.openweathermap.api.model.response;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.github.prominence.openweathermap.api.model.*; import com.github.prominence.openweathermap.api.model.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
@EqualsAndHashCode
public class Weather implements OpenWeatherResponse { public class Weather implements OpenWeatherResponse {
@JSONField(name = "id") @JSONField(name = "id")
@Getter
@Setter
private long cityId; private long cityId;
@JSONField(name = "name") @JSONField(name = "name")
@Getter
@Setter
private String cityName; private String cityName;
@JSONField(name = "coord") @JSONField(name = "coord")
@Getter
@Setter
private Coordinates coordinates; private Coordinates coordinates;
@JSONField(name = "weather") @JSONField(name = "weather")
@Getter
@Setter
private List<WeatherState> weatherStates; private List<WeatherState> weatherStates;
@Getter
@Setter
private String base; private String base;
@JSONField(name = "main") @JSONField(name = "main")
@Getter
@Setter
private WeatherInfo weatherInfo; private WeatherInfo weatherInfo;
@Getter
@Setter
private Wind wind; private Wind wind;
@Getter
@Setter
private Clouds clouds; private Clouds clouds;
@Getter
@Setter
private Rain rain; private Rain rain;
@Getter
@Setter
private Snow snow; private Snow snow;
@JSONField(name = "dt") @JSONField(name = "dt")
@Getter
@Setter
private long dataCalculationTime; private long dataCalculationTime;
@JSONField(name = "sys") @JSONField(name = "sys")
@Getter
@Setter
private WeatherSystemInfo weatherSystemInfo; private WeatherSystemInfo weatherSystemInfo;
@JSONField(name = "cod") @JSONField(name = "cod")
@Getter
@Setter
private short responseCode; 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() { public String getCountry() {
return weatherSystemInfo.country; return weatherSystemInfo.country;
} }
@ -211,8 +136,7 @@ public class Weather implements OpenWeatherResponse {
stringBuilder.append(cityName); stringBuilder.append(cityName);
stringBuilder.append('('); stringBuilder.append('(');
stringBuilder.append(cityId); stringBuilder.append(cityId);
stringBuilder.append("). "); stringBuilder.append("); Coordinates: ");
stringBuilder.append("Coordinates: ");
stringBuilder.append(coordinates); stringBuilder.append(coordinates);
stringBuilder.append('\n'); stringBuilder.append('\n');
stringBuilder.append(weatherSystemInfo); stringBuilder.append(weatherSystemInfo);
@ -243,103 +167,56 @@ public class Weather implements OpenWeatherResponse {
return stringBuilder.toString(); return stringBuilder.toString();
} }
@EqualsAndHashCode
public static class WeatherInfo { public static class WeatherInfo {
@JSONField(name = "temp") @JSONField(name = "temp")
// Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit. // Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float temperature; private float temperature;
@JSONField(name = "pressure") @JSONField(name = "pressure")
// Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa // Atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), hPa
@Getter
@Setter
private short pressure; private short pressure;
@JSONField(name = "humidity") @JSONField(name = "humidity")
// Humidity, % // Humidity, %
@Getter
@Setter
private byte humidity; private byte humidity;
@JSONField(name = "temp_min") @JSONField(name = "temp_min")
// Minimum temperature at the moment. This is deviation from current temp that is possible for large cities // 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. // and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float minimumTemperature; private float minimumTemperature;
@JSONField(name = "temp_max") @JSONField(name = "temp_max")
// Maximum temperature at the moment. This is deviation from current temp that is possible for large cities // 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. // and megalopolises geographically expanded (use these parameter optionally). Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit.
@Getter
@Setter
private float maximumTemperature; private float maximumTemperature;
@JSONField(name = "sea_level") @JSONField(name = "sea_level")
// Atmospheric pressure on the sea level, hPa // Atmospheric pressure on the sea level, hPa
@Getter
@Setter
private short seaLevelPressure; private short seaLevelPressure;
@JSONField(name = "grnd_level") @JSONField(name = "grnd_level")
// Atmospheric pressure on the ground level, hPa // Atmospheric pressure on the ground level, hPa
@Getter
@Setter
private short groundLevelPressure; private short groundLevelPressure;
@Getter
@Setter
private char temperatureUnit; 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() { public String getPressureUnit() {
return "hPa"; return "hPa";
} }
@ -351,11 +228,11 @@ public class Weather implements OpenWeatherResponse {
stringBuilder.append(temperature); stringBuilder.append(temperature);
stringBuilder.append(' '); stringBuilder.append(' ');
stringBuilder.append(temperatureUnit); stringBuilder.append(temperatureUnit);
stringBuilder.append(". Minimum temparature: "); stringBuilder.append("; Minimum temparature: ");
stringBuilder.append(minimumTemperature); stringBuilder.append(minimumTemperature);
stringBuilder.append(' '); stringBuilder.append(' ');
stringBuilder.append(temperatureUnit); stringBuilder.append(temperatureUnit);
stringBuilder.append(". Maximum temperature: "); stringBuilder.append("; Maximum temperature: ");
stringBuilder.append(maximumTemperature); stringBuilder.append(maximumTemperature);
stringBuilder.append(' '); stringBuilder.append(' ');
stringBuilder.append(temperatureUnit); stringBuilder.append(temperatureUnit);
@ -369,13 +246,13 @@ public class Weather implements OpenWeatherResponse {
stringBuilder.append(' '); stringBuilder.append(' ');
stringBuilder.append(getPressureUnit()); stringBuilder.append(getPressureUnit());
if (seaLevelPressure > 0) { if (seaLevelPressure > 0) {
stringBuilder.append(". Sea-level pressure: "); stringBuilder.append("; Sea-level pressure: ");
stringBuilder.append(seaLevelPressure); stringBuilder.append(seaLevelPressure);
stringBuilder.append(' '); stringBuilder.append(' ');
stringBuilder.append(getPressureUnit()); stringBuilder.append(getPressureUnit());
} }
if (groundLevelPressure > 0) { if (groundLevelPressure > 0) {
stringBuilder.append(". Ground-level pressure: "); stringBuilder.append("; Ground-level pressure: ");
stringBuilder.append(groundLevelPressure); stringBuilder.append(groundLevelPressure);
stringBuilder.append(' '); stringBuilder.append(' ');
stringBuilder.append(getPressureUnit()); stringBuilder.append(getPressureUnit());
@ -383,105 +260,49 @@ public class Weather implements OpenWeatherResponse {
return stringBuilder.toString(); 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 { public static class WeatherSystemInfo {
@JSONField(name = "type") @JSONField(name = "type")
// Internal parameter // Internal parameter
@Getter
@Setter
private short type; private short type;
@JSONField(name = "id") @JSONField(name = "id")
// Internal parameter // Internal parameter
@Getter
@Setter
private long id; private long id;
@JSONField(name = "message") @JSONField(name = "message")
// Internal parameter // Internal parameter
@Getter
@Setter
private double message; private double message;
@JSONField(name = "country") @JSONField(name = "country")
// Country code (GB, JP etc.) // Country code (GB, JP etc.)
@Getter
@Setter
private String country; private String country;
@JSONField(name = "sunrise") @JSONField(name = "sunrise")
// Sunrise time, unix, UTC // Sunrise time, unix, UTC
@Getter
@Setter
private long sunriseTimestamp; private long sunriseTimestamp;
@JSONField(name = "sunset") @JSONField(name = "sunset")
// Sunset time, unix, UTC // Sunset time, unix, UTC
@Getter
@Setter
private long sunsetTimestamp; 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() { public Date getSunriseDate() {
return new Date(sunriseTimestamp * 1000); return new Date(sunriseTimestamp * 1000);
} }
public long getSunsetTimestamp() {
return sunsetTimestamp;
}
public void setSunsetTimestamp(long sunsetTimestamp) {
this.sunsetTimestamp = sunsetTimestamp;
}
public Date getSunsetDate() { public Date getSunsetDate() {
return new Date(sunsetTimestamp * 1000); return new Date(sunsetTimestamp * 1000);
} }
@ -507,24 +328,5 @@ public class Weather implements OpenWeatherResponse {
return stringBuilder.toString(); 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);
}
} }
} }