Skip to content

Commit 6dcaec6

Browse files
committed
resolved conflicts
1 parent f091028 commit 6dcaec6

11 files changed

Lines changed: 161 additions & 84 deletions

File tree

src/main/java/io/apimatic/core/ApiCall.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public final class ApiCall<ResponseType, ExceptionType extends CoreApiException>
5050
* An instance of {@link ApiLogger} for logging.
5151
*/
5252
private final ApiLogger apiLogger;
53-
53+
5454
private Response response;
5555

5656

@@ -71,7 +71,18 @@ private ApiCall(final GlobalConfiguration globalConfig,
7171
this.endpointConfiguration = endpointConfiguration;
7272
this.apiLogger = SdkLoggerFactory.getLogger(globalConfig.getLoggingConfiguration());
7373
}
74-
74+
75+
/**
76+
* Prepare this ApiCall for pagination.
77+
* @param <T> Return type for the paginated data.
78+
* @param <I> Type of items in pages.
79+
* @param <P> Type of pages.
80+
* @param converter Converts the PaginatedData into the instance of type T.
81+
* @param responseToPage Converts the PageWrapper into the instance of type P.
82+
* @param responseToItems Extract list of items of type I from response.
83+
* @param strategies List of applicable pagination strategies.
84+
* @return Converted paginated data into type T
85+
*/
7586
public <T, I, P> T paginate(
7687
Function<PaginatedData<I, P, ResponseType, ExceptionType>, T> converter,
7788
Function<PageWrapper<I, ResponseType>, P> responseToPage,
@@ -81,11 +92,11 @@ public <T, I, P> T paginate(
8192
this, responseToPage, responseToItems, strategies
8293
));
8394
}
84-
95+
8596
public Response getResponse() {
8697
return response;
8798
}
88-
99+
89100
public HttpRequest.Builder getRequestBuilder() {
90101
return requestBuilder.copy();
91102
}
@@ -123,15 +134,19 @@ public CompletableFuture<ResponseType> executeAsync() {
123134
return responseHandler.handle(context, endpointConfiguration, globalConfig);
124135
}, apiLogger);
125136
}
126-
137+
138+
/**
139+
* Converts this ApiCall instance to its builder.
140+
* @return ApiCall.Builder that can create a copy of this instance.
141+
*/
127142
public Builder<ResponseType, ExceptionType> toBuilder() {
128143
Builder<ResponseType, ExceptionType> builder = new Builder<ResponseType, ExceptionType>();
129-
144+
130145
builder.globalConfig = globalConfig;
131146
builder.endpointConfigurationBuilder = endpointConfiguration.toBuilder();
132147
builder.responseHandlerBuilder = responseHandler.toBuilder();
133148
builder.requestBuilder = requestBuilder.copy();
134-
149+
135150
return builder;
136151
}
137152

src/main/java/io/apimatic/core/HttpRequest.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ private void updateBodyParams(UnaryOperator<Object> setter, String point) {
365365
}
366366

