Package reorganizations. Small refactoring.

This commit is contained in:
Alexey Zinchenko 2021-03-20 23:48:57 +03:00
parent 2c54375cfe
commit 10ba59652b
27 changed files with 91 additions and 69 deletions

View File

@ -20,7 +20,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequesterImpl;
public class OpenWeatherMapClient { public class OpenWeatherMapClient {

View File

@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request;
import com.github.prominence.openweathermap.api.enums.Accuracy; import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.Language;

View File

@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request;
public interface RequestTerminator<T, S> { public interface RequestTerminator<T, S> {

View File

@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -28,14 +28,16 @@ import java.util.stream.Collectors;
public class RequestUrlBuilder { public class RequestUrlBuilder {
private StringBuilder builder = new StringBuilder(); private static final String API_KEY_PARAM_NAME = "appid";
private Map<String, Object> requestParameters = new HashMap<>();
public RequestUrlBuilder(String baseUrl) { private final StringBuilder builder = new StringBuilder("http://api.openweathermap.org/data/2.5/");
builder.append(baseUrl); private final Map<String, Object> requestParameters = new HashMap<>();
public RequestUrlBuilder(String key) {
requestParameters.put(API_KEY_PARAM_NAME, key);
} }
void append(String value) { public void append(String value) {
builder.append(value); builder.append(value);
} }
@ -43,7 +45,11 @@ public class RequestUrlBuilder {
requestParameters.put(key, value); requestParameters.put(key, value);
} }
String buildUrl() { public void setAPIKey(String key) {
requestParameters.put(API_KEY_PARAM_NAME, key);
}
public String buildUrl() {
final String joinedParameters = requestParameters.entrySet().stream() final String joinedParameters = requestParameters.entrySet().stream()
.map(entry -> entry.getKey() + "=" + entry.getValue()) .map(entry -> entry.getKey() + "=" + entry.getValue())
.collect(Collectors.joining("&")); .collect(Collectors.joining("&"));

View File

@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request;
import java.util.List; import java.util.List;

View File

@ -20,7 +20,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather;
import com.github.prominence.openweathermap.api.request.RequestTerminator;
public interface CurrentWeatherRequestTerminator<T, S> extends RequestTerminator<T, S> { public interface CurrentWeatherRequestTerminator<T, S> extends RequestTerminator<T, S> {

View File

@ -20,7 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather;
import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsWeatherRequester;
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationWeatherRequester;
public interface CurrentWeatherRequester { public interface CurrentWeatherRequester {

View File

@ -20,18 +20,20 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather;
import com.github.prominence.openweathermap.api.CurrentWeatherRequester; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.MultipleLocationsWeatherRequester; import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsCurrentWeatherRequesterImpl;
import com.github.prominence.openweathermap.api.SingleLocationWeatherRequester; import com.github.prominence.openweathermap.api.request.weather.multiple.MultipleLocationsWeatherRequester;
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationCurrentWeatherRequesterImpl;
import com.github.prominence.openweathermap.api.request.weather.single.SingleLocationWeatherRequester;
public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester { public class CurrentWeatherRequesterImpl implements CurrentWeatherRequester {
private RequestUrlBuilder urlBuilder = new RequestUrlBuilder("http://api.openweathermap.org/data/2.5/"); private final RequestUrlBuilder urlBuilder;
CurrentWeatherRequesterImpl(String apiKey) { public CurrentWeatherRequesterImpl(String apiKey) {
urlBuilder.addRequestParameter("appid", apiKey); urlBuilder = new RequestUrlBuilder(apiKey);
} }
public SingleLocationWeatherRequester single() { public SingleLocationWeatherRequester single() {

View File

@ -20,11 +20,11 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.prominence.openweathermap.api.ResponseMapper; import com.github.prominence.openweathermap.api.request.ResponseMapper;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.model.*; import com.github.prominence.openweathermap.api.model.*;
@ -81,9 +81,9 @@ import java.util.TimeZone;
*/ */
public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> { public class CurrentWeatherResponseMapper implements ResponseMapper<Weather> {
private UnitSystem unitSystem; private final UnitSystem unitSystem;
CurrentWeatherResponseMapper(UnitSystem unitSystem) { public CurrentWeatherResponseMapper(UnitSystem unitSystem) {
this.unitSystem = unitSystem != null ? unitSystem : UnitSystem.STANDARD; this.unitSystem = unitSystem != null ? unitSystem : UnitSystem.STANDARD;
} }

View File

@ -20,18 +20,17 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.MultipleLocationsWeatherRequester; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestCustomizer;
import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle; import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsWeatherRequester { public class MultipleLocationsCurrentWeatherRequesterImpl implements MultipleLocationsWeatherRequester {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) { public MultipleLocationsCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder; this.urlBuilder = urlBuilder;
} }

View File

@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle; import com.github.prominence.openweathermap.api.model.CoordinateRectangle;

View File

@ -20,9 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;

View File

@ -20,9 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherAsyncRequestTerminator; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.utils.RequestUtils; import com.github.prominence.openweathermap.api.utils.RequestUtils;
@ -32,8 +33,8 @@ import java.util.concurrent.CompletableFuture;
public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator { public class MultipleResultCurrentWeatherAsyncRequestTerminatorImpl implements MultipleResultCurrentWeatherAsyncRequestTerminator {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
private UnitSystem unitSystem; private final UnitSystem unitSystem;
MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { MultipleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder; this.urlBuilder = urlBuilder;

View File

@ -20,7 +20,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCurrentWeatherRequestCustomizer> { public interface MultipleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<MultipleResultCurrentWeatherRequestCustomizer> {

View File

@ -20,18 +20,16 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherAsyncRequestTerminator; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestCustomizer;
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestTerminator;
import com.github.prominence.openweathermap.api.enums.Accuracy; import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer { public class MultipleResultCurrentWeatherRequestCustomizerImpl implements MultipleResultCurrentWeatherRequestCustomizer {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
private Accuracy accuracy; private Accuracy accuracy;
private Language language; private Language language;

View File

@ -20,9 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
import java.util.List; import java.util.List;

View File

@ -20,9 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.multiple;
import com.github.prominence.openweathermap.api.MultipleResultCurrentWeatherRequestTerminator; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.utils.RequestUtils; import com.github.prominence.openweathermap.api.utils.RequestUtils;
@ -31,8 +32,8 @@ import java.util.List;
public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator { public class MultipleResultCurrentWeatherRequestTerminatorImpl implements MultipleResultCurrentWeatherRequestTerminator {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
private UnitSystem unitSystem; private final UnitSystem unitSystem;
MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { MultipleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder; this.urlBuilder = urlBuilder;

View File

@ -20,16 +20,16 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.SingleLocationWeatherRequester; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.model.Coordinate;
public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationWeatherRequester { public class SingleLocationCurrentWeatherRequesterImpl implements SingleLocationWeatherRequester {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) { public SingleLocationCurrentWeatherRequesterImpl(RequestUrlBuilder urlBuilder) {
this.urlBuilder = urlBuilder; this.urlBuilder = urlBuilder;
urlBuilder.append("weather"); urlBuilder.append("weather");
} }

View File

@ -20,7 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.model.Coordinate;

View File

@ -20,9 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;

View File

@ -20,9 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherAsyncRequestTerminator; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.utils.RequestUtils; import com.github.prominence.openweathermap.api.utils.RequestUtils;
@ -31,8 +32,8 @@ import java.util.concurrent.CompletableFuture;
public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator { public class SingleResultCurrentWeatherAsyncRequestTerminatorImpl implements SingleResultCurrentWeatherAsyncRequestTerminator {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
private UnitSystem unitSystem; private final UnitSystem unitSystem;
SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { SingleResultCurrentWeatherAsyncRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder; this.urlBuilder = urlBuilder;

View File

@ -20,7 +20,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.request.RequestCustomizer;
public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<SingleResultCurrentWeatherRequestCustomizer> { public interface SingleResultCurrentWeatherRequestCustomizer extends RequestCustomizer<SingleResultCurrentWeatherRequestCustomizer> {

View File

@ -20,18 +20,16 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherAsyncRequestTerminator; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestCustomizer;
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestTerminator;
import com.github.prominence.openweathermap.api.enums.Accuracy; import com.github.prominence.openweathermap.api.enums.Accuracy;
import com.github.prominence.openweathermap.api.enums.Language; import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer { public class SingleResultCurrentWeatherRequestCustomizerImpl implements SingleResultCurrentWeatherRequestCustomizer {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
private Accuracy accuracy; private Accuracy accuracy;
private Language language; private Language language;

View File

@ -20,9 +20,10 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequestTerminator;
public interface SingleResultCurrentWeatherRequestTerminator extends CurrentWeatherRequestTerminator<Weather, String> { public interface SingleResultCurrentWeatherRequestTerminator extends CurrentWeatherRequestTerminator<Weather, String> {
} }

View File

@ -20,17 +20,18 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.github.prominence.openweathermap.api.impl; package com.github.prominence.openweathermap.api.request.weather.single;
import com.github.prominence.openweathermap.api.SingleResultCurrentWeatherRequestTerminator; import com.github.prominence.openweathermap.api.request.RequestUrlBuilder;
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherResponseMapper;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;
import com.github.prominence.openweathermap.api.utils.RequestUtils; import com.github.prominence.openweathermap.api.utils.RequestUtils;
public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator { public class SingleResultCurrentWeatherRequestTerminatorImpl implements SingleResultCurrentWeatherRequestTerminator {
private RequestUrlBuilder urlBuilder; private final RequestUrlBuilder urlBuilder;
private UnitSystem unitSystem; private final UnitSystem unitSystem;
SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) { SingleResultCurrentWeatherRequestTerminatorImpl(RequestUrlBuilder urlBuilder, UnitSystem unitSystem) {
this.urlBuilder = urlBuilder; this.urlBuilder = urlBuilder;

View File

@ -22,7 +22,7 @@
package com.github.prominence.openweathermap.api; package com.github.prominence.openweathermap.api;
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient; import com.github.prominence.openweathermap.api.request.OpenWeatherMapClient;
import org.junit.BeforeClass; import org.junit.BeforeClass;
public class ApiTest { public class ApiTest {

View File

@ -27,7 +27,7 @@ import com.github.prominence.openweathermap.api.enums.Language;
import com.github.prominence.openweathermap.api.enums.UnitSystem; import com.github.prominence.openweathermap.api.enums.UnitSystem;
import com.github.prominence.openweathermap.api.exception.NoDataFoundException; import com.github.prominence.openweathermap.api.exception.NoDataFoundException;
import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException; import com.github.prominence.openweathermap.api.exception.InvalidAuthTokenException;
import com.github.prominence.openweathermap.api.impl.OpenWeatherMapClient; import com.github.prominence.openweathermap.api.request.OpenWeatherMapClient;
import com.github.prominence.openweathermap.api.model.Coordinate; import com.github.prominence.openweathermap.api.model.Coordinate;
import com.github.prominence.openweathermap.api.model.CoordinateRectangle; import com.github.prominence.openweathermap.api.model.CoordinateRectangle;
import com.github.prominence.openweathermap.api.model.Weather; import com.github.prominence.openweathermap.api.model.Weather;