diff --git a/docs/Release_2.0.0.md b/docs/Release_2.0.0.md index f5bfa36..7f7c1f0 100644 --- a/docs/Release_2.0.0.md +++ b/docs/Release_2.0.0.md @@ -245,7 +245,7 @@ A forecast for Minsk with 15 timestamps. |----------------------|------------------------------------------------| | Unit.METRIC_SYSTEM | Celsius, meter/sec, hPa, mm(rain, snow). | | Unit.IMPERIAL_SYSTEM | Fahrenheit, miles/hour, hPa, mm(rain, snow). | -| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow) | +| Unit.STANDARD_SYSTEM | Kelvin, meter/sec, hPa, mm(rain, snow). | ### Dependencies * com.fasterxml.jackson.core:jackson-databind:2.12.2 diff --git a/src/main/java/com/github/prominence/openweathermap/api/OpenWeatherMapClient.java b/src/main/java/com/github/prominence/openweathermap/api/OpenWeatherMapClient.java index fc94941..e0d6440 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/OpenWeatherMapClient.java +++ b/src/main/java/com/github/prominence/openweathermap/api/OpenWeatherMapClient.java @@ -30,18 +30,34 @@ import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRe import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.*; +/** + * The main public API client to communicate with OpenWeatherMap services. + * Requires API key for usage. More info on the website https://openweathermap.org/api. + */ public class OpenWeatherMapClient { private final String apiKey; + /** + * Created OpenWeatherMap client object. + * @param apiKey API key obtained on OpwnWeatherMap site. + */ public OpenWeatherMapClient(String apiKey) { this.apiKey = apiKey; } + /** + * Current Weather API. + * @return requester for retrieving current weather information. + */ @SubscriptionAvailability(plans = ALL) public CurrentWeatherRequester currentWeather() { return new CurrentWeatherRequesterImpl(apiKey); } + /** + * 5 Day / 3 Hour Forecast API. + * @return requester for retrieving 5 day/3-hour weather forecast information. + */ @SubscriptionAvailability(plans = ALL) public FiveDayThreeHourStepForecastRequester forecast5Day3HourStep() { return new FiveDayThreeHourStepForecastRequesterImpl(apiKey); diff --git a/src/main/java/com/github/prominence/openweathermap/api/annotation/SubscriptionAvailability.java b/src/main/java/com/github/prominence/openweathermap/api/annotation/SubscriptionAvailability.java index 1e499aa..8e30155 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/annotation/SubscriptionAvailability.java +++ b/src/main/java/com/github/prominence/openweathermap/api/annotation/SubscriptionAvailability.java @@ -35,5 +35,9 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) public @interface SubscriptionAvailability { + /** + * Marks method with subscription plan it needs to have to use the method. + * @return subscription plan. + */ SubscriptionPlan[] plans(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/enums/Language.java b/src/main/java/com/github/prominence/openweathermap/api/enums/Language.java index df73bae..869b9e7 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/enums/Language.java +++ b/src/main/java/com/github/prominence/openweathermap/api/enums/Language.java @@ -27,38 +27,169 @@ package com.github.prominence.openweathermap.api.enums; * Usually it could be specified to get response with some fields translated into desired language. */ public enum Language { + /** + * Arabic language. + */ ARABIC("ar"), + + /** + * Bulgarian language. + */ BULGARIAN("bg"), + + /** + * Catalan language. + */ CATALAN("ca"), + + /** + * Czech language. + */ CZECH("cz"), + + /** + * German language. + */ GERMAN("de"), + + /** + * Greek language. + */ GREEK("el"), + + /** + * English language. + */ ENGLISH("en"), + + /** + * Persian language. + */ PERSIAN("fa"), + + /** + * Finnish language. + */ FINNISH("fi"), + + /** + * French language. + */ FRENCH("fr"), + + /** + * Galician language. + */ GALICIAN("gl"), + + /** + * Croatian language. + */ CROATIAN("hr"), + + /** + * Hungarian language. + */ HUNGARIAN("hu"), + + /** + * Italian language. + */ ITALIAN("it"), + + /** + * Japanese language. + */ JAPANESE("ja"), + + /** + * Korean language. + */ KOREAN("kr"), + + /** + * Latvian language. + */ LATVIAN("la"), + + /** + * Lithuanian language. + */ LITHUANIAN("lt"), + + /** + * Macedonian language. + */ MACEDONIAN("mk"), + + /** + * Dutch language. + */ DUTCH("nl"), + + /** + * Polish language. + */ POLISH("pl"), + + /** + * Portuguese language. + */ PORTUGUESE("pt"), + + /** + * Romanian language. + */ ROMANIAN ("ro"), + + /** + * Russian language. + */ RUSSIAN("ru"), + + /** + * Swedish language. + */ SWEDISH("se"), + + /** + * Slovak language. + */ SLOVAK("sk"), + + /** + * Slovenian language. + */ SLOVENIAN("sl"), + + /** + * Spanish language. + */ SPANISH("en"), + + /** + * Turkish language. + */ TURKISH("tr"), + + /** + * Ukranian language. + */ UKRANIAN("uk"), + + /** + * Vietnamese language. + */ VIETNAMESE("vi"), + + /** + * Chinese simplified language. + */ CHINESE_SIMPLIFIED("zh_cn"), + + /** + * Chinese traditional language. + */ CHINESE_TRADITIONAL("zh_tw"); private final String value; @@ -67,6 +198,10 @@ public enum Language { this.value = value; } + /** + * Returns language's value. + * @return value. + */ public String getValue() { return value; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/enums/SubscriptionPlan.java b/src/main/java/com/github/prominence/openweathermap/api/enums/SubscriptionPlan.java index c70c4fa..b2419c7 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/enums/SubscriptionPlan.java +++ b/src/main/java/com/github/prominence/openweathermap/api/enums/SubscriptionPlan.java @@ -27,10 +27,33 @@ package com.github.prominence.openweathermap.api.enums; * More information at official website. */ public enum SubscriptionPlan { + /** + * Free subscription plan. + */ FREE, + + /** + * Startup subscription plan. + */ STARTUP, + + /** + * Developer subscription plan. + */ DEVELOPER, + + /** + * Professional subscription plan. + */ PROFESSIONAL, + + /** + * Enterprise subscription plan. + */ ENTERPRISE, + + /** + * All existing subscription plans. + */ ALL, } diff --git a/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java b/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java index 6387ed1..94e2781 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java +++ b/src/main/java/com/github/prominence/openweathermap/api/enums/UnitSystem.java @@ -26,8 +26,19 @@ package com.github.prominence.openweathermap.api.enums; * An enumeration for supported unit systems with helper methods. */ public enum UnitSystem { + /** + * Metric units: Celsius, meter/sec, hPa, mm(rain, snow). + */ METRIC("metric"), + + /** + * Imperial units: Fahrenheit, miles/hour, hPa, mm(rain, snow). + */ IMPERIAL("imperial"), + + /** + * OpenWeatherMap standard units: Kelvin, meter/sec, hPa, mm(rain, snow). + */ STANDARD("standard"); private final String value; @@ -36,6 +47,10 @@ public enum UnitSystem { this.value = value; } + /** + * Returns wind unit for current unit system. + * @return wind unit. + */ public String getWindUnit() { switch (this) { case IMPERIAL: @@ -47,6 +62,10 @@ public enum UnitSystem { } } + /** + * Returns temperature unit for current unit system. + * @return temperature unit. + */ public String getTemperatureUnit() { switch (this) { case METRIC: @@ -59,6 +78,10 @@ public enum UnitSystem { } } + /** + * Returns unit system value. + * @return value unit system. + */ public String getValue() { return value; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/exception/InvalidAuthTokenException.java b/src/main/java/com/github/prominence/openweathermap/api/exception/InvalidAuthTokenException.java index 50640fa..db5486f 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/exception/InvalidAuthTokenException.java +++ b/src/main/java/com/github/prominence/openweathermap/api/exception/InvalidAuthTokenException.java @@ -28,6 +28,9 @@ package com.github.prominence.openweathermap.api.exception; * API Keys could be checked in your profile. */ public class InvalidAuthTokenException extends RuntimeException { + /** + * Creates {@link InvalidAuthTokenException} exception with default message. + */ public InvalidAuthTokenException() { super("Authentication token wasn't set or requested functionality is not permitted for your subscription plan. Please, check https://home.openweathermap.org/api_keys/ and https://openweathermap.org/price."); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/exception/NoDataFoundException.java b/src/main/java/com/github/prominence/openweathermap/api/exception/NoDataFoundException.java index 33a6593..95572b7 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/exception/NoDataFoundException.java +++ b/src/main/java/com/github/prominence/openweathermap/api/exception/NoDataFoundException.java @@ -31,10 +31,17 @@ package com.github.prominence.openweathermap.api.exception; * */ public class NoDataFoundException extends RuntimeException { + /** + * Creates {@link NoDataFoundException} with default message. + */ public NoDataFoundException() { super("Data for provided parameters wasn't found. Please, check requested location."); } + /** + * Creates {@link NoDataFoundException} with message from another throwable. + * @param throwable source throwable. + */ public NoDataFoundException(Throwable throwable) { super(throwable.getMessage(), throwable.getCause()); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/AtmosphericPressure.java b/src/main/java/com/github/prominence/openweathermap/api/model/AtmosphericPressure.java index 55d52e6..b486a8b 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/AtmosphericPressure.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/AtmosphericPressure.java @@ -29,7 +29,6 @@ import java.util.Objects; * Its value can only be a double in [0, +∞) range. */ public class AtmosphericPressure { - private static final String DEFAULT_UNIT = "hPa"; private double value; @@ -47,7 +46,12 @@ public class AtmosphericPressure { this.value = value; } - public static AtmosphericPressure forValue(double value) { + /** + * Static method for {@link AtmosphericPressure} creation with value checking. + * @param value atmospheric pressure value. + * @return instantiated {@link AtmosphericPressure} object. + */ + public static AtmosphericPressure withValue(double value) { if (value < 0) { throw new IllegalArgumentException("Atmospheric pressure value must be in [0, +∞) range."); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/Clouds.java b/src/main/java/com/github/prominence/openweathermap/api/model/Clouds.java index 0c2678d..e5f3fa4 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/Clouds.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/Clouds.java @@ -29,7 +29,6 @@ import java.util.Objects; * Its value can only be an integer in [0, 100] range. */ public class Clouds { - private static final String DEFAULT_UNIT = "%"; private byte value; @@ -44,7 +43,12 @@ public class Clouds { this.value = value; } - public static Clouds forValue(byte value) { + /** + * Static method for {@link Clouds} creation with value checking. + * @param value clouds percentage value. + * @return instantiated {@link Clouds} object. + */ + public static Clouds withValue(byte value) { if (value < 0 || value > 100) { throw new IllegalArgumentException("Cloudiness value must be in [0, 100] range."); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/Coordinate.java b/src/main/java/com/github/prominence/openweathermap/api/model/Coordinate.java index e087083..a96acfc 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/Coordinate.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/Coordinate.java @@ -24,6 +24,9 @@ package com.github.prominence.openweathermap.api.model; import java.util.Objects; +/** + * Represents some location by its latitude and longitude. + */ public class Coordinate { private double latitude; private double longitude; @@ -33,7 +36,13 @@ public class Coordinate { this.longitude = longitude; } - public static Coordinate forValues(double latitude, double longitude) { + /** + * Method for {@link Coordinate} creation with correctness check. + * @param latitude latitude + * @param longitude longitude + * @return coordinate object. + */ + public static Coordinate withValues(double latitude, double longitude) { if (latitude < -90 || latitude > 90) { throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0]."); } @@ -43,6 +52,10 @@ public class Coordinate { return new Coordinate(latitude, longitude); } + /** + * Sets latitude with checks. + * @param latitude latitude value + */ public void setLatitude(double latitude) { if (latitude < -90 || latitude > 90) { throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0]."); @@ -50,6 +63,10 @@ public class Coordinate { this.latitude = latitude; } + /** + * Sets longitude with checks. + * @param longitude longitude value + */ public void setLongitude(double longitude) { if (longitude < -180 || longitude > 180) { throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0]."); @@ -57,10 +74,18 @@ public class Coordinate { this.longitude = longitude; } + /** + * Returns latitude. + * @return latitude + */ public double getLatitude() { return latitude; } + /** + * Returns longitude. + * @return longitude + */ public double getLongitude() { return longitude; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/CoordinateRectangle.java b/src/main/java/com/github/prominence/openweathermap/api/model/CoordinateRectangle.java index f9d5de1..2aec240 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/CoordinateRectangle.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/CoordinateRectangle.java @@ -24,9 +24,10 @@ package com.github.prominence.openweathermap.api.model; import java.util.Objects; -// TODO: builder? +/** + * Represents coordinate rectangle by its bottom-left and top-right coordinates. + */ public class CoordinateRectangle { - private final double longitudeLeft; private final double latitudeBottom; private final double longitudeRight; @@ -39,7 +40,15 @@ public class CoordinateRectangle { this.latitudeTop = latitudeTop; } - public static CoordinateRectangle forValues(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) { + /** + * Method for {@link CoordinateRectangle} creation with correctness check. + * @param longitudeLeft left longitude + * @param latitudeBottom bottom latitude + * @param longitudeRight right longitude + * @param latitudeTop tip latitude + * @return coordinate rectangle object. + */ + public static CoordinateRectangle withValues(double longitudeLeft, double latitudeBottom, double longitudeRight, double latitudeTop) { if (latitudeBottom < -90 || latitudeTop < -90 || latitudeBottom > 90 || latitudeTop > 90) { throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0]."); } @@ -49,22 +58,42 @@ public class CoordinateRectangle { return new CoordinateRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop); } + /** + * Returns left longitude value. + * @return left longitude + */ public double getLongitudeLeft() { return longitudeLeft; } + /** + * Returns bottom latitude value. + * @return bottom latitude + */ public double getLatitudeBottom() { return latitudeBottom; } + /** + * Returns right longitude value. + * @return right longitude + */ public double getLongitudeRight() { return longitudeRight; } + /** + * Returns top latitude value. + * @return top latitude + */ public double getLatitudeTop() { return latitudeTop; } + /** + * Formatted coordinate rectangle string. + * @return formatted string + */ public String getFormattedRequestString() { return longitudeLeft + "," + latitudeBottom + "," + longitudeRight + "," + latitudeTop; } @@ -89,4 +118,83 @@ public class CoordinateRectangle { public String toString() { return "Rectangle: " + getFormattedRequestString(); } + + /** + * Builder for CoordinateRectangle class. + */ + public static class Builder { + private Double longitudeLeft; + private Double latitudeBottom; + private Double longitudeRight; + private Double latitudeTop; + + /** + * Creates Builder object. + */ + public Builder() { + } + + /** + * Sets left longitude with correctness check. + * @param longitudeLeft left longitude + * @return builder object + */ + public Builder setLongitudeLeft(double longitudeLeft) { + if (longitudeLeft < -180 || longitudeLeft > 180) { + throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0]."); + } + this.longitudeLeft = longitudeLeft; + return this; + } + + /** + * Sets bottom latitude with correctness check. + * @param latitudeBottom bottom latitude + * @return builder object + */ + public Builder setLatitudeBottom(double latitudeBottom) { + if (latitudeBottom < -90 || latitudeBottom > 90) { + throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0]."); + } + this.latitudeBottom = latitudeBottom; + return this; + } + + /** + * Sets right longitude with correctness check. + * @param longitudeRight right longitude + * @return builder object + */ + public Builder setLongitudeRight(double longitudeRight) { + if (longitudeRight < -180 || longitudeRight > 180) { + throw new IllegalArgumentException("Longitude value must be in the next range: [-180.0; 180.0]."); + } + this.longitudeRight = longitudeRight; + return this; + } + + /** + * Sets top latitude with correctness check. + * @param latitudeTop top latitude + * @return builder object + */ + public Builder setLatitudeTop(double latitudeTop) { + if (latitudeTop < -90 || latitudeTop > 90) { + throw new IllegalArgumentException("Latitude value must be in the next range: [-90.0; 90.0]."); + } + this.latitudeTop = latitudeTop; + return this; + } + + /** + * Builds {@link CoordinateRectangle} object with correctness check. + * @return {@link CoordinateRectangle} built object. + */ + public CoordinateRectangle build() { + if (longitudeLeft == null || latitudeBottom == null || longitudeRight == null || latitudeTop == null) { + throw new IllegalStateException("Not all fields were set."); + } + return new CoordinateRectangle(longitudeLeft, latitudeBottom, longitudeRight, latitudeTop); + } + } } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/DayTime.java b/src/main/java/com/github/prominence/openweathermap/api/model/DayTime.java index 4fe093f..249dd35 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/DayTime.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/DayTime.java @@ -22,8 +22,18 @@ package com.github.prominence.openweathermap.api.model; +/** + * Enumeration for time of a day representation. + */ public enum DayTime { + /** + * Day value. + */ DAY("d"), + + /** + * Night value. + */ NIGHT("n"); private final String value; @@ -32,6 +42,10 @@ public enum DayTime { this.value = value; } + /** + * Returns time of a day value. + * @return string value + */ public String getValue() { return value; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/Humidity.java b/src/main/java/com/github/prominence/openweathermap/api/model/Humidity.java index 38732df..ebd9d3a 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/Humidity.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/Humidity.java @@ -29,7 +29,6 @@ import java.util.Objects; * Its value can only be an integer in [0, 100] range. */ public class Humidity { - private static final String DEFAULT_UNIT = "%"; private int value; @@ -44,7 +43,12 @@ public class Humidity { this.value = value; } - public static Humidity forValue(byte value) { + /** + * Creates {@link Humidity} object with correctness check. + * @param value humidity + * @return created {@link Humidity} object + */ + public static Humidity withValue(byte value) { if (value < 0 || value > 100) { throw new IllegalArgumentException("Humidity value must be in [0, 100] range."); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/Temperature.java b/src/main/java/com/github/prominence/openweathermap/api/model/Temperature.java index 4554a84..5ec1fec 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/Temperature.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/Temperature.java @@ -24,6 +24,9 @@ package com.github.prominence.openweathermap.api.model; import java.util.Objects; +/** + * Represents temperature values and unit. + */ public class Temperature { private double value; private Double maxTemperature; @@ -36,49 +39,95 @@ public class Temperature { this.unit = unit; } - public static Temperature forValue(double value, String unit) { + /** + * Creates {@link Temperature} object with correctness check. + * @param value temperature value + * @param unit temperature unit + * @return temperature object + */ + public static Temperature withValue(double value, String unit) { if (unit == null) { throw new IllegalArgumentException("Unit must be set."); } return new Temperature(value, unit); } + /** + * Returns temperature value. + * @return value + */ public double getValue() { return value; } + /** + * Sets temperature value. + * @param value temperature + */ public void setValue(double value) { this.value = value; } + /** + * Returns maximal temperature value. + * @return maximal temperature value + */ public Double getMaxTemperature() { return maxTemperature; } + /** + * Sets maximal temperature value. + * @param maxTemperature maximal temperature + */ public void setMaxTemperature(Double maxTemperature) { this.maxTemperature = maxTemperature; } + /** + * Returns minimal temperature value. + * @return minimal temperature value + */ public Double getMinTemperature() { return minTemperature; } + /** + * Sets minimal temperature value. + * @param minTemperature minimal temperature + */ public void setMinTemperature(Double minTemperature) { this.minTemperature = minTemperature; } + /** + * Returns 'feels like' temperature value. + * @return 'feels like' temperature value + */ public Double getFeelsLike() { return feelsLike; } + /** + * Sets 'feels like' temperature value. + * @param feelsLike 'feels like' temperature + */ public void setFeelsLike(Double feelsLike) { this.feelsLike = feelsLike; } + /** + * Returns temperature unit. + * @return unit + */ public String getUnit() { return unit; } + /** + * Sets temperature unit with correctness check. + * @param unit temperature unit + */ public void setUnit(String unit) { if (unit == null) { throw new IllegalArgumentException("Unit must be set."); diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Forecast.java b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Forecast.java index c8ee354..093beb2 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Forecast.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Forecast.java @@ -20,49 +20,46 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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.forecast; import java.util.List; import java.util.Objects; +/** + * Represents information about forecast for different timestamps. + */ public class Forecast { private Location location; private List weatherForecasts; + /** + * Returns location information. + * @return location + */ public Location getLocation() { return location; } + /** + * Sets forecast location. + * @param location forecast location + */ public void setLocation(Location location) { this.location = location; } + /** + * Returns list of weather forecasts for different timestamps. + * @return list of forecast-per-timestamp information. + */ public List getWeatherForecasts() { return weatherForecasts; } + /** + * Sets list of weather forecasts for different timestamps. + * @param weatherForecasts list of forecast information + */ public void setWeatherForecasts(List weatherForecasts) { this.weatherForecasts = weatherForecasts; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Location.java b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Location.java index 77a8ba5..0d79832 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Location.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Location.java @@ -28,8 +28,10 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.Objects; +/** + * Represents location information. + */ public class Location { - private int id; private String name; private String countryCode; @@ -47,73 +49,143 @@ public class Location { this.name = name; } - public static Location forValue(int id, String name) { + /** + * Creates {@link Location} object with correctness check. + * @param id location id + * @param name location name + * @return location object + */ + public static Location withValues(int id, String name) { if (name == null) { throw new IllegalArgumentException("Name must be set."); } return new Location(id, name); } + /** + * Returns ID. + * @return location ID + */ public int getId() { return id; } + /** + * Sets location ID. + * @param id location id + */ public void setId(int id) { this.id = id; } + /** + * Returns location name. + * @return location name + */ public String getName() { return name; } + /** + * Sets location name. + * @param name location name + */ public void setName(String name) { this.name = name; } + /** + * Returns country code. + * @return location country code + */ public String getCountryCode() { return countryCode; } + /** + * Sets location country code. + * @param countryCode location country code + */ public void setCountryCode(String countryCode) { this.countryCode = countryCode; } + /** + * Returns location sunrise time. + * @return sunrise time + */ public LocalDateTime getSunrise() { return sunrise; } + /** + * Sets location sunrise time. + * @param sunrise sunrise time + */ public void setSunrise(LocalDateTime sunrise) { this.sunrise = sunrise; } + /** + * Returns location sunset time. + * @return sunset time + */ public LocalDateTime getSunset() { return sunset; } + /** + * Sets location sunset time. + * @param sunset sunset time + */ public void setSunset(LocalDateTime sunset) { this.sunset = sunset; } + /** + * Returns location timezone offset. + * @return timezone offset + */ public ZoneOffset getZoneOffset() { return zoneOffset; } + /** + * Sets location timezone offset. + * @param zoneOffset timezone offset + */ public void setZoneOffset(ZoneOffset zoneOffset) { this.zoneOffset = zoneOffset; } + /** + * Returns location coordinates. + * @return location coordinates. + */ public Coordinate getCoordinate() { return coordinate; } + /** + * Sets location coordinates. + * @param coordinate location coordinates + */ public void setCoordinate(Coordinate coordinate) { this.coordinate = coordinate; } + /** + * Sets location population. + * @return location population + */ public Long getPopulation() { return population; } + /** + * Sets location population. + * @param population location population + */ public void setPopulation(Long population) { this.population = population; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Rain.java b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Rain.java index 0f1e828..f079bc2 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Rain.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Rain.java @@ -24,27 +24,53 @@ package com.github.prominence.openweathermap.api.model.forecast; import java.util.Objects; +/** + * Represents rain information. + */ public class Rain { - private static final String DEFAULT_UNIT = "mm"; - private Double threeHourRainLevel; + private double threeHourRainLevel; - public Rain() { - } - - public Rain(Double threeHourRainLevel) { + private Rain(double threeHourRainLevel) { this.threeHourRainLevel = threeHourRainLevel; } - public Double getThreeHourRainLevel() { + /** + * Creates {@link Rain} object with correctness check. + * @param threeHourRainLevel 3-hour rain level value + * @return rain object. + */ + public static Rain withThreeHourLevelValue(double threeHourRainLevel) { + if (threeHourRainLevel < 0) { + throw new IllegalArgumentException("Rain level value cannot be negative."); + } + return new Rain(threeHourRainLevel); + } + + /** + * Returns 3-hour rain level value. + * @return 3-hour rain level value + */ + public double getThreeHourRainLevel() { return threeHourRainLevel; } - public void setThreeHourRainLevel(Double threeHourRainLevel) { + /** + * Sets 3-hour rain level value with correctness check. + * @param threeHourRainLevel 3-hour rain level value + */ + public void setThreeHourRainLevel(double threeHourRainLevel) { + if (threeHourRainLevel < 0) { + throw new IllegalArgumentException("Rain level value cannot be negative."); + } this.threeHourRainLevel = threeHourRainLevel; } + /** + * Returns rain level unit of measure. Currently is constant. + * @return rain level unit of measure + */ public String getUnit() { return DEFAULT_UNIT; } @@ -52,9 +78,9 @@ public class Rain { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof Rain)) return false; + if (o == null || getClass() != o.getClass()) return false; Rain rain = (Rain) o; - return Objects.equals(threeHourRainLevel, rain.threeHourRainLevel); + return Double.compare(rain.threeHourRainLevel, threeHourRainLevel) == 0; } @Override @@ -64,14 +90,8 @@ public class Rain { @Override public String toString() { - StringBuilder snowString = new StringBuilder(); - if (threeHourRainLevel == null) { - snowString.append("unknown"); - } else { - snowString.append("3 last hours rain level: "); - snowString.append(threeHourRainLevel); - snowString.append(getUnit()); - } - return snowString.toString(); + return "3-hour rain level: " + + threeHourRainLevel + ' ' + + getUnit(); } } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Snow.java b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Snow.java index aad2144..d0cea01 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Snow.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Snow.java @@ -24,26 +24,53 @@ package com.github.prominence.openweathermap.api.model.forecast; import java.util.Objects; +/** + * Represents snow information. + */ public class Snow { - private static final String DEFAULT_UNIT = "mm"; - private Double threeHourSnowLevel; + private double threeHourSnowLevel; - public Snow() { - } - - public Snow(Double threeHourSnowLevel) { + private Snow(double threeHourSnowLevel) { this.threeHourSnowLevel = threeHourSnowLevel; } - public Double getThreeHourSnowLevel() { + + /** + * Creates {@link Snow} object with correctness check. + * @param threeHourSnowLevel 3-hour snow level value + * @return snow object. + */ + public static Snow withThreeHourLevelValue(double threeHourSnowLevel) { + if (threeHourSnowLevel < 0) { + throw new IllegalArgumentException("Snow level value cannot be negative."); + } + return new Snow(threeHourSnowLevel); + } + + /** + * Returns 3-hour snow level value. + * @return 3-hour snow level value + */ + public double getThreeHourSnowLevel() { return threeHourSnowLevel; } - public void setThreeHourSnowLevel(Double threeHourSnowLevel) { + /** + * Sets 3-hour snow level value with correctness check. + * @param threeHourSnowLevel 3-hour snow level value + */ + public void setThreeHourSnowLevel(double threeHourSnowLevel) { + if (threeHourSnowLevel < 0) { + throw new IllegalArgumentException("Snow level value cannot be negative."); + } this.threeHourSnowLevel = threeHourSnowLevel; } + /** + * Returns snow level unit of measure. Currently is constant. + * @return snow level unit of measure + */ public String getUnit() { return DEFAULT_UNIT; } @@ -51,9 +78,9 @@ public class Snow { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof Snow)) return false; + if (o == null || getClass() != o.getClass()) return false; Snow snow = (Snow) o; - return Objects.equals(threeHourSnowLevel, snow.threeHourSnowLevel); + return Double.compare(snow.threeHourSnowLevel, threeHourSnowLevel) == 0; } @Override @@ -63,14 +90,8 @@ public class Snow { @Override public String toString() { - StringBuilder snowString = new StringBuilder(); - if (threeHourSnowLevel == null) { - snowString.append("unknown"); - } else { - snowString.append("3 last hours snow level: "); - snowString.append(threeHourSnowLevel); - snowString.append(getUnit()); - } - return snowString.toString(); + return "3-hour snow level: " + + threeHourSnowLevel + ' ' + + getUnit(); } } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecast.java b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecast.java index bc96f39..7c12652 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecast.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecast.java @@ -27,6 +27,9 @@ import com.github.prominence.openweathermap.api.model.*; import java.time.LocalDateTime; import java.util.Objects; +/** + * Represents weather forecast information for a particular timestamp. + */ public class WeatherForecast { private String state; private String description; @@ -51,6 +54,13 @@ public class WeatherForecast { this.description = description; } + /** + * For value weather forecast. + * + * @param state the state + * @param description the description + * @return the weather forecast + */ public static WeatherForecast forValue(String state, String description) { if (state == null) { throw new IllegalArgumentException("State must be set."); @@ -61,10 +71,20 @@ public class WeatherForecast { return new WeatherForecast(state, description); } + /** + * Gets state. + * + * @return the state + */ public String getState() { return state; } + /** + * Sets state. + * + * @param state the state + */ public void setState(String state) { if (state == null) { throw new IllegalArgumentException("State must be not null."); @@ -72,10 +92,20 @@ public class WeatherForecast { this.state = state; } + /** + * Gets description. + * + * @return the description + */ public String getDescription() { return description; } + /** + * Sets description. + * + * @param description the description + */ public void setDescription(String description) { if (description == null) { throw new IllegalArgumentException("Description must be not null."); @@ -83,90 +113,200 @@ public class WeatherForecast { this.description = description; } + /** + * 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; } + /** + * Gets forecast time. + * + * @return the forecast time + */ public LocalDateTime getForecastTime() { return forecastTime; } + /** + * Sets forecast time. + * + * @param forecastTime the forecast time + */ public void setForecastTime(LocalDateTime forecastTime) { this.forecastTime = forecastTime; } + /** + * Gets temperature. + * + * @return the temperature + */ public Temperature getTemperature() { return temperature; } + /** + * Sets temperature. + * + * @param temperature the temperature + */ public void setTemperature(Temperature temperature) { this.temperature = temperature; } + /** + * Gets atmospheric pressure. + * + * @return the atmospheric pressure + */ public AtmosphericPressure getAtmosphericPressure() { return atmosphericPressure; } + /** + * Sets atmospheric pressure. + * + * @param atmosphericPressure the atmospheric pressure + */ public void setAtmosphericPressure(AtmosphericPressure atmosphericPressure) { this.atmosphericPressure = atmosphericPressure; } + /** + * Gets humidity. + * + * @return the humidity + */ public Humidity getHumidity() { return humidity; } + /** + * Sets humidity. + * + * @param humidity the humidity + */ public void setHumidity(Humidity humidity) { this.humidity = humidity; } + /** + * Gets wind. + * + * @return the wind + */ public Wind getWind() { return wind; } + /** + * Sets wind. + * + * @param wind the wind + */ public void setWind(Wind wind) { this.wind = wind; } + /** + * Gets rain. + * + * @return the rain + */ public Rain getRain() { return rain; } + /** + * Sets rain. + * + * @param rain the rain + */ public void setRain(Rain rain) { this.rain = rain; } + /** + * Gets snow. + * + * @return the snow + */ public Snow getSnow() { return snow; } + /** + * Sets snow. + * + * @param snow the snow + */ public void setSnow(Snow snow) { this.snow = snow; } + /** + * Gets clouds. + * + * @return the clouds + */ public Clouds getClouds() { return clouds; } + /** + * Sets clouds. + * + * @param clouds the clouds + */ public void setClouds(Clouds clouds) { this.clouds = clouds; } + /** + * Gets forecast time iso. + * + * @return the forecast time iso + */ public String getForecastTimeISO() { return forecastTimeISO; } + /** + * Sets forecast time iso. + * + * @param forecastTimeISO the forecast time iso + */ public void setForecastTimeISO(String forecastTimeISO) { this.forecastTimeISO = forecastTimeISO; } + /** + * Gets day time. + * + * @return the day time + */ public DayTime getDayTime() { return dayTime; } + /** + * Sets day time. + * + * @param dayTime the day time + */ public void setDayTime(DayTime dayTime) { this.dayTime = dayTime; } @@ -219,13 +359,13 @@ public class WeatherForecast { stringBuilder.append(", "); stringBuilder.append(clouds.toString()); } - if (rain != null && rain.getThreeHourRainLevel() != null) { + if (rain != null) { stringBuilder.append(", Rain: "); stringBuilder.append(rain.getThreeHourRainLevel()); stringBuilder.append(' '); stringBuilder.append(rain.getUnit()); } - if (snow != null && snow.getThreeHourSnowLevel() != null) { + if (snow != null) { stringBuilder.append(", Snow: "); stringBuilder.append(snow.getThreeHourSnowLevel()); stringBuilder.append(' '); diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Wind.java b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Wind.java index 5c14760..d54af6d 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Wind.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/forecast/Wind.java @@ -20,37 +20,14 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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.forecast; import java.util.Objects; /** - * The type Wind. + * Represents wind information. */ public class Wind { - private double speed; private Double degrees; private String unit; @@ -66,7 +43,13 @@ public class Wind { this.unit = unit; } - public static Wind forValue(double speed, String unit) { + /** + * Creates {@link Wind} object with correctness check + * @param speed the wind + * @param unit the unitSystem + * @return created wind object + */ + public static Wind withValue(double speed, String unit) { if (speed < 0) { throw new IllegalArgumentException("Wind speed value must be in positive or zero."); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Location.java b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Location.java index c4e0ce5..0a8cbea 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Location.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Location.java @@ -20,28 +20,6 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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.weather; import com.github.prominence.openweathermap.api.model.Coordinate; @@ -50,8 +28,10 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.Objects; +/** + * Represents location information. + */ public class Location { - private int id; private String name; private String countryCode; @@ -67,65 +47,127 @@ public class Location { this.name = name; } - public static Location forValue(int id, String name) { + /** + * Creates {@link Location} object with correctness check. + * @param id location id + * @param name location name + * @return location object + */ + public static Location withValues(int id, String name) { if (name == null) { throw new IllegalArgumentException("Name must be set."); } return new Location(id, name); } + /** + * Returns ID. + * @return location ID + */ public int getId() { return id; } + /** + * Sets location ID. + * @param id location id + */ public void setId(int id) { this.id = id; } + /** + * Returns location name. + * @return location name + */ public String getName() { return name; } + /** + * Sets location name. + * @param name location name + */ public void setName(String name) { this.name = name; } + /** + * Returns country code. + * @return location country code + */ public String getCountryCode() { return countryCode; } + /** + * Sets location country code. + * @param countryCode location country code + */ public void setCountryCode(String countryCode) { this.countryCode = countryCode; } + /** + * Returns location sunrise time. + * @return sunrise time + */ public LocalDateTime getSunrise() { return sunrise; } + /** + * Sets location sunrise time. + * @param sunrise sunrise time + */ public void setSunrise(LocalDateTime sunrise) { this.sunrise = sunrise; } + /** + * Returns location sunset time. + * @return sunset time + */ public LocalDateTime getSunset() { return sunset; } + /** + * Sets location sunset time. + * @param sunset sunset time + */ public void setSunset(LocalDateTime sunset) { this.sunset = sunset; } + /** + * Returns location timezone offset. + * @return timezone offset + */ public ZoneOffset getZoneOffset() { return zoneOffset; } + /** + * Sets location timezone offset. + * @param zoneOffset timezone offset + */ public void setZoneOffset(ZoneOffset zoneOffset) { this.zoneOffset = zoneOffset; } + /** + * Returns location coordinates. + * @return location coordinates. + */ public Coordinate getCoordinate() { return coordinate; } + /** + * Sets location coordinates. + * @param coordinate location coordinates + */ public void setCoordinate(Coordinate coordinate) { this.coordinate = coordinate; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Rain.java b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Rain.java index 24449ae..78be760 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Rain.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Rain.java @@ -20,63 +20,107 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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.weather; import java.util.Objects; +/** + * Represents rain information. + */ public class Rain { - private static final String DEFAULT_UNIT = "mm"; private Double oneHourRainLevel; private Double threeHourRainLevel; - public Rain() { + private Rain() { } - public Rain(Double oneHourRainLevel, Double threeHourRainLevel) { - this.oneHourRainLevel = oneHourRainLevel; - this.threeHourRainLevel = threeHourRainLevel; + /** + * Creates {@link Rain} object with correctness check. + * + * @param oneHourRainLevel 1-hour rain level value + * @return rain object. + */ + public static Rain withOneHourLevelValue(double oneHourRainLevel) { + Rain rain = new Rain(); + rain.setOneHourRainLevel(oneHourRainLevel); + return rain; } + /** + * Creates {@link Rain} object with correctness check. + * + * @param threeHourRainLevel 3-hour rain level value + * @return rain object. + */ + public static Rain withThreeHourLevelValue(double threeHourRainLevel) { + Rain rain = new Rain(); + rain.setThreeHourRainLevel(threeHourRainLevel); + return rain; + } + + /** + * Creates {@link Rain} object with correctness check. + * + * @param oneHourRainLevel the one hour rain level + * @param threeHourRainLevel the three hour rain level + * @return the rain + */ + public static Rain withValues(double oneHourRainLevel, double threeHourRainLevel) { + Rain rain = new Rain(); + rain.setOneHourRainLevel(oneHourRainLevel); + rain.setThreeHourRainLevel(threeHourRainLevel); + return rain; + } + + /** + * Gets one hour rain level. + * + * @return the one hour rain level + */ public Double getOneHourRainLevel() { return oneHourRainLevel; } - public void setOneHourRainLevel(Double oneHourRainLevel) { + /** + * Sets one hour rain level. + * + * @param oneHourRainLevel the one hour rain level + */ + public void setOneHourRainLevel(double oneHourRainLevel) { + if (oneHourRainLevel < 0) { + throw new IllegalArgumentException("Rain level value cannot be negative."); + } this.oneHourRainLevel = oneHourRainLevel; } + /** + * Gets three hour rain level. + * + * @return the three hour rain level + */ public Double getThreeHourRainLevel() { return threeHourRainLevel; } - public void setThreeHourRainLevel(Double threeHourRainLevel) { + /** + * Sets three hour rain level. + * + * @param threeHourRainLevel the three hour rain level + */ + public void setThreeHourRainLevel(double threeHourRainLevel) { + if (threeHourRainLevel < 0) { + throw new IllegalArgumentException("Rain level value cannot be negative."); + } this.threeHourRainLevel = threeHourRainLevel; } + /** + * Gets unit. + * + * @return the unit + */ public String getUnit() { return DEFAULT_UNIT; } @@ -98,22 +142,18 @@ public class Rain { @Override public String toString() { StringBuilder snowString = new StringBuilder(); - if (oneHourRainLevel == null && threeHourRainLevel == null) { - snowString.append("unknown"); - } else { + if (oneHourRainLevel != null) { + snowString.append("1-hour rain level: "); + snowString.append(oneHourRainLevel); + snowString.append(getUnit()); + } + if (threeHourRainLevel != null) { if (oneHourRainLevel != null) { - snowString.append("1 last hour rain level: "); - snowString.append(oneHourRainLevel); - snowString.append(getUnit()); - } - if (threeHourRainLevel != null) { - if (oneHourRainLevel != null) { - snowString.append(", "); - } - snowString.append("3 last hours rain level: "); - snowString.append(threeHourRainLevel); - snowString.append(getUnit()); + snowString.append(", "); } + snowString.append("3-hours rain level: "); + snowString.append(threeHourRainLevel); + snowString.append(getUnit()); } return snowString.toString(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Snow.java b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Snow.java index 9c7e881..66991fd 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Snow.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Snow.java @@ -20,63 +20,107 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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.weather; import java.util.Objects; +/** + * Represents snow information. + */ public class Snow { - private static final String DEFAULT_UNIT = "mm"; private Double oneHourSnowLevel; private Double threeHourSnowLevel; - public Snow() { + private Snow() { } - public Snow(Double oneHourSnowLevel, Double threeHourSnowLevel) { - this.oneHourSnowLevel = oneHourSnowLevel; - this.threeHourSnowLevel = threeHourSnowLevel; + /** + * Creates {@link Snow} object with correctness check. + * + * @param oneHourSnowLevel 1-hour snow level value + * @return snow object. + */ + public static Snow withOneHourLevelValue(double oneHourSnowLevel) { + Snow snow = new Snow(); + snow.setOneHourSnowLevel(oneHourSnowLevel); + return snow; } + /** + * Creates {@link Snow} object with correctness check. + * + * @param threeHourSnowLevel 3-hour snow level value + * @return snow object. + */ + public static Snow withThreeHourLevelValue(double threeHourSnowLevel) { + Snow snow = new Snow(); + snow.setThreeHourSnowLevel(threeHourSnowLevel); + return snow; + } + + /** + * Creates {@link Snow} object with correctness check. + * + * @param oneHourSnowLevel the one hour snow level + * @param threeHourSnowLevel the three hour snow level + * @return the snow + */ + public static Snow withValues(double oneHourSnowLevel, double threeHourSnowLevel) { + Snow snow = new Snow(); + snow.setOneHourSnowLevel(oneHourSnowLevel); + snow.setThreeHourSnowLevel(threeHourSnowLevel); + return snow; + } + + /** + * Gets one hour snow level. + * + * @return the one hour snow level + */ public Double getOneHourSnowLevel() { return oneHourSnowLevel; } - public void setOneHourSnowLevel(Double oneHourSnowLevel) { + /** + * Sets one hour snow level. + * + * @param oneHourSnowLevel the one hour snow level + */ + public void setOneHourSnowLevel(double oneHourSnowLevel) { + if (oneHourSnowLevel < 0) { + throw new IllegalArgumentException("Snow level value cannot be negative."); + } this.oneHourSnowLevel = oneHourSnowLevel; } + /** + * Gets three hour snow level. + * + * @return the three hour snow level + */ public Double getThreeHourSnowLevel() { return threeHourSnowLevel; } - public void setThreeHourSnowLevel(Double threeHourSnowLevel) { + /** + * Sets three hour snow level. + * + * @param threeHourSnowLevel the three hour snow level + */ + public void setThreeHourSnowLevel(double threeHourSnowLevel) { + if (threeHourSnowLevel < 0) { + throw new IllegalArgumentException("Snow level value cannot be negative."); + } this.threeHourSnowLevel = threeHourSnowLevel; } + /** + * Gets unit. + * + * @return the unit + */ public String getUnit() { return DEFAULT_UNIT; } @@ -98,22 +142,18 @@ public class Snow { @Override public String toString() { StringBuilder snowString = new StringBuilder(); - if (oneHourSnowLevel == null && threeHourSnowLevel == null) { - snowString.append("unknown"); - } else { + if (oneHourSnowLevel != null) { + snowString.append("1-hour snow level: "); + snowString.append(oneHourSnowLevel); + snowString.append(getUnit()); + } + if (threeHourSnowLevel != null) { if (oneHourSnowLevel != null) { - snowString.append("1 last hour snow level: "); - snowString.append(oneHourSnowLevel); - snowString.append(getUnit()); - } - if (threeHourSnowLevel != null) { - if (oneHourSnowLevel != null) { - snowString.append(", "); - } - snowString.append("3 last hours snow level: "); - snowString.append(threeHourSnowLevel); - snowString.append(getUnit()); + snowString.append(", "); } + snowString.append("3-hours snow level: "); + snowString.append(threeHourSnowLevel); + snowString.append(getUnit()); } return snowString.toString(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Weather.java b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Weather.java index ad78290..b2f5ff0 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Weather.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Weather.java @@ -20,28 +20,6 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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.weather; import com.github.prominence.openweathermap.api.model.*; @@ -49,6 +27,9 @@ import com.github.prominence.openweathermap.api.model.*; import java.time.LocalDateTime; import java.util.Objects; +/** + * Represents weather information. + */ public class Weather { private String state; private String description; @@ -72,6 +53,13 @@ public class Weather { this.description = description; } + /** + * For value weather. + * + * @param state the state + * @param description the description + * @return the weather + */ public static Weather forValue(String state, String description) { if (state == null) { throw new IllegalArgumentException("State must be set."); @@ -82,10 +70,20 @@ public class Weather { return new Weather(state, description); } + /** + * Gets state. + * + * @return the state + */ public String getState() { return state; } + /** + * Sets state. + * + * @param state the state + */ public void setState(String state) { if (state == null) { throw new IllegalArgumentException("State must be set."); @@ -93,10 +91,20 @@ public class Weather { this.state = state; } + /** + * Gets description. + * + * @return the description + */ public String getDescription() { return description; } + /** + * Sets description. + * + * @param description the description + */ public void setDescription(String description) { if (description == null) { throw new IllegalArgumentException("Description must be set."); @@ -104,82 +112,182 @@ public class Weather { this.description = description; } + /** + * 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; } + /** + * Gets calculated on. + * + * @return the calculated on + */ public LocalDateTime getCalculatedOn() { return calculatedOn; } + /** + * Sets calculated on. + * + * @param calculatedOn the calculated on + */ public void setCalculatedOn(LocalDateTime calculatedOn) { this.calculatedOn = calculatedOn; } + /** + * Gets temperature. + * + * @return the temperature + */ public Temperature getTemperature() { return temperature; } + /** + * Sets temperature. + * + * @param temperature the temperature + */ public void setTemperature(Temperature temperature) { this.temperature = temperature; } + /** + * Gets atmospheric pressure. + * + * @return the atmospheric pressure + */ public AtmosphericPressure getAtmosphericPressure() { return atmosphericPressure; } + /** + * Sets atmospheric pressure. + * + * @param atmosphericPressure the atmospheric pressure + */ public void setAtmosphericPressure(AtmosphericPressure atmosphericPressure) { this.atmosphericPressure = atmosphericPressure; } + /** + * Gets humidity. + * + * @return the humidity + */ public Humidity getHumidity() { return humidity; } + /** + * Sets humidity. + * + * @param humidity the humidity + */ public void setHumidity(Humidity humidity) { this.humidity = humidity; } + /** + * Gets wind. + * + * @return the wind + */ public Wind getWind() { return wind; } + /** + * Sets wind. + * + * @param wind the wind + */ public void setWind(Wind wind) { this.wind = wind; } + /** + * Gets rain. + * + * @return the rain + */ public Rain getRain() { return rain; } + /** + * Sets rain. + * + * @param rain the rain + */ public void setRain(Rain rain) { this.rain = rain; } + /** + * Gets snow. + * + * @return the snow + */ public Snow getSnow() { return snow; } + /** + * Sets snow. + * + * @param snow the snow + */ public void setSnow(Snow snow) { this.snow = snow; } + /** + * Gets clouds. + * + * @return the clouds + */ public Clouds getClouds() { return clouds; } + /** + * Sets clouds. + * + * @param clouds the clouds + */ public void setClouds(Clouds clouds) { this.clouds = clouds; } + /** + * Gets location. + * + * @return the location + */ public Location getLocation() { return location; } + /** + * Sets location. + * + * @param location the location + */ public void setLocation(Location location) { this.location = location; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Wind.java b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Wind.java index 0b1d28d..3d9b4a8 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/model/weather/Wind.java +++ b/src/main/java/com/github/prominence/openweathermap/api/model/weather/Wind.java @@ -28,7 +28,6 @@ import java.util.Objects; * The type Wind. */ public class Wind { - private double speed; private Double degrees; private Double gust; @@ -45,7 +44,13 @@ public class Wind { this.unit = unit; } - public static Wind forValue(double speed, String unit) { + /** + * Creates {@link Wind} object with correctness check. + * @param speed the speed + * @param unit the unitSystem + * @return wind object + */ + public static Wind withValue(double speed, String unit) { if (speed < 0) { throw new IllegalArgumentException("Wind speed value must be in positive or zero."); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/AsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/AsyncRequestTerminator.java index a216e67..099f958 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/AsyncRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/AsyncRequestTerminator.java @@ -24,5 +24,11 @@ package com.github.prominence.openweathermap.api.request; import java.util.concurrent.CompletableFuture; +/** + * The interface Async request terminator. + * + * @param the type parameter + * @param the type parameter + */ public interface AsyncRequestTerminator extends RequestTerminator, CompletableFuture> { } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/RequestCustomizer.java b/src/main/java/com/github/prominence/openweathermap/api/request/RequestCustomizer.java index ccca335..daf544e 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/RequestCustomizer.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/RequestCustomizer.java @@ -25,9 +25,26 @@ package com.github.prominence.openweathermap.api.request; import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.UnitSystem; +/** + * The interface Request customizer. + * + * @param the type parameter + */ public interface RequestCustomizer> { + /** + * Customize language. + * + * @param language the language + * @return the request customizer + */ T language(Language language); + /** + * Customize unit system. + * + * @param unitSystem the unit system + * @return the request customizer + */ T unitSystem(UnitSystem unitSystem); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/RequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/RequestTerminator.java index 2060144..20a8f97 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/RequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/RequestTerminator.java @@ -22,9 +22,25 @@ package com.github.prominence.openweathermap.api.request; +/** + * The interface Request terminator. + * + * @param the type parameter + * @param the type parameter + */ public interface RequestTerminator { + /** + * Java object response format. + * + * @return the java object + */ T asJava(); + /** + * JSON response format. + * + * @return the JSON string + */ S asJSON(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/RequestUrlBuilder.java b/src/main/java/com/github/prominence/openweathermap/api/request/RequestUrlBuilder.java index aa9d55e..378bfca 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/RequestUrlBuilder.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/RequestUrlBuilder.java @@ -29,6 +29,9 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; +/** + * The type Request url builder. + */ public class RequestUrlBuilder { private static final String API_KEY_PARAM_NAME = "appid"; @@ -36,18 +39,40 @@ public class RequestUrlBuilder { private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/"); private final Map requestParameters = new HashMap<>(); + /** + * Instantiates a new Request url builder. + * + * @param key the API key + */ public RequestUrlBuilder(String key) { requestParameters.put(API_KEY_PARAM_NAME, key); } + /** + * Appends value. + * + * @param value the value + */ public void append(String value) { builder.append(value); } + /** + * Adds request parameter. + * + * @param key the key + * @param value the value + */ public void addRequestParameter(String key, Object value) { requestParameters.put(key, value); } + /** + * Applies customization. + * + * @param language the language + * @param unitSystem the unit system + */ public void applyCustomization(Language language, UnitSystem unitSystem) { if (language != null) { addRequestParameter("lang", language.getValue()); @@ -57,6 +82,11 @@ public class RequestUrlBuilder { } } + /** + * Builds url string. + * + * @return the string + */ public String buildUrl() { final String joinedParameters = requestParameters.entrySet().stream() .map(entry -> entry.getKey() + "=" + entry.getValue()) diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/ResponseMapper.java b/src/main/java/com/github/prominence/openweathermap/api/request/ResponseMapper.java deleted file mode 100644 index f1ce9d8..0000000 --- a/src/main/java/com/github/prominence/openweathermap/api/request/ResponseMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 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.request; - -import java.util.List; - -public interface ResponseMapper { - - T getSingle(String json); - - List getList(String json); -} diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminator.java index 03c3fcb..a2eeb14 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminator.java @@ -28,7 +28,15 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator; import java.util.concurrent.CompletableFuture; +/** + * The forecast async request terminator interface. + */ public interface FiveDayThreeHourStepForecastAsyncRequestTerminator extends AsyncRequestTerminator { + /** + * XML response format. + * + * @return the completable future + */ CompletableFuture asXML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl.java index 286b8df..9806ac7 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl.java @@ -29,11 +29,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils; import java.util.concurrent.CompletableFuture; +/** + * Async request terminator. + */ public class FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl implements FiveDayThreeHourStepForecastAsyncRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new async request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ FiveDayThreeHourStepForecastAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizer.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizer.java index f8dde7e..c6b10c1 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizer.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizer.java @@ -24,11 +24,30 @@ package com.github.prominence.openweathermap.api.request.forecast.free; import com.github.prominence.openweathermap.api.request.RequestCustomizer; +/** + * The forecast request customizer interface. + */ public interface FiveDayThreeHourStepForecastRequestCustomizer extends RequestCustomizer { + /** + * Count customizer. + * + * @param numberOfTimestamps the number of timestamps + * @return forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer count(int numberOfTimestamps); + /** + * Retrieve forecast request terminator. + * + * @return forecast request terminator + */ FiveDayThreeHourStepForecastRequestTerminator retrieve(); + /** + * Retrieve forecast async request terminator. + * + * @return forecast async request terminator + */ FiveDayThreeHourStepForecastAsyncRequestTerminator retrieveAsync(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizerImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizerImpl.java index ad2dabc..ec462b6 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizerImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestCustomizerImpl.java @@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; +/** + * The forecast request customizer. + */ public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDayThreeHourStepForecastRequestCustomizer { private final RequestUrlBuilder urlBuilder; @@ -34,6 +37,11 @@ public class FiveDayThreeHourStepForecastRequestCustomizerImpl implements FiveDa private UnitSystem unitSystem = UnitSystem.STANDARD; private int count = -1; + /** + * Instantiates a new forecast request customizer. + * + * @param urlBuilder the url builder + */ FiveDayThreeHourStepForecastRequestCustomizerImpl(RequestUrlBuilder urlBuilder) { this.urlBuilder = urlBuilder; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminator.java index c1e075c..0f07243 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminator.java @@ -26,7 +26,15 @@ import com.github.prominence.openweathermap.api.model.forecast.Forecast; import com.github.prominence.openweathermap.api.request.RequestTerminator; +/** + * The forecast request terminator interface. + */ public interface FiveDayThreeHourStepForecastRequestTerminator extends RequestTerminator { + /** + * XML response format. + * + * @return the XML string + */ String asXML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminatorImpl.java index 3d4ee4b..70802cd 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequestTerminatorImpl.java @@ -27,11 +27,20 @@ import com.github.prominence.openweathermap.api.model.forecast.Forecast; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; import com.github.prominence.openweathermap.api.utils.RequestUtils; +/** + * The forecast request terminator. + */ public class FiveDayThreeHourStepForecastRequestTerminatorImpl implements FiveDayThreeHourStepForecastRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new forecast request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ FiveDayThreeHourStepForecastRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequester.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequester.java index 9ac7d48..a19211f 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequester.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequester.java @@ -29,17 +29,63 @@ import com.github.prominence.openweathermap.api.model.Coordinate; */ public interface FiveDayThreeHourStepForecastRequester { + /** + * By city name forecast request customizer. + * + * @param cityName the city name + * @return the forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName); + /** + * By city name forecast request customizer. + * + * @param cityName the city name + * @param stateCode the state code + * @return the forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode); + /** + * By city name forecast request customizer. + * + * @param cityName the city name + * @param stateCode the state code + * @param countryCode the country code + * @return the forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer byCityName(String cityName, String stateCode, String countryCode); + /** + * By city id forecast request customizer. + * + * @param cityId the city id + * @return the forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer byCityId(long cityId); + /** + * By coordinate forecast request customizer. + * + * @param coordinate the coordinate + * @return the forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer byCoordinate(Coordinate coordinate); + /** + * By zip code and country forecast request customizer. + * + * @param zipCode the zip code + * @param countryCode the country code + * @return the forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode); + /** + * By zip code in USA forecast request customizer. + * + * @param zipCode the zip code + * @return the forecast request customizer + */ FiveDayThreeHourStepForecastRequestCustomizer byZipCodeInUSA(String zipCode); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequesterImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequesterImpl.java index 863158b..c0479b2 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequesterImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastRequesterImpl.java @@ -25,10 +25,18 @@ package com.github.prominence.openweathermap.api.request.forecast.free; import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; +/** + * The forecast requester. + */ public class FiveDayThreeHourStepForecastRequesterImpl implements FiveDayThreeHourStepForecastRequester { private final RequestUrlBuilder urlBuilder; + /** + * Instantiates a new forecast requester. + * + * @param apiKey the api key + */ public FiveDayThreeHourStepForecastRequesterImpl(String apiKey) { urlBuilder = new RequestUrlBuilder(apiKey); urlBuilder.append("forecast"); diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastResponseMapper.java b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastResponseMapper.java index 2fdbf6c..8bcf504 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastResponseMapper.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastResponseMapper.java @@ -90,10 +90,21 @@ public class FiveDayThreeHourStepForecastResponseMapper { private final UnitSystem unitSystem; + /** + * Instantiates a new forecast response mapper. + * + * @param unitSystem the unit system + */ public FiveDayThreeHourStepForecastResponseMapper(UnitSystem unitSystem) { this.unitSystem = unitSystem; } + /** + * Maps forecast response into java object. + * + * @param json the json string + * @return the forecast + */ public Forecast mapToForecast(String json) { ObjectMapper objectMapper = new ObjectMapper(); Forecast forecast; @@ -151,7 +162,7 @@ public class FiveDayThreeHourStepForecastResponseMapper { private Temperature parseTemperature(JsonNode rootNode) { final double tempValue = rootNode.get("temp").asDouble(); - Temperature temperature = Temperature.forValue(tempValue, unitSystem.getTemperatureUnit()); + Temperature temperature = Temperature.withValue(tempValue, unitSystem.getTemperatureUnit()); final JsonNode tempMaxNode = rootNode.get("temp_max"); if (tempMaxNode != null) { @@ -170,7 +181,7 @@ public class FiveDayThreeHourStepForecastResponseMapper { } private AtmosphericPressure parsePressure(JsonNode rootNode) { - AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(rootNode.get("pressure").asDouble()); + AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(rootNode.get("pressure").asDouble()); final JsonNode seaLevelNode = rootNode.get("sea_level"); final JsonNode groundLevelNode = rootNode.get("grnd_level"); @@ -185,14 +196,14 @@ public class FiveDayThreeHourStepForecastResponseMapper { } private Humidity parseHumidity(JsonNode rootNode) { - return Humidity.forValue((byte) (rootNode.get("humidity").asInt())); + return Humidity.withValue((byte) (rootNode.get("humidity").asInt())); } private Wind parseWind(JsonNode root) { final JsonNode windNode = root.get("wind"); double speed = windNode.get("speed").asDouble(); - Wind wind = Wind.forValue(speed, unitSystem.getWindUnit()); + Wind wind = Wind.withValue(speed, unitSystem.getWindUnit()); final JsonNode degNode = windNode.get("deg"); if (degNode != null) { wind.setDegrees(degNode.asDouble()); @@ -202,34 +213,25 @@ public class FiveDayThreeHourStepForecastResponseMapper { } private Rain parseRain(JsonNode root) { - Rain rain = null; - final JsonNode rainNode = root.get("rain"); if (rainNode != null) { - rain = new Rain(); final JsonNode threeHourNode = rainNode.get("3h"); if (threeHourNode != null) { - rain.setThreeHourRainLevel(threeHourNode.asDouble()); + return Rain.withThreeHourLevelValue(threeHourNode.asDouble()); } } - - return rain; + return null; } private Snow parseSnow(JsonNode root) { - Snow snow = null; - final JsonNode snowNode = root.get("snow"); - if (snowNode != null) { - snow = new Snow(); final JsonNode threeHourNode = snowNode.get("3h"); if (threeHourNode != null) { - snow.setThreeHourSnowLevel(threeHourNode.asDouble()); + Rain.withThreeHourLevelValue(threeHourNode.asDouble()); } } - - return snow; + return null; } private Clouds parseClouds(JsonNode rootNode) { @@ -238,14 +240,14 @@ public class FiveDayThreeHourStepForecastResponseMapper { final JsonNode cloudsNode = rootNode.get("clouds"); final JsonNode allValueNode = cloudsNode.get("all"); if (allValueNode != null) { - clouds = Clouds.forValue((byte) allValueNode.asInt()); + clouds = Clouds.withValue((byte) allValueNode.asInt()); } return clouds; } private Location parseLocation(JsonNode rootNode) { - Location location = Location.forValue(rootNode.get("id").asInt(), rootNode.get("name").asText()); + Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText()); final JsonNode timezoneNode = rootNode.get("timezone"); if (timezoneNode != null) { @@ -283,7 +285,7 @@ public class FiveDayThreeHourStepForecastResponseMapper { JsonNode latitudeNode = rootNode.get("lat"); JsonNode longitudeNode = rootNode.get("lon"); if (latitudeNode != null && longitudeNode != null) { - return Coordinate.forValues(latitudeNode.asDouble(), longitudeNode.asDouble()); + return Coordinate.withValues(latitudeNode.asDouble(), longitudeNode.asDouble()); } return null; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequester.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequester.java index bb4b7e9..9c459d4 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequester.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequester.java @@ -30,7 +30,17 @@ import com.github.prominence.openweathermap.api.request.weather.single.SingleLoc */ public interface CurrentWeatherRequester { + /** + * Single location current weather requester. + * + * @return the single location current weather requester + */ SingleLocationCurrentWeatherRequester single(); + /** + * Multiple locations current weather requester. + * + * @return the multiple locations current weather requester + */ MultipleLocationsCurrentWeatherRequester multiple(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequesterImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequesterImpl.java index 1585573..b3b0811 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequesterImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherRequesterImpl.java @@ -28,10 +28,18 @@ import com.github.prominence.openweathermap.api.request.weather.multiple.Multipl import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequesterImpl; import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequester; +/** + * The type Current weather requester. + */ public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester { private final RequestUrlBuilder urlBuilder; + /** + * Instantiates a new Current weather requester. + * + * @param apiKey the api key + */ public CurrentWeatherRequesterImpl(String apiKey) { urlBuilder = new RequestUrlBuilder(apiKey); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherResponseMapper.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherResponseMapper.java index 6452687..690edc4 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherResponseMapper.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/CurrentWeatherResponseMapper.java @@ -25,7 +25,6 @@ package com.github.prominence.openweathermap.api.request.weather; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.prominence.openweathermap.api.model.weather.*; -import com.github.prominence.openweathermap.api.request.ResponseMapper; import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.model.*; @@ -83,15 +82,25 @@ import java.util.TimeZone; * --- name City name * --- cod Internal parameter */ -public class CurrentWeatherResponseMapper implements ResponseMapper { +public class CurrentWeatherResponseMapper { private final UnitSystem unitSystem; + /** + * Instantiates a new Current weather response mapper. + * + * @param unitSystem the unit system + */ public CurrentWeatherResponseMapper(UnitSystem unitSystem) { this.unitSystem = unitSystem != null ? unitSystem : UnitSystem.STANDARD; } - @Override + /** + * Gets single result. + * + * @param json the json string + * @return the weather object + */ public Weather getSingle(String json) { ObjectMapper objectMapper = new ObjectMapper(); Weather weather; @@ -127,7 +136,12 @@ public class CurrentWeatherResponseMapper implements ResponseMapper { return weather; } - @Override + /** + * Gets list of results. + * + * @param json the json string + * @return the list of weathers + */ public List getList(String json) { ObjectMapper objectMapper = new ObjectMapper(); List weatherList = new ArrayList<>(); @@ -147,7 +161,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper { final JsonNode mainNode = rootNode.get("main"); final double tempValue = mainNode.get("temp").asDouble(); - temperature = Temperature.forValue(tempValue, unitSystem.getTemperatureUnit()); + temperature = Temperature.withValue(tempValue, unitSystem.getTemperatureUnit()); final JsonNode feelsLikeNode = mainNode.get("feels_like"); if (feelsLikeNode != null) { @@ -167,7 +181,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper { private AtmosphericPressure parsePressure(JsonNode rootNode) { final JsonNode mainNode = rootNode.get("main"); - AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(mainNode.get("pressure").asDouble()); + AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(mainNode.get("pressure").asDouble()); final JsonNode seaLevelNode = mainNode.get("sea_level"); final JsonNode groundLevelNode = mainNode.get("grnd_level"); @@ -184,14 +198,14 @@ public class CurrentWeatherResponseMapper implements ResponseMapper { private Humidity parseHumidity(JsonNode rootNode) { final JsonNode mainNode = rootNode.get("main"); - return Humidity.forValue((byte) (mainNode.get("humidity").asInt())); + return Humidity.withValue((byte) (mainNode.get("humidity").asInt())); } private Wind parseWind(JsonNode rootNode) { final JsonNode windNode = rootNode.get("wind"); double speed = windNode.get("speed").asDouble(); - Wind wind = Wind.forValue(speed, unitSystem.getWindUnit()); + Wind wind = Wind.withValue(speed, unitSystem.getWindUnit()); final JsonNode degNode = windNode.get("deg"); if (degNode != null) { @@ -206,42 +220,35 @@ public class CurrentWeatherResponseMapper implements ResponseMapper { } private Rain parseRain(JsonNode rootNode) { - Rain rain = null; - final JsonNode rainNode = rootNode.get("rain"); if (rainNode != null) { - rain = new Rain(); final JsonNode oneHourNode = rainNode.get("1h"); final JsonNode threeHourNode = rainNode.get("3h"); - if (oneHourNode != null) { - rain.setOneHourRainLevel(oneHourNode.asDouble()); - } - if (threeHourNode != null) { - rain.setThreeHourRainLevel(threeHourNode.asDouble()); + if (oneHourNode != null && oneHourNode.isDouble() && threeHourNode != null && threeHourNode.isDouble()) { + return Rain.withValues(oneHourNode.asDouble(), threeHourNode.asDouble()); + } else if (oneHourNode != null && oneHourNode.isDouble()) { + return Rain.withOneHourLevelValue(oneHourNode.asDouble()); + } else if (threeHourNode != null && threeHourNode.isDouble()) { + return Rain.withThreeHourLevelValue(threeHourNode.asDouble()); } } - - return rain; + return null; } private Snow parseSnow(JsonNode rootNode) { - Snow snow = null; - final JsonNode snowNode = rootNode.get("snow"); - if (snowNode != null) { - snow = new Snow(); final JsonNode oneHourNode = snowNode.get("1h"); final JsonNode threeHourNode = snowNode.get("3h"); - if (oneHourNode != null) { - snow.setOneHourSnowLevel(oneHourNode.asDouble()); - } - if (threeHourNode != null) { - snow.setThreeHourSnowLevel(threeHourNode.asDouble()); + if (oneHourNode != null && oneHourNode.isDouble() && threeHourNode != null && threeHourNode.isDouble()) { + return Snow.withValues(oneHourNode.asDouble(), threeHourNode.asDouble()); + } else if (oneHourNode != null && oneHourNode.isDouble()) { + return Snow.withOneHourLevelValue(oneHourNode.asDouble()); + } else if (threeHourNode != null && threeHourNode.isDouble()) { + return Snow.withThreeHourLevelValue(threeHourNode.asDouble()); } } - - return snow; + return null; } private Clouds parseClouds(JsonNode rootNode) { @@ -250,14 +257,14 @@ public class CurrentWeatherResponseMapper implements ResponseMapper { final JsonNode cloudsNode = rootNode.get("clouds"); final JsonNode allValueNode = cloudsNode.get("all"); if (allValueNode != null) { - clouds = Clouds.forValue((byte) allValueNode.asInt()); + clouds = Clouds.withValue((byte) allValueNode.asInt()); } return clouds; } private Location parseLocation(JsonNode rootNode) { - Location location = Location.forValue(rootNode.get("id").asInt(), rootNode.get("name").asText()); + Location location = Location.withValues(rootNode.get("id").asInt(), rootNode.get("name").asText()); final JsonNode timezoneNode = rootNode.get("timezone"); if (timezoneNode != null) { @@ -293,7 +300,7 @@ public class CurrentWeatherResponseMapper implements ResponseMapper { JsonNode latitudeNode = rootNode.get("lat"); JsonNode longitudeNode = rootNode.get("lon"); if (latitudeNode != null && longitudeNode != null) { - return Coordinate.forValues(latitudeNode.asDouble(), longitudeNode.asDouble()); + return Coordinate.withValues(latitudeNode.asDouble(), longitudeNode.asDouble()); } return null; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java index 0796908..291674e 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequester.java @@ -25,12 +25,35 @@ package com.github.prominence.openweathermap.api.request.weather.multiple; import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.model.CoordinateRectangle; +/** + * The interface Multiple locations current weather requester. + */ public interface MultipleLocationsCurrentWeatherRequester { + /** + * By rectangle multiple result current weather request customizer. + * + * @param rectangle the rectangle + * @param zoom the zoom + * @return the multiple result current weather request customizer + */ MultipleResultCurrentWeatherRequestCustomizer byRectangle(CoordinateRectangle rectangle, int zoom); + /** + * By cities in cycle multiple result current weather request customizer. + * + * @param point the point + * @return the multiple result cities in circle current weather request customizer + */ MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point); + /** + * By cities in cycle multiple result current weather request customizer. + * + * @param point the point + * @param citiesCount the cities count + * @return the multiple result cities in circle current weather request customizer + */ MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer byCitiesInCycle(Coordinate point, int citiesCount); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java index d0b085c..6b28095 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleLocationsCurrentWeatherRequesterImpl.java @@ -26,10 +26,18 @@ import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.model.CoordinateRectangle; +/** + * The type Multiple locations current weather requester. + */ public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsCurrentWeatherRequester { private final RequestUrlBuilder urlBuilder; + /** + * Instantiates a new Multiple locations current weather requester. + * + * @param urlBuilder the url builder + */ public MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) { this.urlBuilder = urlBuilder; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator.java index 5ddc02f..31905d1 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator.java @@ -28,6 +28,14 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator; import java.util.List; import java.util.concurrent.CompletableFuture; +/** + * The interface Multiple result current weather async request terminator. + */ public interface MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator, String> { + /** + * XML response format. + * + * @return the completable future + */ CompletableFuture asXML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl.java index fadf1cb..99b120b 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl.java @@ -31,11 +31,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils; import java.util.List; import java.util.concurrent.CompletableFuture; +/** + * The type Multiple result current weather async request terminator. + */ public class MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new Multiple result current weather async request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer.java index 35646d5..b51357e 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer.java @@ -24,9 +24,22 @@ package com.github.prominence.openweathermap.api.request.weather.multiple; import com.github.prominence.openweathermap.api.request.RequestCustomizer; +/** + * The interface Multiple result current weather request customizer. + */ public interface MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer extends RequestCustomizer { + /** + * Retrieve multiple result current weather request terminator. + * + * @return the multiple result current weather request terminator + */ MultipleResultCitiesInCircleCurrentWeatherRequestTerminator retrieve(); + /** + * Retrieve async multiple result current weather async request terminator. + * + * @return the multiple result current weather async request terminator + */ MultipleResultCitiesInCircleCurrentWeatherAsyncRequestTerminator retrieveAsync(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl.java index 10f3939..09935df 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl.java @@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; +/** + * The type Multiple result current weather request customizer. + */ public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestCustomizer { private final RequestUrlBuilder urlBuilder; @@ -33,6 +36,11 @@ public class MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl imp private Language language; private UnitSystem unitSystem = UnitSystem.STANDARD; + /** + * Instantiates a new Multiple result current weather request customizer. + * + * @param urlBuilder the url builder + */ MultipleResultCitiesInCircleCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) { this.urlBuilder = urlBuilder; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminator.java index 37a490f..dcd1905 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminator.java @@ -27,6 +27,14 @@ import com.github.prominence.openweathermap.api.request.RequestTerminator; import java.util.List; +/** + * The interface Multiple result current weather request terminator. + */ public interface MultipleResultCitiesInCircleCurrentWeatherRequestTerminator extends RequestTerminator, String> { + /** + * XML response format. + * + * @return the XML string + */ String asXML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl.java index e2a1c2c..6d22b90 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl.java @@ -30,11 +30,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils; import java.util.List; +/** + * The type Multiple result current weather request terminator. + */ public class MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl implements MultipleResultCitiesInCircleCurrentWeatherRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new Multiple result current weather request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ MultipleResultCitiesInCircleCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java index 4db7c58..6374a96 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminator.java @@ -27,5 +27,8 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator; import java.util.List; +/** + * The interface Multiple result current weather async request terminator. + */ public interface MultipleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator, String> { } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java index 8edabef..876c73a 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherAsyncRequestTerminatorImpl.java @@ -31,11 +31,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils; import java.util.List; import java.util.concurrent.CompletableFuture; +/** + * The type Multiple result current weather async request terminator. + */ public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new Multiple result current weather async request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizer.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizer.java index a5f667d..57f5e06 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizer.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizer.java @@ -24,9 +24,22 @@ package com.github.prominence.openweathermap.api.request.weather.multiple; import com.github.prominence.openweathermap.api.request.RequestCustomizer; +/** + * The interface Multiple result current weather request customizer. + */ public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer { + /** + * Retrieve multiple result current weather request terminator. + * + * @return the multiple result current weather request terminator + */ MultipleResultCurrentWeatherRequestTerminator retrieve(); + /** + * Retrieve async multiple result current weather async request terminator. + * + * @return the multiple result current weather async request terminator + */ MultipleResultCurrentWeatherAsyncRequestTerminator retrieveAsync(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizerImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizerImpl.java index 6661f20..911ae54 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizerImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestCustomizerImpl.java @@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.UnitSystem; +/** + * The type Multiple result current weather request customizer. + */ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer { private final RequestUrlBuilder urlBuilder; @@ -33,6 +36,11 @@ public class MultipleResultCurrentWeatherRequestCustomizerImpl implements Multip private Language language; private UnitSystem unitSystem = UnitSystem.STANDARD; + /** + * Instantiates a new Multiple result current weather request customizer. + * + * @param urlBuilder the url builder + */ MultipleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) { this.urlBuilder = urlBuilder; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java index bab9d52..aa916f6 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminator.java @@ -27,5 +27,8 @@ import com.github.prominence.openweathermap.api.request.RequestTerminator; import java.util.List; +/** + * The interface Multiple result current weather request terminator. + */ public interface MultipleResultCurrentWeatherRequestTerminator extends RequestTerminator, String> { } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java index a225467..dc1e927 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherRequestTerminatorImpl.java @@ -30,11 +30,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils; import java.util.List; +/** + * The type Multiple result current weather request terminator. + */ public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new Multiple result current weather request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java index 5235322..0dc887a 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequester.java @@ -24,19 +24,68 @@ package com.github.prominence.openweathermap.api.request.weather.single; import com.github.prominence.openweathermap.api.model.Coordinate; +/** + * The interface Single location current weather requester. + */ public interface SingleLocationCurrentWeatherRequester { + /** + * By city name current weather request customizer. + * + * @param cityName the city name + * @return the single result current weather request customizer + */ SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName); + /** + * By city name current weather request customizer. + * + * @param cityName the city name + * @param countryCode the country code + * @return the single result current weather request customizer + */ SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String countryCode); + /** + * By city name current weather request customizer. + * + * @param cityName the city name + * @param stateCode the state code + * @param countryCode the country code + * @return the single result current weather request customizer + */ SingleResultCurrentWeatherRequestCustomizer byCityName(String cityName, String stateCode, String countryCode); + /** + * By city id current weather request customizer. + * + * @param cityId the city id + * @return the single result current weather request customizer + */ SingleResultCurrentWeatherRequestCustomizer byCityId(long cityId); + /** + * By coordinate current weather request customizer. + * + * @param coordinate the coordinate + * @return the single result current weather request customizer + */ SingleResultCurrentWeatherRequestCustomizer byCoordinate(Coordinate coordinate); + /** + * By zip code and country current weather request customizer. + * + * @param zipCode the zip code + * @param countryCode the country code + * @return the single result current weather request customizer + */ SingleResultCurrentWeatherRequestCustomizer byZipCodeAndCountry(String zipCode, String countryCode); + /** + * By zip code in usa current weather request customizer. + * + * @param zipCode the zip code + * @return the single result current weather request customizer + */ SingleResultCurrentWeatherRequestCustomizer byZipCodeInUSA(String zipCode); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java index 8331a45..dd452e6 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleLocationCurrentWeatherRequesterImpl.java @@ -25,10 +25,18 @@ package com.github.prominence.openweathermap.api.request.weather.single; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; import com.github.prominence.openweathermap.api.model.Coordinate; +/** + * The type Single location current weather requester. + */ public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationCurrentWeatherRequester { private final RequestUrlBuilder urlBuilder; + /** + * Instantiates a new Single location current weather requester. + * + * @param urlBuilder the url builder + */ public SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) { this.urlBuilder = urlBuilder; urlBuilder.append("weather"); diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java index d9ab9b1..3c4cd61 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminator.java @@ -27,8 +27,21 @@ import com.github.prominence.openweathermap.api.request.AsyncRequestTerminator; import java.util.concurrent.CompletableFuture; +/** + * The current weather async request terminator interface. + */ public interface SingleResultCurrentWeatherAsyncRequestTerminator extends AsyncRequestTerminator { + /** + * XML response format. + * + * @return the completable future + */ CompletableFuture asXML(); + /** + * HTML response format. + * + * @return the completable future + */ CompletableFuture asHTML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminatorImpl.java index de01dc4..439671b 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherAsyncRequestTerminatorImpl.java @@ -30,11 +30,20 @@ import com.github.prominence.openweathermap.api.utils.RequestUtils; import java.util.concurrent.CompletableFuture; +/** + * The type Single result current weather async request terminator. + */ public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new Single result current weather async request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizer.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizer.java index 1faf700..0ce8577 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizer.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizer.java @@ -24,10 +24,23 @@ package com.github.prominence.openweathermap.api.request.weather.single; import com.github.prominence.openweathermap.api.request.RequestCustomizer; +/** + * The current weather request customizer interface. + */ public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer { + /** + * Retrieve current weather request terminator. + * + * @return the single result current weather request terminator + */ SingleResultCurrentWeatherRequestTerminator retrieve(); + /** + * Retrieve current weather async request terminator. + * + * @return the single result current weather async request terminator + */ SingleResultCurrentWeatherAsyncRequestTerminator retrieveAsync(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizerImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizerImpl.java index 66b6912..f8d149e 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizerImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestCustomizerImpl.java @@ -26,6 +26,9 @@ import com.github.prominence.openweathermap.api.request.RequestUrlBuilder; import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.UnitSystem; +/** + * The type Single result current weather request customizer. + */ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer { private final RequestUrlBuilder urlBuilder; @@ -33,6 +36,11 @@ public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleRe private Language language; private UnitSystem unitSystem = UnitSystem.STANDARD; + /** + * Instantiates a new Single result current weather request customizer. + * + * @param urlBuilder the url builder + */ SingleResultCurrentWeatherRequestCustomizerImpl(RequestUrlBuilder urlBuilder) { this.urlBuilder = urlBuilder; } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java index 7f89efc..499091d 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminator.java @@ -25,8 +25,21 @@ package com.github.prominence.openweathermap.api.request.weather.single; import com.github.prominence.openweathermap.api.model.weather.Weather; import com.github.prominence.openweathermap.api.request.RequestTerminator; +/** + * The current weather request terminator interface. + */ public interface SingleResultCurrentWeatherRequestTerminator extends RequestTerminator { + /** + * XML response format. + * + * @return the XML string + */ String asXML(); + /** + * HTML response format. + * + * @return the HTML string + */ String asHTML(); } diff --git a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminatorImpl.java b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminatorImpl.java index 321cc92..76ec882 100644 --- a/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminatorImpl.java +++ b/src/main/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherRequestTerminatorImpl.java @@ -28,11 +28,20 @@ import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.model.weather.Weather; import com.github.prominence.openweathermap.api.utils.RequestUtils; +/** + * The type Single result current weather request terminator. + */ public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator { private final RequestUrlBuilder urlBuilder; private final UnitSystem unitSystem; + /** + * Instantiates a new Single result current weather request terminator. + * + * @param urlBuilder the url builder + * @param unitSystem the unit system + */ SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { this.urlBuilder = urlBuilder; this.unitSystem = unitSystem; diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/AtmosphericPressureUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/AtmosphericPressureUnitTest.java index 4ac386a..c8d98e4 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/AtmosphericPressureUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/AtmosphericPressureUnitTest.java @@ -50,18 +50,18 @@ import org.junit.Test; public class AtmosphericPressureUnitTest { @Test public void whenCreatePressureWithArgs_thenValueIsSet() { - AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(100); + AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(100); Assert.assertEquals(100, atmosphericPressure.getValue(), 0.00001); - Assert.assertEquals(0, AtmosphericPressure.forValue(0).getValue(), 0.00001); - Assert.assertEquals(100, AtmosphericPressure.forValue(100).getValue(), 0.00001); - Assert.assertEquals(55, AtmosphericPressure.forValue(55).getValue(), 0.00001); + Assert.assertEquals(0, AtmosphericPressure.withValue(0).getValue(), 0.00001); + Assert.assertEquals(100, AtmosphericPressure.withValue(100).getValue(), 0.00001); + Assert.assertEquals(55, AtmosphericPressure.withValue(55).getValue(), 0.00001); } @Test public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() { - AtmosphericPressure one = AtmosphericPressure.forValue(22); - AtmosphericPressure two = AtmosphericPressure.forValue(22); + AtmosphericPressure one = AtmosphericPressure.withValue(22); + AtmosphericPressure two = AtmosphericPressure.withValue(22); Assert.assertTrue(one.equals(two)); Assert.assertTrue(one.equals(one)); @@ -80,17 +80,17 @@ public class AtmosphericPressureUnitTest { @Test public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() { - AtmosphericPressure one = AtmosphericPressure.forValue(5); - AtmosphericPressure two = AtmosphericPressure.forValue(88); + AtmosphericPressure one = AtmosphericPressure.withValue(5); + AtmosphericPressure two = AtmosphericPressure.withValue(88); Assert.assertFalse(one.equals(two)); Assert.assertFalse(two.equals(one)); Assert.assertFalse(one.equals(new Object())); Assert.assertNotEquals(one.hashCode(), two.hashCode()); - one = AtmosphericPressure.forValue(44); + one = AtmosphericPressure.withValue(44); one.setSeaLevelValue(44); - two = AtmosphericPressure.forValue(44); + two = AtmosphericPressure.withValue(44); two.setGroundLevelValue(22); Assert.assertFalse(one.equals(two)); @@ -104,7 +104,7 @@ public class AtmosphericPressureUnitTest { @Test public void whenSetValidValues_thenAllIsFine() { - AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(14); + AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(14); atmosphericPressure.setValue(0); atmosphericPressure.setValue(15); atmosphericPressure.setValue(100); @@ -118,31 +118,31 @@ public class AtmosphericPressureUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final String pressureString = AtmosphericPressure.forValue(44).toString(); + final String pressureString = AtmosphericPressure.withValue(44).toString(); Assert.assertNotNull(pressureString); Assert.assertNotEquals("", pressureString); } @Test(expected = IllegalArgumentException.class) public void whenCreatePressureByConstructorWithInvalidDataNegative_thenThrowAnException() { - AtmosphericPressure.forValue(-33); + AtmosphericPressure.withValue(-33); } @Test(expected = IllegalArgumentException.class) public void whenCreatePressureAndSetInvalidDataNegative_thenThrowAnException() { - AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88); + AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88); atmosphericPressure.setValue(-89); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidSeaLevelPressure_thenThrowAnException() { - AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88); + AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88); atmosphericPressure.setSeaLevelValue(-89); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidGroundLevelPressure_thenThrowAnException() { - AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(88); + AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(88); atmosphericPressure.setGroundLevelValue(-223); } } diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/CloudsUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/CloudsUnitTest.java index 3b40e53..caa25dd 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/CloudsUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/CloudsUnitTest.java @@ -50,27 +50,27 @@ import org.junit.Test; public class CloudsUnitTest { @Test public void whenCreateCloudsWithValidArgs_thenValueIsSet() { - Clouds clouds = Clouds.forValue((byte) 100); + Clouds clouds = Clouds.withValue((byte) 100); Assert.assertEquals(100, clouds.getValue()); - Assert.assertEquals(0, Clouds.forValue((byte) 0).getValue()); - Assert.assertEquals(100, Clouds.forValue((byte) 100).getValue()); - Assert.assertEquals(55, Clouds.forValue((byte) 55).getValue()); + Assert.assertEquals(0, Clouds.withValue((byte) 0).getValue()); + Assert.assertEquals(100, Clouds.withValue((byte) 100).getValue()); + Assert.assertEquals(55, Clouds.withValue((byte) 55).getValue()); } @Test(expected = IllegalArgumentException.class) public void whenCreateCloudsByConstructorWithInvalidDataAboveHundred_thenThrowAnException() { - Clouds.forValue((byte) 110); + Clouds.withValue((byte) 110); } @Test(expected = IllegalArgumentException.class) public void whenCreateCloudsByConstructorWithInvalidDataNegative_thenThrowAnException() { - Clouds.forValue((byte) -33); + Clouds.withValue((byte) -33); } @Test public void whenSetValidValues_thenAllIsFine() { - Clouds clouds = Clouds.forValue((byte) 14); + Clouds clouds = Clouds.withValue((byte) 14); clouds.setValue((byte) 0); Assert.assertEquals(0, clouds.getValue()); clouds.setValue((byte) 15); @@ -81,20 +81,20 @@ public class CloudsUnitTest { @Test(expected = IllegalArgumentException.class) public void whenCreateCloudsAndSetInvalidDataAboveHundred_thenThrowAnException() { - Clouds clouds = Clouds.forValue((byte) 12); + Clouds clouds = Clouds.withValue((byte) 12); clouds.setValue((byte) 112); } @Test(expected = IllegalArgumentException.class) public void whenCreateCloudsAndSetInvalidDataNegative_thenThrowAnException() { - Clouds clouds = Clouds.forValue((byte) 88); + Clouds clouds = Clouds.withValue((byte) 88); clouds.setValue((byte) -89); } @Test public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() { - Clouds one = Clouds.forValue((byte) 22); - Clouds two = Clouds.forValue((byte) 22); + Clouds one = Clouds.withValue((byte) 22); + Clouds two = Clouds.withValue((byte) 22); Assert.assertTrue(one.equals(two)); Assert.assertTrue(one.equals(one)); @@ -103,8 +103,8 @@ public class CloudsUnitTest { @Test public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() { - Clouds one = Clouds.forValue((byte) 5); - Clouds two = Clouds.forValue((byte) 88); + Clouds one = Clouds.withValue((byte) 5); + Clouds two = Clouds.withValue((byte) 88); Assert.assertFalse(one.equals(two)); Assert.assertFalse(two.equals(one)); @@ -114,7 +114,7 @@ public class CloudsUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final String cloudsString = Clouds.forValue((byte) 44).toString(); + final String cloudsString = Clouds.withValue((byte) 44).toString(); Assert.assertNotNull(cloudsString); Assert.assertNotEquals("", cloudsString); } diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateRectangleUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateRectangleUnitTest.java index cad64e5..68339c9 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateRectangleUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateRectangleUnitTest.java @@ -20,28 +20,6 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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 org.junit.Assert; @@ -50,52 +28,93 @@ import org.junit.Test; public class CoordinateRectangleUnitTest { @Test public void whenCreateObjectWithValidArgs_thenObjectIsCreated() { - CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2); + CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLatitudeBottomBelowMinus90_thenThrowAnException() { - CoordinateRectangle.forValues(44.5, -91.2, 54.4, 22.2); + CoordinateRectangle.withValues(44.5, -91.2, 54.4, 22.2); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLatitudeBottomAbove90_thenThrowAnException() { - CoordinateRectangle.forValues(44.5, 91.2, 54.4, 22.2); + CoordinateRectangle.withValues(44.5, 91.2, 54.4, 22.2); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLatitudeTopBelowMinus90_thenThrowAnException() { - CoordinateRectangle.forValues(44.5, 22.4, 54.4, -92.3); + CoordinateRectangle.withValues(44.5, 22.4, 54.4, -92.3); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLatitudeTopAbove90_thenThrowAnException() { - CoordinateRectangle.forValues(44.5, 22.5, 54.4, 94.887); + CoordinateRectangle.withValues(44.5, 22.5, 54.4, 94.887); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLongitudeLeftBelowMinus180_thenThrowAnException() { - CoordinateRectangle.forValues(-944.5, 22.4, 54.4, 22.2); + CoordinateRectangle.withValues(-944.5, 22.4, 54.4, 22.2); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLongitudeLeftAbove180_thenThrowAnException() { - CoordinateRectangle.forValues(544.5, 22.4, 54.4, 22.2); + CoordinateRectangle.withValues(544.5, 22.4, 54.4, 22.2); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLongitudeRightBelowMinus180_thenThrowAnException() { - CoordinateRectangle.forValues(44.5, 22.4, -254.4, 22.2); + CoordinateRectangle.withValues(44.5, 22.4, -254.4, 22.2); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithLongitudeRightAbove180_thenThrowAnException() { - CoordinateRectangle.forValues(44.5, 22.4, 354.4, 22.2); + CoordinateRectangle.withValues(44.5, 22.4, 354.4, 22.2); + } + + @Test(expected = IllegalArgumentException.class) + public void whenCreateObjectUsingBuilderWithInvalidLatitudeBottom_thenFail() { + new CoordinateRectangle.Builder() + .setLatitudeBottom(-1000); + } + + @Test(expected = IllegalArgumentException.class) + public void whenCreateObjectUsingBuilderWithInvalidLatitudeTop_thenFail() { + new CoordinateRectangle.Builder() + .setLatitudeTop(-1000); + } + + @Test(expected = IllegalArgumentException.class) + public void whenCreateObjectUsingBuilderWithInvalidLongitudeLeft_thenFail() { + new CoordinateRectangle.Builder() + .setLongitudeLeft(-1000); + } + + @Test(expected = IllegalArgumentException.class) + public void whenCreateObjectUsingBuilderWithInvalidLongitudeRight_thenFail() { + new CoordinateRectangle.Builder() + .setLongitudeRight(-1000); + } + + @Test(expected = IllegalStateException.class) + public void whenCreateObjectUsingBuilderWithoutAllPropertiesSet_thenFail() { + new CoordinateRectangle.Builder() + .setLongitudeRight(10) + .build(); + } + + @Test + public void whenCreateObjectUsingBuilderWithCorrectUsage_thenOk() { + new CoordinateRectangle.Builder() + .setLongitudeRight(10) + .setLongitudeLeft(10) + .setLatitudeTop(10) + .setLatitudeBottom(10) + .build(); } @Test public void whenGetAllParameters_thenAllIsFine() { - final CoordinateRectangle rectangle = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2); + final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2); Assert.assertEquals(44.5, rectangle.getLongitudeLeft(), 0.00001); Assert.assertEquals(22.4, rectangle.getLatitudeBottom(), 0.00001); Assert.assertEquals(54.4, rectangle.getLongitudeRight(), 0.00001); @@ -104,7 +123,7 @@ public class CoordinateRectangleUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final CoordinateRectangle rectangle = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2); + final CoordinateRectangle rectangle = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2); Assert.assertNotNull(rectangle.toString()); Assert.assertNotEquals("", rectangle.toString()); @@ -112,12 +131,12 @@ public class CoordinateRectangleUnitTest { @Test public void whenCallHashCode_thenAllIsFine() { - final CoordinateRectangle first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2); - final CoordinateRectangle second = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2); + final CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2); + final CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2); Assert.assertEquals(first.hashCode(), second.hashCode()); - final CoordinateRectangle third = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 23.566); + final CoordinateRectangle third = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 23.566); Assert.assertNotEquals(first.hashCode(), third.hashCode()); Assert.assertNotEquals(second.hashCode(), third.hashCode()); @@ -125,26 +144,26 @@ public class CoordinateRectangleUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - CoordinateRectangle first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2); - CoordinateRectangle second = CoordinateRectangle.forValues(44.5, 22.4, 54.4, 22.2); + CoordinateRectangle first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2); + CoordinateRectangle second = CoordinateRectangle.withValues(44.5, 22.4, 54.4, 22.2); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); Assert.assertFalse(first.equals(new Object())); - first = CoordinateRectangle.forValues(49.5, 22.4, 54.4, 22.2); + first = CoordinateRectangle.withValues(49.5, 22.4, 54.4, 22.2); Assert.assertFalse(first.equals(second)); - first = CoordinateRectangle.forValues(44.5, 29.4, 54.4, 22.2); + first = CoordinateRectangle.withValues(44.5, 29.4, 54.4, 22.2); Assert.assertFalse(first.equals(second)); - first = CoordinateRectangle.forValues(44.5, 22.4, 24.4, 22.2); + first = CoordinateRectangle.withValues(44.5, 22.4, 24.4, 22.2); Assert.assertFalse(first.equals(second)); - first = CoordinateRectangle.forValues(44.5, 22.4, 54.4, -2.2); + first = CoordinateRectangle.withValues(44.5, 22.4, 54.4, -2.2); Assert.assertFalse(first.equals(second)); } diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateUnitTest.java index 91c8cc5..8482ce1 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/CoordinateUnitTest.java @@ -20,28 +20,6 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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 org.junit.Assert; @@ -50,32 +28,32 @@ import org.junit.Test; public class CoordinateUnitTest { @Test public void whenCreateCoordinateWithValidValues_thenObjectCreated() { - Coordinate.forValues(44, 53); + Coordinate.withValues(44, 53); } @Test(expected = IllegalArgumentException.class) public void whenCreateCoordinateWithInvalidLatitudeBelowMinus90_thenThrowAnException() { - Coordinate.forValues(-333, 44); + Coordinate.withValues(-333, 44); } @Test(expected = IllegalArgumentException.class) public void whenCreateCoordinateWithInvalidLatitudeAbove90_thenThrowAnException() { - Coordinate.forValues(223, 44); + Coordinate.withValues(223, 44); } @Test(expected = IllegalArgumentException.class) public void whenCreateCoordinateWithInvalidLongitudeBelowMinus180_thenThrowAnException() { - Coordinate.forValues(33, -999); + Coordinate.withValues(33, -999); } @Test(expected = IllegalArgumentException.class) public void whenCreateCoordinateWithInvalidLongitudeAbove180_thenThrowAnException() { - Coordinate.forValues(33, 999); + Coordinate.withValues(33, 999); } @Test public void whenSetValidCoordinates_thenAllIsFine() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); coordinate.setLatitude(-90); Assert.assertEquals(-90, coordinate.getLatitude(), 0.00001); @@ -94,31 +72,31 @@ public class CoordinateUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetInvalidLatitudeBelowMinus90_thenThrowAnException() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); coordinate.setLatitude(-91); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidLatitudeAbove90_thenThrowAnException() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); coordinate.setLatitude(92); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidLongitudeBelowMinus180_thenThrowAnException() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); coordinate.setLongitude(-194); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidLongitudeAbove180_thenThrowAnException() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); coordinate.setLongitude(444); } @Test public void whenGetLatitude_thenAllIsFine() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); Assert.assertEquals(0, coordinate.getLatitude(), 0.00001); coordinate.setLatitude(45); @@ -128,7 +106,7 @@ public class CoordinateUnitTest { @Test public void whenGetLongitude_thenAllIsFine() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); Assert.assertEquals(0, coordinate.getLongitude(), 0.00001); coordinate.setLongitude(33); @@ -138,15 +116,15 @@ public class CoordinateUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final Coordinate coordinate = Coordinate.forValues(0, 0); + final Coordinate coordinate = Coordinate.withValues(0, 0); Assert.assertNotNull(coordinate.toString()); Assert.assertNotEquals("", coordinate.toString()); } @Test public void whenCallHashCode_thenAllIsFine() { - final Coordinate first = Coordinate.forValues(22, 66); - final Coordinate second = Coordinate.forValues(22, 44); + final Coordinate first = Coordinate.withValues(22, 66); + final Coordinate second = Coordinate.withValues(22, 44); Assert.assertNotEquals(first.hashCode(), second.hashCode()); @@ -165,8 +143,8 @@ public class CoordinateUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Coordinate first = Coordinate.forValues(11, 99); - final Coordinate second = Coordinate.forValues(11, 99); + final Coordinate first = Coordinate.withValues(11, 99); + final Coordinate second = Coordinate.withValues(11, 99); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/HumidityUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/HumidityUnitTest.java index 67b4e6a..7d3d490 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/HumidityUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/HumidityUnitTest.java @@ -20,28 +20,6 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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 org.junit.Assert; @@ -50,26 +28,26 @@ import org.junit.Test; public class HumidityUnitTest { @Test public void whenCreateHumidityWithArgs_thenValueIsSet() { - Humidity humidity = Humidity.forValue((byte) 100); + Humidity humidity = Humidity.withValue((byte) 100); Assert.assertEquals(100, humidity.getValue()); - Assert.assertEquals(0, Humidity.forValue((byte) 0).getValue()); - Assert.assertEquals(55, Humidity.forValue((byte) 55).getValue()); + Assert.assertEquals(0, Humidity.withValue((byte) 0).getValue()); + Assert.assertEquals(55, Humidity.withValue((byte) 55).getValue()); } @Test(expected = IllegalArgumentException.class) public void whenCreateHumidityByConstructorWithInvalidDataAboveHundred_thenThrowAnException() { - Humidity.forValue((byte) 112); + Humidity.withValue((byte) 112); } @Test(expected = IllegalArgumentException.class) public void whenCreateHumidityByConstructorWithInvalidDataNegative_thenThrowAnException() { - Humidity.forValue((byte) -33); + Humidity.withValue((byte) -33); } @Test public void whenSetValidValues_thenAllIsFine() { - Humidity humidity = Humidity.forValue((byte) 14); + Humidity humidity = Humidity.withValue((byte) 14); Assert.assertEquals(14, humidity.getValue()); humidity.setValue((byte) 0); Assert.assertEquals(0, humidity.getValue()); @@ -81,20 +59,20 @@ public class HumidityUnitTest { @Test(expected = IllegalArgumentException.class) public void whenCreateHumidityAndSetInvalidDataAboveHundred_thenThrowAnException() { - Humidity humidity = Humidity.forValue((byte) 12); + Humidity humidity = Humidity.withValue((byte) 12); humidity.setValue((byte) 112); } @Test(expected = IllegalArgumentException.class) public void whenCreateHumidityAndSetInvalidDataNegative_thenThrowAnException() { - Humidity humidity = Humidity.forValue((byte) 88); + Humidity humidity = Humidity.withValue((byte) 88); humidity.setValue((byte) -89); } @Test public void whenCreateTwoIdenticalInstances_thenWheyAreEquals() { - Humidity one = Humidity.forValue((byte) 22); - Humidity two = Humidity.forValue((byte) 22); + Humidity one = Humidity.withValue((byte) 22); + Humidity two = Humidity.withValue((byte) 22); Assert.assertTrue(one.equals(two)); Assert.assertTrue(one.equals(one)); @@ -103,8 +81,8 @@ public class HumidityUnitTest { @Test public void whenCreateTwoDifferentInstances_thenWheyAreNotEquals() { - Humidity one = Humidity.forValue((byte) 5); - Humidity two = Humidity.forValue((byte) 88); + Humidity one = Humidity.withValue((byte) 5); + Humidity two = Humidity.withValue((byte) 88); Assert.assertFalse(one.equals(two)); Assert.assertFalse(two.equals(one)); @@ -114,7 +92,7 @@ public class HumidityUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final String humidityString = Humidity.forValue((byte) 44).toString(); + final String humidityString = Humidity.withValue((byte) 44).toString(); Assert.assertNotNull(humidityString); Assert.assertNotEquals("", humidityString); } diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/TemperatureUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/TemperatureUnitTest.java index 241a783..aee2034 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/TemperatureUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/TemperatureUnitTest.java @@ -20,28 +20,6 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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 org.junit.Assert; @@ -50,17 +28,17 @@ import org.junit.Test; public class TemperatureUnitTest { @Test public void whenCreateObjectWithValidArgs_thenObjectIsCreated() { - Temperature.forValue(22.2, "K"); + Temperature.withValue(22.2, "K"); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithEmptyUnit_thenThrowAnException() { - Temperature.forValue(22.2, null); + Temperature.withValue(22.2, null); } @Test public void whenSetValue_thenAllIsFine() { - final Temperature temperature = Temperature.forValue(22.2, "K"); + final Temperature temperature = Temperature.withValue(22.2, "K"); temperature.setValue(55.44); Assert.assertEquals(55.44, temperature.getValue(), 0.00001); @@ -68,7 +46,7 @@ public class TemperatureUnitTest { @Test public void whenSetMaximumTemperature_thenAllIsOk() { - final Temperature temperature = Temperature.forValue(22.2, "K"); + final Temperature temperature = Temperature.withValue(22.2, "K"); temperature.setMaxTemperature(44.4); Assert.assertEquals(44.4, temperature.getMaxTemperature(), 0.00001); @@ -80,7 +58,7 @@ public class TemperatureUnitTest { @Test public void whenSetMinimumTemperature_thenAllIsOk() { - final Temperature temperature = Temperature.forValue(22.2, "K"); + final Temperature temperature = Temperature.withValue(22.2, "K"); temperature.setMinTemperature(33.2); Assert.assertEquals(33.2, temperature.getMinTemperature(), 0.00001); @@ -92,7 +70,7 @@ public class TemperatureUnitTest { @Test public void whenSetFeelsLikeTemperature_thenAllIsOk() { - final Temperature temperature = Temperature.forValue(22.2, "K"); + final Temperature temperature = Temperature.withValue(22.2, "K"); temperature.setFeelsLike(22.3); Assert.assertEquals(22.3, temperature.getFeelsLike(), 0.00001); @@ -104,7 +82,7 @@ public class TemperatureUnitTest { @Test public void whenSetNonNullUnit_thenAllIsOk() { - final Temperature temperature = Temperature.forValue(22.2, "K"); + final Temperature temperature = Temperature.withValue(22.2, "K"); temperature.setUnit("test"); Assert.assertTrue("test".equals(temperature.getUnit())); @@ -112,14 +90,14 @@ public class TemperatureUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetNullUnit_thenThrowAnException() { - final Temperature temperature = Temperature.forValue(22.2, "K"); + final Temperature temperature = Temperature.withValue(22.2, "K"); temperature.setUnit(null); } @Test public void whenCallToString_thenAllIsFine() { - final Temperature temperature = Temperature.forValue(22.2, "K"); + final Temperature temperature = Temperature.withValue(22.2, "K"); Assert.assertNotNull(temperature.toString()); Assert.assertNotEquals("", temperature.toString()); @@ -142,16 +120,16 @@ public class TemperatureUnitTest { @Test public void whenCallHashCode_thenAllIsFine() { - final Temperature one = Temperature.forValue(22.2, "K"); - final Temperature two = Temperature.forValue(22.2, "K"); + final Temperature one = Temperature.withValue(22.2, "K"); + final Temperature two = Temperature.withValue(22.2, "K"); Assert.assertEquals(one.hashCode(), two.hashCode()); } @Test public void whenCheckEquality_thenAllIsFine() { - final Temperature one = Temperature.forValue(22.2, "K"); - final Temperature two = Temperature.forValue(21.2, "K"); + final Temperature one = Temperature.withValue(22.2, "K"); + final Temperature two = Temperature.withValue(21.2, "K"); Assert.assertTrue(one.equals(one)); Assert.assertFalse(one.equals(new Object())); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/ForecastUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/ForecastUnitTest.java index 161a704..dd360b1 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/ForecastUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/ForecastUnitTest.java @@ -31,7 +31,7 @@ public class ForecastUnitTest { @Test public void whenLocationIsSet_thenAllIsOk() { final Forecast forecast = new Forecast(); - forecast.setLocation(Location.forValue(2, "asd")); + forecast.setLocation(Location.withValues(2, "asd")); Assert.assertNotNull(forecast.getLocation()); } @@ -51,7 +51,7 @@ public class ForecastUnitTest { Assert.assertEquals(one.hashCode(), two.hashCode()); - one.setLocation(Location.forValue(22, "444")); + one.setLocation(Location.withValues(22, "444")); Assert.assertNotEquals(one.hashCode(), two.hashCode()); } @@ -66,7 +66,7 @@ public class ForecastUnitTest { Assert.assertTrue(one.equals(two)); Assert.assertFalse(one.equals(new Object())); - one.setLocation(Location.forValue(22, "234")); + one.setLocation(Location.withValues(22, "234")); Assert.assertFalse(one.equals(two)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/LocationUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/LocationUnitTest.java index d36df61..3aba580 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/LocationUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/LocationUnitTest.java @@ -32,17 +32,17 @@ import java.time.ZoneOffset; public class LocationUnitTest { @Test public void whenCreateObjectWithValidArgs_thenObjectIsCreated() { - Location.forValue(33, "test"); + Location.withValues(33, "test"); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithoutName_thenThrowAnException() { - Location.forValue(33, null); + Location.withValues(33, null); } @Test public void whenSetId_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); location.setId(55); Assert.assertEquals(55, location.getId()); @@ -50,7 +50,7 @@ public class LocationUnitTest { @Test public void whenSetName_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); location.setName("city"); Assert.assertEquals("city", location.getName()); @@ -58,7 +58,7 @@ public class LocationUnitTest { @Test public void whenSetCountryCode_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); location.setCountryCode("by"); Assert.assertEquals("by", location.getCountryCode()); @@ -66,7 +66,7 @@ public class LocationUnitTest { @Test public void whenSetSunrise_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); final LocalDateTime now = LocalDateTime.now(); location.setSunrise(now); @@ -75,7 +75,7 @@ public class LocationUnitTest { @Test public void whenSetSunset_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); final LocalDateTime now = LocalDateTime.now(); location.setSunset(now); @@ -84,7 +84,7 @@ public class LocationUnitTest { @Test public void whenSetZoneOffset_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); final ZoneOffset offset = ZoneOffset.UTC; location.setZoneOffset(offset); @@ -93,8 +93,8 @@ public class LocationUnitTest { @Test public void whenSetCoordinate_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); - final Coordinate coordinate = Coordinate.forValues(33.2, 64.2); + final Location location = Location.withValues(33, "test"); + final Coordinate coordinate = Coordinate.withValues(33.2, 64.2); location.setCoordinate(coordinate); Assert.assertEquals(coordinate, location.getCoordinate()); @@ -102,7 +102,7 @@ public class LocationUnitTest { @Test public void whenSetPopulation_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); location.setPopulation(3444L); Assert.assertEquals(3444L, location.getPopulation().longValue()); @@ -110,11 +110,11 @@ public class LocationUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final Location location = Location.forValue(44, "test"); + final Location location = Location.withValues(44, "test"); Assert.assertNotEquals("", location.toString()); - location.setCoordinate(Coordinate.forValues(33.2, 56.3)); + location.setCoordinate(Coordinate.withValues(33.2, 56.3)); Assert.assertNotEquals("", location.toString()); @@ -130,8 +130,8 @@ public class LocationUnitTest { @Test public void whenCallHashCode_thenAllIsFine() { - final Location one = Location.forValue(44, "test"); - final Location two = Location.forValue(44, "test"); + final Location one = Location.withValues(44, "test"); + final Location two = Location.withValues(44, "test"); Assert.assertEquals(one.hashCode(), two.hashCode()); @@ -142,8 +142,8 @@ public class LocationUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Location one = Location.forValue(44, "test"); - final Location two = Location.forValue(44, "test"); + final Location one = Location.withValues(44, "test"); + final Location two = Location.withValues(44, "test"); Assert.assertTrue(one.equals(one)); Assert.assertFalse(one.equals(new Object())); @@ -200,7 +200,7 @@ public class LocationUnitTest { Assert.assertTrue(one.equals(two)); - final Coordinate coordinate = Coordinate.forValues(33.5, -22.4); + final Coordinate coordinate = Coordinate.withValues(33.5, -22.4); one.setCoordinate(coordinate); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/RainUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/RainUnitTest.java index 4f47afd..3105dd1 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/RainUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/RainUnitTest.java @@ -28,42 +28,44 @@ import org.junit.Test; public class RainUnitTest { @Test public void whenCreateRainWithValidArgs_thenObjectIsCreated() { - new Rain(2222.3); - new Rain(null); + Rain.withThreeHourLevelValue(2222.3); + Rain.withThreeHourLevelValue(0); + } + + @Test(expected = IllegalArgumentException.class) + public void whenCreateWithInvalidData_thenFail() { + Rain.withThreeHourLevelValue(-20); } @Test public void whenSetValues_thenTheyAreSet() { - final Rain rain = new Rain(null); + final Rain rain = Rain.withThreeHourLevelValue(0); - Assert.assertNull(rain.getThreeHourRainLevel()); + Assert.assertEquals(0, rain.getThreeHourRainLevel(), 0.00001); rain.setThreeHourRainLevel(55.5); Assert.assertEquals(55.5, rain.getThreeHourRainLevel(), 0.00001); } + @Test(expected = IllegalArgumentException.class) + public void whenSetInvalidValue_thenFail() { + final Rain rain = Rain.withThreeHourLevelValue(0); + + rain.setThreeHourRainLevel(-20); + } + @Test public void whenCallToString_thenAllIsFine() { - final Rain rain = new Rain(); + final Rain rain = Rain.withThreeHourLevelValue(33.5); Assert.assertNotNull(rain.toString()); - Assert.assertEquals("unknown", rain.toString()); - - rain.setThreeHourRainLevel(33.5); - - Assert.assertNotNull(rain.toString()); - Assert.assertNotEquals("unknown", rain.toString()); - - rain.setThreeHourRainLevel(null); - - Assert.assertNotNull(rain.toString()); - Assert.assertEquals("unknown", rain.toString()); + Assert.assertNotEquals("", rain.toString()); } @Test public void whenCallHashCode_thenAllIsFine() { - final Rain first = new Rain(); - final Rain second = new Rain(); + final Rain first = Rain.withThreeHourLevelValue(0); + final Rain second = Rain.withThreeHourLevelValue(0); Assert.assertEquals(first.hashCode(), second.hashCode()); @@ -78,8 +80,8 @@ public class RainUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Rain first = new Rain(); - final Rain second = new Rain(); + final Rain first = Rain.withThreeHourLevelValue(0); + final Rain second = Rain.withThreeHourLevelValue(0); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/SnowUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/SnowUnitTest.java index a783687..6b5bf8d 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/SnowUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/SnowUnitTest.java @@ -28,42 +28,43 @@ import org.junit.Test; public class SnowUnitTest { @Test public void whenCreateSnowWithValidArgs_ObjectIsCreated() { - new Snow(2222.3); - new Snow(null); + Snow.withThreeHourLevelValue(2222.3); + Snow.withThreeHourLevelValue(0); + } + @Test(expected = IllegalArgumentException.class) + public void whenCreateWithInvalidData_thenFail() { + Snow.withThreeHourLevelValue(-20); } @Test public void whenSetValues_thenTheyAreSet() { - final Snow snow = new Snow(null); + final Snow snow = Snow.withThreeHourLevelValue(0); - Assert.assertNull(snow.getThreeHourSnowLevel()); + Assert.assertEquals(0, snow.getThreeHourSnowLevel(), 0.00001); snow.setThreeHourSnowLevel(55.5); Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001); } + @Test(expected = IllegalArgumentException.class) + public void whenSetInvalidValue_thenFail() { + final Snow snow = Snow.withThreeHourLevelValue(0); + + snow.setThreeHourSnowLevel(-20); + } + @Test public void whenCallToString_thenAllIsFine() { - final Snow snow = new Snow(); + final Snow snow = Snow.withThreeHourLevelValue(33.5); Assert.assertNotNull(snow.toString()); - Assert.assertEquals("unknown", snow.toString()); - - snow.setThreeHourSnowLevel(33.5); - - Assert.assertNotNull(snow.toString()); - Assert.assertNotEquals("unknown", snow.toString()); - - snow.setThreeHourSnowLevel(null); - - Assert.assertNotNull(snow.toString()); - Assert.assertEquals("unknown", snow.toString()); + Assert.assertNotEquals("", snow.toString()); } @Test public void whenCallHashCode_thenAllIsFine() { - final Snow first = new Snow(); - final Snow second = new Snow(); + final Snow first = Snow.withThreeHourLevelValue(0); + final Snow second = Snow.withThreeHourLevelValue(0); Assert.assertEquals(first.hashCode(), second.hashCode()); @@ -78,8 +79,8 @@ public class SnowUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Snow first = new Snow(); - final Snow second = new Snow(); + final Snow first = Snow.withThreeHourLevelValue(0); + final Snow second = Snow.withThreeHourLevelValue(0); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecastUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecastUnitTest.java index e589849..0204f5c 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecastUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WeatherForecastUnitTest.java @@ -20,28 +20,6 @@ * SOFTWARE. */ -/* - * Copyright (c) 2021 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.forecast; import com.github.prominence.openweathermap.api.model.*; @@ -114,7 +92,7 @@ public class WeatherForecastUnitTest { @Test public void whenSetTemperature_thenValueIsSet() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final Temperature temperature = Temperature.forValue(22.3, "a"); + final Temperature temperature = Temperature.withValue(22.3, "a"); weatherForecast.setTemperature(temperature); Assert.assertEquals(temperature, weatherForecast.getTemperature()); @@ -123,7 +101,7 @@ public class WeatherForecastUnitTest { @Test public void whenSetPressure_thenValueIsSet() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.2); + final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2); weatherForecast.setAtmosphericPressure(atmosphericPressure); Assert.assertEquals(atmosphericPressure, weatherForecast.getAtmosphericPressure()); @@ -132,7 +110,7 @@ public class WeatherForecastUnitTest { @Test public void whenSetHumidity_thenValueIsSet() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final Humidity humidity = Humidity.forValue((byte) 44); + final Humidity humidity = Humidity.withValue((byte) 44); weatherForecast.setHumidity(humidity); Assert.assertEquals(humidity, weatherForecast.getHumidity()); @@ -141,7 +119,7 @@ public class WeatherForecastUnitTest { @Test public void whenSetWind_thenValueIsSet() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final Wind wind = Wind.forValue(22.2, "a"); + final Wind wind = Wind.withValue(22.2, "a"); weatherForecast.setWind(wind); Assert.assertEquals(wind, weatherForecast.getWind()); @@ -150,7 +128,7 @@ public class WeatherForecastUnitTest { @Test public void whenSetRain_thenValueIsSet() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final Rain rain = new Rain(); + final Rain rain = Rain.withThreeHourLevelValue(0); weatherForecast.setRain(rain); Assert.assertEquals(rain, weatherForecast.getRain()); @@ -159,7 +137,7 @@ public class WeatherForecastUnitTest { @Test public void whenSetSnow_thenValueIsSet() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final Snow snow = new Snow(); + final Snow snow = Snow.withThreeHourLevelValue(0); weatherForecast.setSnow(snow); Assert.assertEquals(snow, weatherForecast.getSnow()); @@ -168,7 +146,7 @@ public class WeatherForecastUnitTest { @Test public void whenSetClouds_thenValueIsSet() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final Clouds clouds = Clouds.forValue((byte) 33); + final Clouds clouds = Clouds.withValue((byte) 33); weatherForecast.setClouds(clouds); Assert.assertEquals(clouds, weatherForecast.getClouds()); @@ -199,12 +177,12 @@ public class WeatherForecastUnitTest { @Test public void whenCallToString_thenAllIsFine() { final WeatherForecast weatherForecast = WeatherForecast.forValue("state", "desc"); - final Location location = Location.forValue(12312, "asd"); - final Temperature temperature = Temperature.forValue(33.2, "asd"); - final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(44.4); - final Clouds clouds = Clouds.forValue((byte) 55); - final Rain rain = new Rain(33.2); - final Snow snow = new Snow(33.1); + final Location location = Location.withValues(12312, "asd"); + final Temperature temperature = Temperature.withValue(33.2, "asd"); + final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4); + final Clouds clouds = Clouds.withValue((byte) 55); + final Rain rain = Rain.withThreeHourLevelValue(33.2); + final Snow snow = Snow.withThreeHourLevelValue(33.1); Assert.assertNotEquals("", weatherForecast.toString()); Assert.assertNotNull(weatherForecast.toString()); @@ -241,11 +219,11 @@ public class WeatherForecastUnitTest { Assert.assertNotEquals("", weatherForecast.toString()); Assert.assertNotNull(weatherForecast.toString()); - weatherForecast.setRain(new Rain(null)); + weatherForecast.setRain(Rain.withThreeHourLevelValue(0)); Assert.assertNotEquals("", weatherForecast.toString()); Assert.assertNotNull(weatherForecast.toString()); - weatherForecast.setSnow(new Snow(null)); + weatherForecast.setSnow(Snow.withThreeHourLevelValue(0)); Assert.assertNotEquals("", weatherForecast.toString()); Assert.assertNotNull(weatherForecast.toString()); } @@ -297,7 +275,7 @@ public class WeatherForecastUnitTest { Assert.assertTrue(one.equals(two)); - final Temperature temperature = Temperature.forValue(33.2, "as"); + final Temperature temperature = Temperature.withValue(33.2, "as"); one.setTemperature(temperature); Assert.assertFalse(one.equals(two)); @@ -306,7 +284,7 @@ public class WeatherForecastUnitTest { Assert.assertTrue(one.equals(two)); - final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.33); + final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33); one.setAtmosphericPressure(atmosphericPressure); Assert.assertFalse(one.equals(two)); @@ -315,7 +293,7 @@ public class WeatherForecastUnitTest { Assert.assertTrue(one.equals(two)); - final Humidity humidity = Humidity.forValue((byte) 33); + final Humidity humidity = Humidity.withValue((byte) 33); one.setHumidity(humidity); Assert.assertFalse(one.equals(two)); @@ -324,7 +302,7 @@ public class WeatherForecastUnitTest { Assert.assertTrue(one.equals(two)); - final Wind wind = Wind.forValue(33.6, "asd"); + final Wind wind = Wind.withValue(33.6, "asd"); one.setWind(wind); Assert.assertFalse(one.equals(two)); @@ -333,7 +311,7 @@ public class WeatherForecastUnitTest { Assert.assertTrue(one.equals(two)); - final Rain rain = new Rain(); + final Rain rain = Rain.withThreeHourLevelValue(0); one.setRain(rain); Assert.assertFalse(one.equals(two)); @@ -342,7 +320,7 @@ public class WeatherForecastUnitTest { Assert.assertTrue(one.equals(two)); - final Snow snow = new Snow(); + final Snow snow = Snow.withThreeHourLevelValue(0); one.setSnow(snow); Assert.assertFalse(one.equals(two)); @@ -351,7 +329,7 @@ public class WeatherForecastUnitTest { Assert.assertTrue(one.equals(two)); - final Clouds clouds = Clouds.forValue((byte) 33); + final Clouds clouds = Clouds.withValue((byte) 33); one.setClouds(clouds); Assert.assertFalse(one.equals(two)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WindUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WindUnitTest.java index f77a2f1..41697c4 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WindUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/forecast/WindUnitTest.java @@ -28,22 +28,22 @@ import org.junit.Test; public class WindUnitTest { @Test public void whenCreateWindWithValidArgs_thenValueIsSet() { - Assert.assertEquals(44.0, Wind.forValue(44, "ms").getSpeed(), 0.00001); + Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001); } @Test(expected = IllegalArgumentException.class) public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() { - Wind.forValue(-21, "a"); + Wind.withValue(-21, "a"); } @Test(expected = IllegalArgumentException.class) public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() { - Wind.forValue(342, null); + Wind.withValue(342, null); } @Test public void whenSetValidSpeed_thenValueIsSet() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertEquals(33, wind.getSpeed(), 0.00001); @@ -58,7 +58,7 @@ public class WindUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetInvalidSpeedBelow0_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertEquals(33, wind.getSpeed(), 0.00001); @@ -67,7 +67,7 @@ public class WindUnitTest { @Test public void whenSetValidDegrees_thenValueIsSet() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertNull(wind.getDegrees()); @@ -86,19 +86,19 @@ public class WindUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetInvalidDegreesBelow0_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setDegrees(-32); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidDegreesAbove360_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setDegrees(378); } @Test public void whenSetNonNullUnit_thenValueIsSet() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertEquals(wind.getUnit(), "as"); @@ -109,14 +109,14 @@ public class WindUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetNullUnit_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setUnit(null); } @Test public void whenCallToString_thenAllIsFine() { - final Wind wind = Wind.forValue(302, "a"); + final Wind wind = Wind.withValue(302, "a"); Assert.assertNotNull(wind.toString()); @@ -128,8 +128,8 @@ public class WindUnitTest { @Test public void whenCallHashCode_thenAllIsFine() { - final Wind first = Wind.forValue(22, "a"); - final Wind second = Wind.forValue(22, "b"); + final Wind first = Wind.withValue(22, "a"); + final Wind second = Wind.withValue(22, "b"); Assert.assertNotEquals(first.hashCode(), second.hashCode()); @@ -152,8 +152,8 @@ public class WindUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Wind first = Wind.forValue(11, "a"); - final Wind second = Wind.forValue(11, "a"); + final Wind first = Wind.withValue(11, "a"); + final Wind second = Wind.withValue(11, "a"); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/weather/LocationUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/weather/LocationUnitTest.java index c65b899..9f0e505 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/weather/LocationUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/weather/LocationUnitTest.java @@ -32,17 +32,17 @@ import java.time.ZoneOffset; public class LocationUnitTest { @Test public void whenCreateObjectWithValidArgs_thenObjectIsCreated() { - Location.forValue(33, "test"); + Location.withValues(33, "test"); } @Test(expected = IllegalArgumentException.class) public void whenCreateObjectWithoutName_thenThrowAnException() { - Location.forValue(33, null); + Location.withValues(33, null); } @Test public void whenSetId_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); location.setId(55); Assert.assertEquals(55, location.getId()); @@ -50,7 +50,7 @@ public class LocationUnitTest { @Test public void whenSetName_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); location.setName("city"); Assert.assertEquals("city", location.getName()); @@ -58,7 +58,7 @@ public class LocationUnitTest { @Test public void whenSetCountryCode_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); location.setCountryCode("by"); Assert.assertEquals("by", location.getCountryCode()); @@ -66,7 +66,7 @@ public class LocationUnitTest { @Test public void whenSetSunrise_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); final LocalDateTime now = LocalDateTime.now(); location.setSunrise(now); @@ -75,7 +75,7 @@ public class LocationUnitTest { @Test public void whenSetSunset_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); final LocalDateTime now = LocalDateTime.now(); location.setSunset(now); @@ -84,7 +84,7 @@ public class LocationUnitTest { @Test public void whenSetZoneOffset_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); + final Location location = Location.withValues(33, "test"); final ZoneOffset offset = ZoneOffset.UTC; location.setZoneOffset(offset); @@ -93,8 +93,8 @@ public class LocationUnitTest { @Test public void whenSetCoordinate_thenValueIsSet() { - final Location location = Location.forValue(33, "test"); - final Coordinate coordinate = Coordinate.forValues(33.2, 64.2); + final Location location = Location.withValues(33, "test"); + final Coordinate coordinate = Coordinate.withValues(33.2, 64.2); location.setCoordinate(coordinate); Assert.assertEquals(coordinate, location.getCoordinate()); @@ -102,11 +102,11 @@ public class LocationUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final Location location = Location.forValue(44, "test"); + final Location location = Location.withValues(44, "test"); Assert.assertNotEquals("", location.toString()); - location.setCoordinate(Coordinate.forValues(33.2, 56.3)); + location.setCoordinate(Coordinate.withValues(33.2, 56.3)); Assert.assertNotEquals("", location.toString()); @@ -118,8 +118,8 @@ public class LocationUnitTest { @Test public void whenCallHashCode_thenAllIsFine() { - final Location one = Location.forValue(44, "test"); - final Location two = Location.forValue(44, "test"); + final Location one = Location.withValues(44, "test"); + final Location two = Location.withValues(44, "test"); Assert.assertEquals(one.hashCode(), two.hashCode()); @@ -130,8 +130,8 @@ public class LocationUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Location one = Location.forValue(44, "test"); - final Location two = Location.forValue(44, "test"); + final Location one = Location.withValues(44, "test"); + final Location two = Location.withValues(44, "test"); Assert.assertTrue(one.equals(one)); Assert.assertFalse(one.equals(new Object())); @@ -188,7 +188,7 @@ public class LocationUnitTest { Assert.assertTrue(one.equals(two)); - final Coordinate coordinate = Coordinate.forValues(33.5, -22.4); + final Coordinate coordinate = Coordinate.withValues(33.5, -22.4); one.setCoordinate(coordinate); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/weather/RainUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/weather/RainUnitTest.java index dc17c4d..accfa50 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/weather/RainUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/weather/RainUnitTest.java @@ -28,18 +28,14 @@ import org.junit.Test; public class RainUnitTest { @Test public void whenCreateRainWithValidArgs_thenObjectIsCreated() { - new Rain(2222.3, 324234.3); - new Rain(null, -213123.4); - new Rain(-123123.123, null); - new Rain(null, null); + Rain.withValues(2222.3, 324234.3); + Rain.withThreeHourLevelValue(213123.4); + Rain.withOneHourLevelValue(123123.123); } @Test public void whenSetValues_thenTheyAreSet() { - final Rain rain = new Rain(null, null); - - Assert.assertNull(rain.getOneHourRainLevel()); - Assert.assertNull(rain.getThreeHourRainLevel()); + final Rain rain = Rain.withValues(0, 0); rain.setOneHourRainLevel(33.3); Assert.assertEquals(33.3, rain.getOneHourRainLevel(), 0.00001); @@ -50,31 +46,33 @@ public class RainUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final Rain rain = new Rain(); + Rain rain = Rain.withThreeHourLevelValue(33.5); Assert.assertNotNull(rain.toString()); - Assert.assertEquals("unknown", rain.toString()); - - rain.setThreeHourRainLevel(33.5); - - Assert.assertNotNull(rain.toString()); - Assert.assertNotEquals("unknown", rain.toString()); + Assert.assertNotEquals("", rain.toString()); rain.setOneHourRainLevel(22.2); Assert.assertNotNull(rain.toString()); - Assert.assertNotEquals("unknown", rain.toString()); + Assert.assertNotEquals("", rain.toString()); + } - rain.setThreeHourRainLevel(null); + @Test(expected = IllegalArgumentException.class) + public void whenSetInvalidOneHourLevelValue_thenFail() { + final Rain rain = Rain.withValues(0, 0); + rain.setOneHourRainLevel(-20); + } - Assert.assertNotNull(rain.toString()); - Assert.assertNotEquals("unknown", rain.toString()); + @Test(expected = IllegalArgumentException.class) + public void whenSetInvalidThreeHourLevelValue_thenFail() { + final Rain rain = Rain.withValues(0, 0); + rain.setThreeHourRainLevel(-20); } @Test public void whenCallHashCode_thenAllIsFine() { - final Rain first = new Rain(); - final Rain second = new Rain(); + final Rain first = Rain.withValues(0, 0); + final Rain second = Rain.withValues(0, 0); Assert.assertEquals(first.hashCode(), second.hashCode()); @@ -97,8 +95,8 @@ public class RainUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Rain first = new Rain(); - final Rain second = new Rain(); + final Rain first = Rain.withValues(0, 0); + final Rain second = Rain.withValues(0, 0); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/weather/SnowUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/weather/SnowUnitTest.java index 8474185..d0b4c92 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/weather/SnowUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/weather/SnowUnitTest.java @@ -28,18 +28,14 @@ import org.junit.Test; public class SnowUnitTest { @Test public void whenCreateSnowWithValidArgs_ObjectIsCreated() { - new Snow(2222.3, 324234.3); - new Snow(null, -213123.4); - new Snow(-123123.123, null); - new Snow(null, null); + Snow.withValues(2222.3, 324234.3); + Snow.withThreeHourLevelValue(213123.4); + Snow.withOneHourLevelValue(123123.123); } @Test public void whenSetValues_thenTheyAreSet() { - final Snow snow = new Snow(null, null); - - Assert.assertNull(snow.getOneHourSnowLevel()); - Assert.assertNull(snow.getThreeHourSnowLevel()); + final Snow snow = Snow.withValues(0, 0); snow.setOneHourSnowLevel(33.3); Assert.assertEquals(33.3, snow.getOneHourSnowLevel(), 0.00001); @@ -48,33 +44,40 @@ public class SnowUnitTest { Assert.assertEquals(55.5, snow.getThreeHourSnowLevel(), 0.00001); } + @Test(expected = IllegalArgumentException.class) + public void whenSetInvalidOneHourLevelValue_thenFail() { + final Snow rain = Snow.withValues(0, 0); + rain.setOneHourSnowLevel(-20); + } + + @Test(expected = IllegalArgumentException.class) + public void whenSetInvalidThreeHourLevelValue_thenFail() { + final Snow rain = Snow.withValues(0, 0); + rain.setThreeHourSnowLevel(-20); + } + @Test public void whenCallToString_thenAllIsFine() { - final Snow snow = new Snow(); + final Snow snow = Snow.withOneHourLevelValue(33.5); Assert.assertNotNull(snow.toString()); - Assert.assertEquals("unknown", snow.toString()); - - snow.setThreeHourSnowLevel(33.5); - - Assert.assertNotNull(snow.toString()); - Assert.assertNotEquals("unknown", snow.toString()); + Assert.assertNotEquals("", snow.toString()); snow.setOneHourSnowLevel(22.2); Assert.assertNotNull(snow.toString()); - Assert.assertNotEquals("unknown", snow.toString()); + Assert.assertNotEquals("", snow.toString()); - snow.setThreeHourSnowLevel(null); + snow.setThreeHourSnowLevel(33.2); Assert.assertNotNull(snow.toString()); - Assert.assertNotEquals("unknown", snow.toString()); + Assert.assertNotEquals("", snow.toString()); } @Test public void whenCallHashCode_thenAllIsFine() { - final Snow first = new Snow(); - final Snow second = new Snow(); + final Snow first = Snow.withValues(0, 0); + final Snow second = Snow.withValues(0, 0); Assert.assertEquals(first.hashCode(), second.hashCode()); @@ -97,8 +100,8 @@ public class SnowUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Snow first = new Snow(); - final Snow second = new Snow(); + final Snow first = Snow.withValues(0, 0); + final Snow second = Snow.withValues(0, 0); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/weather/WeatherUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/weather/WeatherUnitTest.java index 353e897..10719bc 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/weather/WeatherUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/weather/WeatherUnitTest.java @@ -95,7 +95,7 @@ public class WeatherUnitTest { @Test public void whenSetTemperature_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final Temperature temperature = Temperature.forValue(22.3, "a"); + final Temperature temperature = Temperature.withValue(22.3, "a"); weather.setTemperature(temperature); Assert.assertEquals(temperature, weather.getTemperature()); @@ -104,7 +104,7 @@ public class WeatherUnitTest { @Test public void whenSetPressure_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.2); + final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.2); weather.setAtmosphericPressure(atmosphericPressure); Assert.assertEquals(atmosphericPressure, weather.getAtmosphericPressure()); @@ -113,7 +113,7 @@ public class WeatherUnitTest { @Test public void whenSetHumidity_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final Humidity humidity = Humidity.forValue((byte) 44); + final Humidity humidity = Humidity.withValue((byte) 44); weather.setHumidity(humidity); Assert.assertEquals(humidity, weather.getHumidity()); @@ -122,7 +122,7 @@ public class WeatherUnitTest { @Test public void whenSetWind_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final Wind wind = Wind.forValue(22.2, "a"); + final Wind wind = Wind.withValue(22.2, "a"); weather.setWind(wind); Assert.assertEquals(wind, weather.getWind()); @@ -131,7 +131,7 @@ public class WeatherUnitTest { @Test public void whenSetRain_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final Rain rain = new Rain(); + final Rain rain = Rain.withValues(0, 0); weather.setRain(rain); Assert.assertEquals(rain, weather.getRain()); @@ -140,7 +140,7 @@ public class WeatherUnitTest { @Test public void whenSetSnow_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final Snow snow = new Snow(); + final Snow snow = Snow.withValues(0, 0); weather.setSnow(snow); Assert.assertEquals(snow, weather.getSnow()); @@ -149,7 +149,7 @@ public class WeatherUnitTest { @Test public void whenSetClouds_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final Clouds clouds = Clouds.forValue((byte) 33); + final Clouds clouds = Clouds.withValue((byte) 33); weather.setClouds(clouds); Assert.assertEquals(clouds, weather.getClouds()); @@ -158,7 +158,7 @@ public class WeatherUnitTest { @Test public void whenSetLocation_thenValueIsSet() { final Weather weather = Weather.forValue("state", "desc"); - final Location location = Location.forValue(22, "asd"); + final Location location = Location.withValues(22, "asd"); weather.setLocation(location); Assert.assertEquals(location, weather.getLocation()); @@ -167,12 +167,12 @@ public class WeatherUnitTest { @Test public void whenCallToString_thenAllIsFine() { final Weather weather = Weather.forValue("state", "desc"); - final Location location = Location.forValue(12312, "asd"); - final Temperature temperature = Temperature.forValue(33.2, "asd"); - final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(44.4); - final Clouds clouds = Clouds.forValue((byte) 55); - final Rain rain = new Rain(33.2, null); - final Snow snow = new Snow(33.1, null); + final Location location = Location.withValues(12312, "asd"); + final Temperature temperature = Temperature.withValue(33.2, "asd"); + final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(44.4); + final Clouds clouds = Clouds.withValue((byte) 55); + final Rain rain = Rain.withOneHourLevelValue(33.2); + final Snow snow = Snow.withOneHourLevelValue(33.1); Assert.assertNotEquals("", weather.toString()); Assert.assertNotNull(weather.toString()); @@ -252,7 +252,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final Temperature temperature = Temperature.forValue(33.2, "as"); + final Temperature temperature = Temperature.withValue(33.2, "as"); one.setTemperature(temperature); Assert.assertFalse(one.equals(two)); @@ -261,7 +261,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final AtmosphericPressure atmosphericPressure = AtmosphericPressure.forValue(33.33); + final AtmosphericPressure atmosphericPressure = AtmosphericPressure.withValue(33.33); one.setAtmosphericPressure(atmosphericPressure); Assert.assertFalse(one.equals(two)); @@ -270,7 +270,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final Humidity humidity = Humidity.forValue((byte) 33); + final Humidity humidity = Humidity.withValue((byte) 33); one.setHumidity(humidity); Assert.assertFalse(one.equals(two)); @@ -279,7 +279,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final Wind wind = Wind.forValue(33.6, "asd"); + final Wind wind = Wind.withValue(33.6, "asd"); one.setWind(wind); Assert.assertFalse(one.equals(two)); @@ -288,7 +288,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final Rain rain = new Rain(); + final Rain rain = Rain.withValues(0, 0); one.setRain(rain); Assert.assertFalse(one.equals(two)); @@ -297,7 +297,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final Snow snow = new Snow(); + final Snow snow = Snow.withValues(0, 0); one.setSnow(snow); Assert.assertFalse(one.equals(two)); @@ -306,7 +306,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final Clouds clouds = Clouds.forValue((byte) 33); + final Clouds clouds = Clouds.withValue((byte) 33); one.setClouds(clouds); Assert.assertFalse(one.equals(two)); @@ -315,7 +315,7 @@ public class WeatherUnitTest { Assert.assertTrue(one.equals(two)); - final Location location = Location.forValue(231, "asda"); + final Location location = Location.withValues(231, "asda"); one.setLocation(location); Assert.assertFalse(one.equals(two)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/model/weather/WindUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/model/weather/WindUnitTest.java index f2ea0e0..3f57404 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/model/weather/WindUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/model/weather/WindUnitTest.java @@ -28,22 +28,22 @@ import org.junit.Test; public class WindUnitTest { @Test public void whenCreateWindWithValidArgs_thenValueIsSet() { - Assert.assertEquals(44.0, Wind.forValue(44, "ms").getSpeed(), 0.00001); + Assert.assertEquals(44.0, Wind.withValue(44, "ms").getSpeed(), 0.00001); } @Test(expected = IllegalArgumentException.class) public void whenCreateWindWithInvalidSpeedArg_thenThrowAnException() { - Wind.forValue(-21, "a"); + Wind.withValue(-21, "a"); } @Test(expected = IllegalArgumentException.class) public void whenCreateWindWithInvalidUnitArg_thenThrowAnException() { - Wind.forValue(342, null); + Wind.withValue(342, null); } @Test public void whenSetValidSpeed_thenValueIsSet() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertEquals(33, wind.getSpeed(), 0.00001); @@ -58,7 +58,7 @@ public class WindUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetInvalidSpeedBelow0_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertEquals(33, wind.getSpeed(), 0.00001); @@ -67,7 +67,7 @@ public class WindUnitTest { @Test public void whenSetValidDegrees_thenValueIsSet() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertNull(wind.getDegrees()); @@ -86,19 +86,19 @@ public class WindUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetInvalidDegreesBelow0_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setDegrees(-32); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidDegreesAbove360_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setDegrees(378); } @Test public void whenSetNonNullUnit_thenValueIsSet() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); Assert.assertEquals(wind.getUnit(), "as"); @@ -109,21 +109,21 @@ public class WindUnitTest { @Test(expected = IllegalArgumentException.class) public void whenSetNullUnit_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setUnit(null); } @Test(expected = IllegalArgumentException.class) public void whenSetInvalidGustValue_thenThrowAnException() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setGust(-50); } @Test public void whenSetValidGustValue_thenAllIsFine() { - final Wind wind = Wind.forValue(33, "as"); + final Wind wind = Wind.withValue(33, "as"); wind.setGust(30); @@ -132,7 +132,7 @@ public class WindUnitTest { @Test public void whenCallToString_thenAllIsFine() { - final Wind wind = Wind.forValue(302, "a"); + final Wind wind = Wind.withValue(302, "a"); Assert.assertNotNull(wind.toString()); @@ -148,8 +148,8 @@ public class WindUnitTest { @Test public void whenCallHashCode_thenAllIsFine() { - final Wind first = Wind.forValue(22, "a"); - final Wind second = Wind.forValue(22, "b"); + final Wind first = Wind.withValue(22, "a"); + final Wind second = Wind.withValue(22, "b"); Assert.assertNotEquals(first.hashCode(), second.hashCode()); @@ -172,8 +172,8 @@ public class WindUnitTest { @Test public void whenCheckEquality_thenAllIsFine() { - final Wind first = Wind.forValue(11, "a"); - final Wind second = Wind.forValue(11, "a"); + final Wind first = Wind.withValue(11, "a"); + final Wind second = Wind.withValue(11, "a"); Assert.assertTrue(first.equals(second)); Assert.assertTrue(first.equals(first)); diff --git a/src/test/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastIntegrationTest.java b/src/test/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastIntegrationTest.java index 51ed656..f085210 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastIntegrationTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/request/forecast/free/FiveDayThreeHourStepForecastIntegrationTest.java @@ -252,7 +252,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest { public void whenGetForecastByCoordinatesRequestAsJava_thenReturnNotNull() { final Forecast forecast = getClient() .forecast5Day3HourStep() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCoordinate(Coordinate.withValues(5, 5)) .language(Language.ENGLISH) .unitSystem(UnitSystem.METRIC) .count(15) @@ -277,7 +277,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest { public void whenGetForecastByCoordinatesRequestAsJSON_thenReturnNotNull() { final String forecastJson = getClient() .forecast5Day3HourStep() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCoordinate(Coordinate.withValues(5, 5)) .language(Language.SPANISH) .unitSystem(UnitSystem.IMPERIAL) .count(15) @@ -291,7 +291,7 @@ public class FiveDayThreeHourStepForecastIntegrationTest extends ApiTest { public void whenGetForecastByCoordinatesRequestAsXML_thenReturnNotNull() { final String forecastXml = getClient() .forecast5Day3HourStep() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCoordinate(Coordinate.withValues(5, 5)) .language(Language.ENGLISH) .unitSystem(UnitSystem.METRIC) .retrieve() diff --git a/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java b/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java index 806c4d4..2fb20a9 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/request/weather/multiple/MultipleResultCurrentWeatherIntegrationTest.java @@ -44,7 +44,15 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final List weatherList = getClient() .currentWeather() .multiple() - .byRectangle(CoordinateRectangle.forValues(12, 32, 15, 37), 10) + .byRectangle( + new CoordinateRectangle.Builder() + .setLongitudeLeft(12) + .setLatitudeBottom(32) + .setLongitudeRight(15) + .setLatitudeTop(37) + .build(), + 10 + ) .language(Language.ROMANIAN) .unitSystem(UnitSystem.METRIC) .retrieve() @@ -69,7 +77,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherJson = getClient() .currentWeather() .multiple() - .byRectangle(CoordinateRectangle.forValues(12, 32, 15, 37), 10) + .byRectangle(CoordinateRectangle.withValues(12, 32, 15, 37), 10) .language(Language.ROMANIAN) .unitSystem(UnitSystem.METRIC) .retrieve() @@ -83,7 +91,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final List weatherList = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5)) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5)) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieve() @@ -109,7 +117,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherJson = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5)) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5)) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieve() @@ -123,7 +131,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherXml = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5)) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5)) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieve() @@ -138,7 +146,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final List weatherList = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieve() @@ -164,7 +172,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherJson = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieve() @@ -178,7 +186,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherXml = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieve() @@ -192,7 +200,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final CompletableFuture> weatherListFuture = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieveAsync() @@ -209,7 +217,7 @@ public class MultipleResultCurrentWeatherIntegrationTest extends ApiTest { final CompletableFuture weatherFuture = getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(55.5, 37.5), 10) + .byCitiesInCycle(Coordinate.withValues(55.5, 37.5), 10) .language(Language.GERMAN) .unitSystem(UnitSystem.IMPERIAL) .retrieveAsync() diff --git a/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java b/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java index 260c86c..671fbac 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/request/weather/single/SingleResultCurrentWeatherIntegrationTest.java @@ -298,7 +298,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { final Weather weather = getClient() .currentWeather() .single() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCoordinate(Coordinate.withValues(5, 5)) .unitSystem(UnitSystem.METRIC) .retrieve() .asJava(); @@ -320,7 +320,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherJson = getClient() .currentWeather() .single() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCoordinate(Coordinate.withValues(5, 5)) .unitSystem(UnitSystem.METRIC) .retrieve() .asJSON(); @@ -333,7 +333,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherXml = getClient() .currentWeather() .single() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCoordinate(Coordinate.withValues(5, 5)) .unitSystem(UnitSystem.METRIC) .retrieve() .asXML(); @@ -346,7 +346,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { final String weatherHtml = getClient() .currentWeather() .single() - .byCoordinate(Coordinate.forValues(5, 5)) + .byCoordinate(Coordinate.withValues(5, 5)) .unitSystem(UnitSystem.METRIC) .retrieve() .asHTML(); @@ -550,7 +550,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { client .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(34.53, 66.74), 10) + .byCitiesInCycle(Coordinate.withValues(34.53, 66.74), 10) .retrieve() .asJSON(); } @@ -560,7 +560,7 @@ public class SingleResultCurrentWeatherIntegrationTest extends ApiTest { getClient() .currentWeather() .multiple() - .byCitiesInCycle(Coordinate.forValues(90.00, 66.74), 10) + .byCitiesInCycle(Coordinate.withValues(90.00, 66.74), 10) .retrieve() .asJava(); } diff --git a/src/test/java/com/github/prominence/openweathermap/api/utils/RequestUtilsUnitTest.java b/src/test/java/com/github/prominence/openweathermap/api/utils/RequestUtilsUnitTest.java index 3f4247a..763f8f7 100644 --- a/src/test/java/com/github/prominence/openweathermap/api/utils/RequestUtilsUnitTest.java +++ b/src/test/java/com/github/prominence/openweathermap/api/utils/RequestUtilsUnitTest.java @@ -1,3 +1,25 @@ +/* + * Copyright (c) 2021 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.utils; import com.github.prominence.openweathermap.api.exception.NoDataFoundException;