367367
if (bodySerializer != null && "".equals(point)) {
368-
try {
368+
try {
369369
String serializedBody = bodySerializer.supply();
370370
String newSerializedBody = setter.apply(serializedBody).toString();
371371
bodySerializer = () -> newSerializedBody;
@@ -633,39 +633,45 @@ private static String getSerializedHeaderValue(Object obj) {
633633

634634
return CoreHelper.trySerialize(obj);
635635
}
636-
636+
637+
/**
638+
* @return A query URL combining the path, query and template parameters.
639+
*/
637640
public String getQueryUrl() {
638641
StringBuilder builder = new StringBuilder(path);
639642

640643
CoreHelper.appendUrlWithQueryParameters(builder, queryParams,
641644
arraySerializationFormat);
642645
CoreHelper.appendUrlWithTemplateParameters(builder, templateParams);
643-
646+
644647
return builder.toString();
645648
}
646649

650+
/**
651+
* @return A copy of this request builder instance.
652+
*/
647653
public Builder copy() {
648654
Builder copy = new Builder();
649-
copy.server = this.server;
650-
copy.path = this.path;
651-
copy.httpMethod = this.httpMethod;
652-
copy.authBuilder = this.authBuilder.copy(); // Ensure AuthBuilder has a copy() method.
653-
copy.queryParams = new HashMap<>(this.queryParams);
654-
for (Map.Entry<String, SimpleEntry<Object, Boolean>> entry : this.templateParams.entrySet()) {
655+
copy.server = server;
656+
copy.path = path;
657+
copy.httpMethod = httpMethod;
658+
copy.authBuilder = authBuilder.copy();
659+
copy.queryParams = new HashMap<>(queryParams);
660+
for (Entry<String, SimpleEntry<Object, Boolean>> entry : templateParams.entrySet()) {
655661
copy.templateParams.put(entry.getKey(),
656662
new SimpleEntry<>(entry.getValue().getKey(), entry.getValue().getValue()));
657663
}
658-
for (Map.Entry<String, List<Object>> entry : this.headerParams.entrySet()) {
664+
for (Entry<String, List<Object>> entry : headerParams.entrySet()) {
659665
copy.headerParams.put(entry.getKey(), new ArrayList<>(entry.getValue()));
660666
}
661-
copy.multipartFormParams = new HashSet<>(this.multipartFormParams);
662-
copy.formParamaters = new HashMap<>(this.formParamaters);
663-
copy.body = this.body;
664-
copy.bodySerializer = this.bodySerializer;
665-
if (this.bodyParameters != null) {
666-
copy.bodyParameters = new HashMap<>(this.bodyParameters);
667+
copy.multipartFormParams = new HashSet<>(multipartFormParams);
668+
copy.formParamaters = new HashMap<>(formParamaters);
669+
copy.body = body;
670+
copy.bodySerializer = bodySerializer;
671+
if (bodyParameters != null) {
672+
copy.bodyParameters = new HashMap<>(bodyParameters);
667673
}
668-
copy.arraySerializationFormat = this.arraySerializationFormat;
674+
copy.arraySerializationFormat = arraySerializationFormat;
669675
copy.parameterBuilder = new Parameter.Builder();
670676

671677
return copy;

src/main/java/io/apimatic/core/ResponseHandler.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public final class ResponseHandler<ResponseType, ExceptionType extends CoreApiEx
8484
* @param globalErrorCases the map of global errors.
8585
* @param deserializer the deserializer of json response.
8686
* @param intermediateDeserializer the api response deserializer.
87-
* @param paginationDeserializer the pagination deserializer.
8887
* @param responseClassType the type of response class.
8988
* @param contextInitializer the context initializer in response models.
9089
* @param isNullify404Enabled on 404 error return null or not?.
@@ -233,18 +232,22 @@ private void throwConfiguredException(Map<String, ErrorCase<ExceptionType>> erro
233232
}
234233
}
235234

235+
/**
236+
* Converts this ResponseHandler to its builder.
237+
* @return ResponseHandler.Builder that can create a copy of this instance.
238+
*/
236239
public Builder<ResponseType, ExceptionType> toBuilder() {
237240
Builder<ResponseType, ExceptionType> builder = new Builder<ResponseType, ExceptionType>()
238-
.globalErrorCase(this.globalErrorCases != null ? new HashMap<>(this.globalErrorCases) : null)
239-
.deserializer(this.deserializer)
240-
.apiResponseDeserializer(this.intermediateDeserializer)
241-
.responseClassType(this.responseClassType)
242-
.contextInitializer(this.contextInitializer)
243-
.nullify404(this.isNullify404Enabled)
244-
.nullableResponseType(this.isNullableResponseType);
245-
241+
.globalErrorCase(globalErrorCases != null ? new HashMap<>(globalErrorCases) : null)
242+
.deserializer(deserializer)
243+
.apiResponseDeserializer(intermediateDeserializer)
244+
.responseClassType(responseClassType)
245+
.contextInitializer(contextInitializer)
246+
.nullify404(isNullify404Enabled)
247+
.nullableResponseType(isNullableResponseType);
248+
246249
builder.localErrorCases = localErrorCases;
247-
250+
248251
return builder;
249252
}
250253

src/main/java/io/apimatic/core/authentication/AuthBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ private List<Authentication> buildAuthGroup(Map<String, Authentication> authMana
137137
return auths;
138138
}
139139

140+
/**
141+
* @return A copy of this AuthBuilder instance.
142+
*/
140143
public AuthBuilder copy() {
141144
AuthBuilder copy = new AuthBuilder();
142145
copy.authKeys = new ArrayList<>(this.authKeys);
@@ -147,7 +150,7 @@ public AuthBuilder copy() {
147150
}
148151
copy.authBuilders.put(entry.getKey(), copiedList);
149152
}
150-
153+
151154
return copy;
152155
}
153156
}

src/main/java/io/apimatic/core/types/pagination/CheckedSupplier.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
import io.apimatic.core.types.CoreApiException;
66

77
public interface CheckedSupplier<T, E extends CoreApiException> {
8-
8+
9+
/**
10+
* @param <T> Represents type of stored value.
11+
* @param <E> Represents type of stored exception.
12+
* @param value Create an instance with stored exception of type E.
13+
* @return created CheckedSupplier object.
14+
*/
915
@SuppressWarnings("unchecked")
10-
public static <T, E extends CoreApiException> CheckedSupplier<T, E> createError(
16+
static <T, E extends CoreApiException> CheckedSupplier<T, E> createError(
1117
Throwable exception) {
1218
if (exception instanceof IOException) {
13-
return new CheckedSupplier<T, E>()
14-
{
19+
return new CheckedSupplier<T, E>() {
1520
@Override
1621
public T get() throws E, IOException {
1722
throw (IOException) exception;
@@ -20,8 +25,7 @@ public T get() throws E, IOException {
2025
}
2126

2227
if (exception instanceof CoreApiException) {
23-
return new CheckedSupplier<T, E>()
24-
{
28+
return new CheckedSupplier<T, E>() {
2529
@Override
2630
public T get() throws E, IOException {
2731
throw (E) exception;
@@ -30,18 +34,28 @@ public T get() throws E, IOException {
3034
}
3135

3236
return null;
33-
3437
}
3538

36-
public static <T, E extends CoreApiException> CheckedSupplier<T, E> create(T item) {
37-
return new CheckedSupplier<T, E>()
38-
{
39+
/**
40+
* @param <T> Represents type of stored value.
41+
* @param <E> Represents type of stored exception.
42+
* @param value Create an instance with stored value of type T.
43+
* @return created CheckedSupplier object.
44+
*/
45+
static <T, E extends CoreApiException> CheckedSupplier<T, E> create(T value) {
46+
return new CheckedSupplier<T, E>() {
3947
@Override
4048
public T get() throws E, IOException {
41-
return item;
49+
return value;
4250
}
4351
};
4452
}
4553

54+
/**
55+
* Get the stored instance or throw an exception.
56+
* @return The stored instance of type T.
57+
* @throws E
58+
* @throws IOException
59+
*/
4660
T get() throws E, IOException;
4761
}

src/main/java/io/apimatic/core/types/pagination/CursorPagination.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Builder apply(PaginatedData<?, ?, ?, ?> paginatedData) {
2727
AtomicBoolean isUpdated = new AtomicBoolean(false);
2828

2929
reqBuilder.updateParameterByJsonPointer(input, old -> {
30-
30+
3131
if (response == null) {
3232
currentRequestCursor = (String) old;
3333
isUpdated.set(true);
@@ -44,7 +44,7 @@ public Builder apply(PaginatedData<?, ?, ?, ?> paginatedData) {
4444
isUpdated.set(true);
4545
return cursorValue;
4646
});
47-
47+
4848
if (!isUpdated.get() && response == null) {
4949
return reqBuilder;
5050
}

src/main/java/io/apimatic/core/types/pagination/OffsetPagination.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public Builder apply(PaginatedData<?, ?, ?, ?> paginatedData) {
2121
Response response = paginatedData.getResponse();
2222
Builder reqBuilder = paginatedData.getRequestBuilder();
2323
AtomicBoolean isUpdated = new AtomicBoolean(false);
24-
24+
2525
reqBuilder.updateParameterByJsonPointer(input, old -> {
2626
int oldValue = Integer.parseInt("" + old);
2727

@@ -36,7 +36,7 @@ public Builder apply(PaginatedData<?, ?, ?, ?> paginatedData) {
3636
isUpdated.set(true);
3737
return newValue;
3838
});
39-
39+
4040
if (!isUpdated.get() && response == null) {
4141
return reqBuilder;
4242
}

src/main/java/io/apimatic/core/types/pagination/PagePagination.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public Builder apply(PaginatedData<?, ?, ?, ?> paginatedData) {
3636
isUpdated.set(true);
3737
return newValue;
3838
});
39-
39+
4040
if (!isUpdated.get() && response == null) {
4141
return reqBuilder;
4242
}

src/main/java/io/apimatic/core/types/pagination/PageWrapper.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
import io.apimatic.coreinterfaces.http.response.ApiResponseType;
77
import io.apimatic.coreinterfaces.http.response.Response;
88

9-
public class PageWrapper<I, P> implements ApiResponseType<P> {
9+
public final class PageWrapper<I, P> implements ApiResponseType<P> {
1010

11-
public static <I, P> PageWrapper<I, P> create(
12-
Response response, P page, List<I> items) {
11+
/**
12+
* Create an instance of PageWrapper with provided page and meta data.
13+
* @param <I> Represent type of items in the page.
14+
* @param <P> Represent type of page.
15+
* @param response Response from API call.
16+
* @param page Page to be wrapped.
17+
* @param items Extracted items from the page.
18+
* @return An new instance of PageWrapper.
19+
*/
20+
public static <I, P> PageWrapper<I, P> create(Response response, P page, List<I> items) {
1321
return new PageWrapper<I, P>(response.getStatusCode(), response.getHeaders(), page, items);
1422
}
1523

@@ -23,7 +31,8 @@ public static <I, P> PageWrapper<I, P> create(
2331
private int pageInput = -1;
2432
private String cursorInput = null;
2533

26-
private PageWrapper(int statusCode, HttpHeaders headers, P page, List<I> items) {
34+
private PageWrapper(int statusCode, final HttpHeaders headers, final P page,
35+
final List<I> items) {
2736
this.statusCode = statusCode;
2837
this.headers = headers;
2938
this.page = page;

0 commit comments

Comments
 (0)