mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-07-03 03:06:45 +03:00
Version 2.0.1 (#13)
* Added method for weather icon id retrieval. Small internal changes in models. * Changed temperature unit signs.
This commit is contained in:
@@ -69,9 +69,9 @@ public enum UnitSystem {
|
||||
public String getTemperatureUnit() {
|
||||
switch (this) {
|
||||
case METRIC:
|
||||
return "℃";
|
||||
return "°C";
|
||||
case IMPERIAL:
|
||||
return "℉";
|
||||
return "°F";
|
||||
case STANDARD:
|
||||
default:
|
||||
return "K";
|
||||
|
||||
+25
-13
@@ -33,7 +33,7 @@ import java.util.Objects;
|
||||
public class WeatherForecast {
|
||||
private String state;
|
||||
private String description;
|
||||
private String weatherIconUrl;
|
||||
private String weatherIconId;
|
||||
|
||||
private LocalDateTime forecastTime;
|
||||
|
||||
@@ -113,22 +113,34 @@ public class WeatherForecast {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon ID.
|
||||
*
|
||||
* @return the weather icon ID
|
||||
*/
|
||||
public String getWeatherIconId() {
|
||||
return weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon ID.
|
||||
*
|
||||
* @param weatherIconId the weather icon ID
|
||||
*/
|
||||
public void setWeatherIconId(String weatherIconId) {
|
||||
this.weatherIconId = weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon url.
|
||||
*
|
||||
* @return the weather icon url
|
||||
*/
|
||||
public String getWeatherIconUrl() {
|
||||
return weatherIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon url.
|
||||
*
|
||||
* @param weatherIconUrl the weather icon url
|
||||
*/
|
||||
public void setWeatherIconUrl(String weatherIconUrl) {
|
||||
this.weatherIconUrl = weatherIconUrl;
|
||||
if (weatherIconId != null) {
|
||||
return "https://openweathermap.org/img/w/" + weatherIconId + ".png";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,7 +330,7 @@ public class WeatherForecast {
|
||||
WeatherForecast that = (WeatherForecast) o;
|
||||
return Objects.equals(state, that.state) &&
|
||||
Objects.equals(description, that.description) &&
|
||||
Objects.equals(weatherIconUrl, that.weatherIconUrl) &&
|
||||
Objects.equals(weatherIconId, that.weatherIconId) &&
|
||||
Objects.equals(forecastTime, that.forecastTime) &&
|
||||
Objects.equals(temperature, that.temperature) &&
|
||||
Objects.equals(atmosphericPressure, that.atmosphericPressure) &&
|
||||
@@ -333,7 +345,7 @@ public class WeatherForecast {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(state, description, weatherIconUrl, forecastTime, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||
return Objects.hash(state, description, weatherIconId, forecastTime, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, forecastTimeISO, dayTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.Objects;
|
||||
public class Weather {
|
||||
private String state;
|
||||
private String description;
|
||||
private String weatherIconUrl;
|
||||
private String weatherIconId;
|
||||
|
||||
private LocalDateTime calculatedOn;
|
||||
|
||||
@@ -112,22 +112,34 @@ public class Weather {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon ID.
|
||||
*
|
||||
* @return the weather icon ID
|
||||
*/
|
||||
public String getWeatherIconId() {
|
||||
return weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon ID.
|
||||
*
|
||||
* @param weatherIconId the weather icon ID
|
||||
*/
|
||||
public void setWeatherIconId(String weatherIconId) {
|
||||
this.weatherIconId = weatherIconId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets weather icon url.
|
||||
*
|
||||
* @return the weather icon url
|
||||
*/
|
||||
public String getWeatherIconUrl() {
|
||||
return weatherIconUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets weather icon url.
|
||||
*
|
||||
* @param weatherIconUrl the weather icon url
|
||||
*/
|
||||
public void setWeatherIconUrl(String weatherIconUrl) {
|
||||
this.weatherIconUrl = weatherIconUrl;
|
||||
if (weatherIconId != null) {
|
||||
return "http://openweathermap.org/img/w/" + weatherIconId + ".png";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +311,7 @@ public class Weather {
|
||||
Weather weather = (Weather) o;
|
||||
return Objects.equals(state, weather.state) &&
|
||||
Objects.equals(description, weather.description) &&
|
||||
Objects.equals(weatherIconUrl, weather.weatherIconUrl) &&
|
||||
Objects.equals(weatherIconId, weather.weatherIconId) &&
|
||||
Objects.equals(calculatedOn, weather.calculatedOn) &&
|
||||
Objects.equals(temperature, weather.temperature) &&
|
||||
Objects.equals(atmosphericPressure, weather.atmosphericPressure) &&
|
||||
@@ -313,7 +325,7 @@ public class Weather {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(state, description, weatherIconUrl, calculatedOn, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, location);
|
||||
return Objects.hash(state, description, weatherIconId, calculatedOn, temperature, atmosphericPressure, humidity, wind, rain, snow, clouds, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@ public class FiveDayThreeHourStepForecastResponseMapper {
|
||||
weatherNode.get("main").asText(),
|
||||
weatherNode.get("description").asText()
|
||||
);
|
||||
weatherForecast.setWeatherIconUrl("https://openweathermap.org/img/w/" + weatherNode.get("icon").asText() + ".png");
|
||||
weatherForecast.setWeatherIconId(weatherNode.get("icon").asText());
|
||||
|
||||
JsonNode mainNode = rootNode.get("main");
|
||||
weatherForecast.setTemperature(parseTemperature(mainNode));
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ public class CurrentWeatherResponseMapper {
|
||||
private Weather getSingle(JsonNode rootNode) {
|
||||
JsonNode weatherState = rootNode.get("weather").get(0);
|
||||
Weather weather = Weather.forValue(weatherState.get("main").asText(), weatherState.get("description").asText());
|
||||
weather.setWeatherIconUrl("http://openweathermap.org/img/w/" + weatherState.get("icon").asText() + ".png");
|
||||
weather.setWeatherIconId(weatherState.get("icon").asText());
|
||||
|
||||
weather.setTemperature(parseTemperature(rootNode));
|
||||
weather.setAtmosphericPressure(parsePressure(rootNode));
|
||||
|
||||
+9
-5
@@ -73,11 +73,15 @@ public class WeatherForecastUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetIconUrl_thenValueIsSet() {
|
||||
public void whenSetIconId_thenValueIsSet() {
|
||||
final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc");
|
||||
weatherForecast.setWeatherIconUrl("test");
|
||||
Assert.assertNull(weatherForecast.getWeatherIconId());
|
||||
Assert.assertNull(weatherForecast.getWeatherIconUrl());
|
||||
|
||||
Assert.assertEquals("test", weatherForecast.getWeatherIconUrl());
|
||||
weatherForecast.setWeatherIconId("02n");
|
||||
|
||||
Assert.assertEquals("02n", weatherForecast.getWeatherIconId());
|
||||
Assert.assertNotNull(weatherForecast.getWeatherIconUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,11 +262,11 @@ public class WeatherForecastUnitTest {
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
one.setWeatherIconUrl("1");
|
||||
one.setWeatherIconId("1");
|
||||
|
||||
Assert.assertFalse(one.equals(two));
|
||||
|
||||
two.setWeatherIconUrl("1");
|
||||
two.setWeatherIconId("1");
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
|
||||
+9
-5
@@ -76,11 +76,15 @@ public class WeatherUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSetIconUrl_thenValueIsSet() {
|
||||
public void whenSetIconId_thenValueIsSet() {
|
||||
final Weather weather = Weather.forValue("state", "desc");
|
||||
weather.setWeatherIconUrl("test");
|
||||
Assert.assertNull(weather.getWeatherIconId());
|
||||
Assert.assertNull(weather.getWeatherIconUrl());
|
||||
|
||||
Assert.assertEquals("test", weather.getWeatherIconUrl());
|
||||
weather.setWeatherIconId("11d");
|
||||
|
||||
Assert.assertEquals("11d", weather.getWeatherIconId());
|
||||
Assert.assertNotNull(weather.getWeatherIconUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,11 +239,11 @@ public class WeatherUnitTest {
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
one.setWeatherIconUrl("1");
|
||||
one.setWeatherIconId("1");
|
||||
|
||||
Assert.assertFalse(one.equals(two));
|
||||
|
||||
two.setWeatherIconUrl("1");
|
||||
two.setWeatherIconId("1");
|
||||
|
||||
Assert.assertTrue(one.equals(two));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user