From 724ea5acd2355c4b815f0ff9154d5ff76dff3698 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 16 Mar 2016 12:11:57 -0700 Subject: [PATCH 1/7] A working solution for lazy initiliazed paging --- .../ParameterGroupingOperationsImpl.java | 8 +- ...RestResourceFlatteningTestServiceImpl.java | 6 +- .../ApiVersionLocalOperationsImpl.java | 8 +- .../azurespecials/OdataOperationsImpl.java | 6 +- .../SkipUrlEncodingOperationsImpl.java | 6 +- .../fixtures/lro/LRORetrysOperationsImpl.java | 8 +- .../fixtures/lro/LROSADsOperationsImpl.java | 34 +-- .../lro/LROsCustomHeaderOperationsImpl.java | 8 +- .../java/fixtures/lro/LROsOperationsImpl.java | 46 ++-- .../fixtures/paging/PagingOperations.java | 21 +- .../fixtures/paging/PagingOperationsImpl.java | 158 +++++------ .../java/fixtures/paging/PagingTests.java | 12 +- .../AzureMethodTemplateModel.cs | 27 +- .../Templates/AzureMethodTemplate.cshtml | 2 +- .../Java/Java/Templates/MethodTemplate.cshtml | 6 +- .../java/com/microsoft/azure/PagedList.java | 245 ++++++++++++++++++ 16 files changed, 435 insertions(+), 166 deletions(-) create mode 100644 ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureparametergrouping/ParameterGroupingOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureparametergrouping/ParameterGroupingOperationsImpl.java index c58c318380..c9daca73b5 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureparametergrouping/ParameterGroupingOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureparametergrouping/ParameterGroupingOperationsImpl.java @@ -151,7 +151,7 @@ private ServiceResponse postRequiredDelegate(Response respon * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse postOptional() throws ErrorException, IOException { - ParameterGroupingPostOptionalParameters parameterGroupingPostOptionalParameters = null; + final ParameterGroupingPostOptionalParameters parameterGroupingPostOptionalParameters = null; String customHeader = null; if (parameterGroupingPostOptionalParameters != null) { customHeader = parameterGroupingPostOptionalParameters.getCustomHeader(); @@ -272,8 +272,8 @@ private ServiceResponse postOptionalDelegate(Response respon * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse postMultiParamGroups() throws ErrorException, IOException { - FirstParameterGroup firstParameterGroup = null; - ParameterGroupingPostMultiParamGroupsSecondParamGroup parameterGroupingPostMultiParamGroupsSecondParamGroup = null; + final FirstParameterGroup firstParameterGroup = null; + final ParameterGroupingPostMultiParamGroupsSecondParamGroup parameterGroupingPostMultiParamGroupsSecondParamGroup = null; String headerOne = null; if (firstParameterGroup != null) { headerOne = firstParameterGroup.getHeaderOne(); @@ -431,7 +431,7 @@ private ServiceResponse postMultiParamGroupsDelegate(Response postSharedParameterGroupObject() throws ErrorException, IOException { - FirstParameterGroup firstParameterGroup = null; + final FirstParameterGroup firstParameterGroup = null; String headerOne = null; if (firstParameterGroup != null) { headerOne = firstParameterGroup.getHeaderOne(); diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureresource/AutoRestResourceFlatteningTestServiceImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureresource/AutoRestResourceFlatteningTestServiceImpl.java index a2eff701dd..ef682bf3f4 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureresource/AutoRestResourceFlatteningTestServiceImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azureresource/AutoRestResourceFlatteningTestServiceImpl.java @@ -254,7 +254,7 @@ interface AutoRestResourceFlatteningTestServiceService { * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putArray() throws ErrorException, IOException { - List resourceArray = null; + final List resourceArray = null; Call call = service.putArray(resourceArray, this.getAcceptLanguage()); return putArrayDelegate(call.execute()); } @@ -388,7 +388,7 @@ private ServiceResponse> getArrayDelegate(Response putDictionary() throws ErrorException, IOException { - Map resourceDictionary = null; + final Map resourceDictionary = null; Call call = service.putDictionary(resourceDictionary, this.getAcceptLanguage()); return putDictionaryDelegate(call.execute()); } @@ -522,7 +522,7 @@ private ServiceResponse> getDictionaryDelegate(Res * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putResourceCollection() throws ErrorException, IOException { - ResourceCollection resourceComplexObject = null; + final ResourceCollection resourceComplexObject = null; Call call = service.putResourceCollection(resourceComplexObject, this.getAcceptLanguage()); return putResourceCollectionDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/ApiVersionLocalOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/ApiVersionLocalOperationsImpl.java index 0a2f4231af..fd1bad46b3 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/ApiVersionLocalOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/ApiVersionLocalOperationsImpl.java @@ -79,7 +79,7 @@ interface ApiVersionLocalService { * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getMethodLocalValid() throws ErrorException, IOException { - String apiVersion = "2.0"; + final String apiVersion = "2.0"; Call call = service.getMethodLocalValid(apiVersion, this.client.getAcceptLanguage()); return getMethodLocalValidDelegate(call.execute()); } @@ -126,7 +126,7 @@ private ServiceResponse getMethodLocalValidDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getMethodLocalNull() throws ErrorException, IOException { - String apiVersion = null; + final String apiVersion = null; Call call = service.getMethodLocalNull(apiVersion, this.client.getAcceptLanguage()); return getMethodLocalNullDelegate(call.execute()); } @@ -213,7 +213,7 @@ private ServiceResponse getMethodLocalNullDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getPathLocalValid() throws ErrorException, IOException { - String apiVersion = "2.0"; + final String apiVersion = "2.0"; Call call = service.getPathLocalValid(apiVersion, this.client.getAcceptLanguage()); return getPathLocalValidDelegate(call.execute()); } @@ -260,7 +260,7 @@ private ServiceResponse getPathLocalValidDelegate(Response r * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getSwaggerLocalValid() throws ErrorException, IOException { - String apiVersion = "2.0"; + final String apiVersion = "2.0"; Call call = service.getSwaggerLocalValid(apiVersion, this.client.getAcceptLanguage()); return getSwaggerLocalValidDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/OdataOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/OdataOperationsImpl.java index b0b40b356b..d8ff6ea5bd 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/OdataOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/OdataOperationsImpl.java @@ -69,9 +69,9 @@ interface OdataService { * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getWithFilter() throws ErrorException, IOException { - OdataFilter filter = null; - Integer top = null; - String orderby = null; + final OdataFilter filter = null; + final Integer top = null; + final String orderby = null; Call call = service.getWithFilter(this.client.getMapperAdapter().serializeRaw(filter), top, orderby, this.client.getAcceptLanguage()); return getWithFilterDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/SkipUrlEncodingOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/SkipUrlEncodingOperationsImpl.java index 7685a6dfee..20d997c500 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/SkipUrlEncodingOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/azurespecials/SkipUrlEncodingOperationsImpl.java @@ -202,7 +202,7 @@ private ServiceResponse getPathPathValidDelegate(Response re * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getSwaggerPathValid() throws ErrorException, IOException { - String unencodedPathParam = "path1/path2/path3"; + final String unencodedPathParam = "path1/path2/path3"; Call call = service.getSwaggerPathValid(unencodedPathParam, this.client.getAcceptLanguage()); return getSwaggerPathValidDelegate(call.execute()); } @@ -304,7 +304,7 @@ private ServiceResponse getMethodQueryValidDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getMethodQueryNull() throws ErrorException, IOException { - String q1 = null; + final String q1 = null; Call call = service.getMethodQueryNull(q1, this.client.getAcceptLanguage()); return getMethodQueryNullDelegate(call.execute()); } @@ -446,7 +446,7 @@ private ServiceResponse getPathQueryValidDelegate(Response r * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getSwaggerQueryValid() throws ErrorException, IOException { - String q1 = "value1&q2=value2&q3=value3"; + final String q1 = "value1&q2=value2&q3=value3"; Call call = service.getSwaggerQueryValid(q1, this.client.getAcceptLanguage()); return getSwaggerQueryValidDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LRORetrysOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LRORetrysOperationsImpl.java index 692030a0c9..7dc45ef987 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LRORetrysOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LRORetrysOperationsImpl.java @@ -214,7 +214,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut201CreatingSucceeded200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut201CreatingSucceeded200(product, this.client.getAcceptLanguage()); return beginPut201CreatingSucceeded200Delegate(call.execute()); } @@ -387,7 +387,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRelativeRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRelativeRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPutAsyncRelativeRetrySucceededDelegate(call.execute()); } @@ -812,7 +812,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPost202Retry200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPost202Retry200(product, this.client.getAcceptLanguage()); return beginPost202Retry200Delegate(call.execute()); } @@ -984,7 +984,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRelativeRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRelativeRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPostAsyncRelativeRetrySucceededDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROSADsOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROSADsOperationsImpl.java index 35987529ae..a00b4293ab 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROSADsOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROSADsOperationsImpl.java @@ -372,7 +372,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPutNonRetry400() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutNonRetry400(product, this.client.getAcceptLanguage()); return beginPutNonRetry400Delegate(call.execute()); } @@ -545,7 +545,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPutNonRetry201Creating400() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutNonRetry201Creating400(product, this.client.getAcceptLanguage()); return beginPutNonRetry201Creating400Delegate(call.execute()); } @@ -718,7 +718,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRelativeRetry400() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRelativeRetry400(product, this.client.getAcceptLanguage()); return beginPutAsyncRelativeRetry400Delegate(call.execute()); } @@ -1142,7 +1142,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostNonRetry400() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostNonRetry400(product, this.client.getAcceptLanguage()); return beginPostNonRetry400Delegate(call.execute()); } @@ -1314,7 +1314,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPost202NonRetry400() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPost202NonRetry400(product, this.client.getAcceptLanguage()); return beginPost202NonRetry400Delegate(call.execute()); } @@ -1486,7 +1486,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRelativeRetry400() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRelativeRetry400(product, this.client.getAcceptLanguage()); return beginPostAsyncRelativeRetry400Delegate(call.execute()); } @@ -1658,7 +1658,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPutError201NoProvisioningStatePayload() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutError201NoProvisioningStatePayload(product, this.client.getAcceptLanguage()); return beginPutError201NoProvisioningStatePayloadDelegate(call.execute()); } @@ -1831,7 +1831,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRelativeRetryNoStatus() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRelativeRetryNoStatus(product, this.client.getAcceptLanguage()); return beginPutAsyncRelativeRetryNoStatusDelegate(call.execute()); } @@ -2003,7 +2003,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRelativeRetryNoStatusPayload() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRelativeRetryNoStatusPayload(product, this.client.getAcceptLanguage()); return beginPutAsyncRelativeRetryNoStatusPayloadDelegate(call.execute()); } @@ -2343,7 +2343,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPost202NoLocation() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPost202NoLocation(product, this.client.getAcceptLanguage()); return beginPost202NoLocationDelegate(call.execute()); } @@ -2515,7 +2515,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRelativeRetryNoPayload() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRelativeRetryNoPayload(product, this.client.getAcceptLanguage()); return beginPostAsyncRelativeRetryNoPayloadDelegate(call.execute()); } @@ -2687,7 +2687,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut200InvalidJson() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut200InvalidJson(product, this.client.getAcceptLanguage()); return beginPut200InvalidJsonDelegate(call.execute()); } @@ -2860,7 +2860,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRelativeRetryInvalidHeader() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRelativeRetryInvalidHeader(product, this.client.getAcceptLanguage()); return beginPutAsyncRelativeRetryInvalidHeaderDelegate(call.execute()); } @@ -3032,7 +3032,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRelativeRetryInvalidJsonPolling() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRelativeRetryInvalidJsonPolling(product, this.client.getAcceptLanguage()); return beginPutAsyncRelativeRetryInvalidJsonPollingDelegate(call.execute()); } @@ -3456,7 +3456,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPost202RetryInvalidHeader() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPost202RetryInvalidHeader(product, this.client.getAcceptLanguage()); return beginPost202RetryInvalidHeaderDelegate(call.execute()); } @@ -3628,7 +3628,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRelativeRetryInvalidHeader() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRelativeRetryInvalidHeader(product, this.client.getAcceptLanguage()); return beginPostAsyncRelativeRetryInvalidHeaderDelegate(call.execute()); } @@ -3800,7 +3800,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRelativeRetryInvalidJsonPolling() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRelativeRetryInvalidJsonPolling(product, this.client.getAcceptLanguage()); return beginPostAsyncRelativeRetryInvalidJsonPollingDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsCustomHeaderOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsCustomHeaderOperationsImpl.java index 6c94f2561b..d5d7fa473e 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsCustomHeaderOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsCustomHeaderOperationsImpl.java @@ -186,7 +186,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPutAsyncRetrySucceededDelegate(call.execute()); } @@ -358,7 +358,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut201CreatingSucceeded200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut201CreatingSucceeded200(product, this.client.getAcceptLanguage()); return beginPut201CreatingSucceeded200Delegate(call.execute()); } @@ -531,7 +531,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPost202Retry200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPost202Retry200(product, this.client.getAcceptLanguage()); return beginPost202Retry200Delegate(call.execute()); } @@ -703,7 +703,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPostAsyncRetrySucceededDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsOperationsImpl.java index 214a5b14e6..6d2e6b6124 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/lro/LROsOperationsImpl.java @@ -465,7 +465,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut200Succeeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut200Succeeded(product, this.client.getAcceptLanguage()); return beginPut200SucceededDelegate(call.execute()); } @@ -638,7 +638,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut200SucceededNoState() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut200SucceededNoState(product, this.client.getAcceptLanguage()); return beginPut200SucceededNoStateDelegate(call.execute()); } @@ -810,7 +810,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut202Retry200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut202Retry200(product, this.client.getAcceptLanguage()); return beginPut202Retry200Delegate(call.execute()); } @@ -982,7 +982,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut201CreatingSucceeded200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut201CreatingSucceeded200(product, this.client.getAcceptLanguage()); return beginPut201CreatingSucceeded200Delegate(call.execute()); } @@ -1155,7 +1155,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut200UpdatingSucceeded204() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut200UpdatingSucceeded204(product, this.client.getAcceptLanguage()); return beginPut200UpdatingSucceeded204Delegate(call.execute()); } @@ -1327,7 +1327,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut201CreatingFailed200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut201CreatingFailed200(product, this.client.getAcceptLanguage()); return beginPut201CreatingFailed200Delegate(call.execute()); } @@ -1500,7 +1500,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPut200Acceptedcanceled200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPut200Acceptedcanceled200(product, this.client.getAcceptLanguage()); return beginPut200Acceptedcanceled200Delegate(call.execute()); } @@ -1672,7 +1672,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutNoHeaderInRetry() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutNoHeaderInRetry(product, this.client.getAcceptLanguage()); return beginPutNoHeaderInRetryDelegate(call.execute()); } @@ -1844,7 +1844,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPutAsyncRetrySucceededDelegate(call.execute()); } @@ -2016,7 +2016,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncNoRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncNoRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPutAsyncNoRetrySucceededDelegate(call.execute()); } @@ -2188,7 +2188,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncRetryFailed() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncRetryFailed(product, this.client.getAcceptLanguage()); return beginPutAsyncRetryFailedDelegate(call.execute()); } @@ -2360,7 +2360,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncNoRetrycanceled() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncNoRetrycanceled(product, this.client.getAcceptLanguage()); return beginPutAsyncNoRetrycanceledDelegate(call.execute()); } @@ -2532,7 +2532,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPutAsyncNoHeaderInRetry() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPutAsyncNoHeaderInRetry(product, this.client.getAcceptLanguage()); return beginPutAsyncNoHeaderInRetryDelegate(call.execute()); } @@ -2704,7 +2704,7 @@ public void onResponse(Call call, Response response) * @return the Sku object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPutNonResource() throws CloudException, IOException { - Sku sku = null; + final Sku sku = null; Call call = service.beginPutNonResource(sku, this.client.getAcceptLanguage()); return beginPutNonResourceDelegate(call.execute()); } @@ -2876,7 +2876,7 @@ public void onResponse(Call call, Response response) * @return the Sku object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPutAsyncNonResource() throws CloudException, IOException { - Sku sku = null; + final Sku sku = null; Call call = service.beginPutAsyncNonResource(sku, this.client.getAcceptLanguage()); return beginPutAsyncNonResourceDelegate(call.execute()); } @@ -3048,7 +3048,7 @@ public void onResponse(Call call, Response response) * @return the SubProduct object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPutSubResource() throws CloudException, IOException { - SubProduct product = null; + final SubProduct product = null; Call call = service.beginPutSubResource(product, this.client.getAcceptLanguage()); return beginPutSubResourceDelegate(call.execute()); } @@ -3220,7 +3220,7 @@ public void onResponse(Call call, Response response) * @return the SubProduct object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse beginPutAsyncSubResource() throws CloudException, IOException { - SubProduct product = null; + final SubProduct product = null; Call call = service.beginPutAsyncSubResource(product, this.client.getAcceptLanguage()); return beginPutAsyncSubResourceDelegate(call.execute()); } @@ -4492,7 +4492,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPost202Retry200() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPost202Retry200(product, this.client.getAcceptLanguage()); return beginPost202Retry200Delegate(call.execute()); } @@ -4664,7 +4664,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPost202NoRetry204() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPost202NoRetry204(product, this.client.getAcceptLanguage()); return beginPost202NoRetry204Delegate(call.execute()); } @@ -4836,7 +4836,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPostAsyncRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPostAsyncRetrySucceededDelegate(call.execute()); } @@ -5009,7 +5009,7 @@ public void onResponse(Call call, Response response) * @return the Product object wrapped in {@link ServiceResponseWithHeaders} if successful. */ public ServiceResponseWithHeaders beginPostAsyncNoRetrySucceeded() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncNoRetrySucceeded(product, this.client.getAcceptLanguage()); return beginPostAsyncNoRetrySucceededDelegate(call.execute()); } @@ -5182,7 +5182,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRetryFailed() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRetryFailed(product, this.client.getAcceptLanguage()); return beginPostAsyncRetryFailedDelegate(call.execute()); } @@ -5354,7 +5354,7 @@ public void onResponse(Call call, Response response) * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders beginPostAsyncRetrycanceled() throws CloudException, IOException { - Product product = null; + final Product product = null; Call call = service.beginPostAsyncRetrycanceled(product, this.client.getAcceptLanguage()); return beginPostAsyncRetrycanceledDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java index 711ca21a9c..6c0fceccf4 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java @@ -12,6 +12,7 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.PagedList; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceResponse; import fixtures.paging.models.PageImpl; @@ -34,7 +35,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getSinglePages() throws CloudException, IOException; + ServiceResponse> getSinglePages() throws CloudException, IOException; /** * A paging operation that finishes on the first call without a nextlink. @@ -52,7 +53,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePages() throws CloudException, IOException; + ServiceResponse> getMultiplePages() throws CloudException, IOException; /** * A paging operation that includes a nextLink that has 10 pages. @@ -71,7 +72,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePages(final String clientRequestId, final PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions) throws CloudException, IOException; + ServiceResponse> getMultiplePages(final String clientRequestId, final PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions) throws CloudException, IOException; /** * A paging operation that includes a nextLink that has 10 pages. @@ -93,7 +94,7 @@ public interface PagingOperations { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions) throws CloudException, IOException, IllegalArgumentException; + ServiceResponse> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions) throws CloudException, IOException, IllegalArgumentException; /** * A paging operation that includes a nextLink that has 10 pages. @@ -114,7 +115,7 @@ public interface PagingOperations { * @throws IllegalArgumentException exception thrown from invalid parameters * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions, final String clientRequestId) throws CloudException, IOException, IllegalArgumentException; + ServiceResponse> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions, final String clientRequestId) throws CloudException, IOException, IllegalArgumentException; /** * A paging operation that includes a nextLink that has 10 pages. @@ -134,7 +135,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePagesRetryFirst() throws CloudException, IOException; + ServiceResponse> getMultiplePagesRetryFirst() throws CloudException, IOException; /** * A paging operation that fails on the first call with 500 and then retries and then get a response including a nextLink that has 10 pages. @@ -152,7 +153,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePagesRetrySecond() throws CloudException, IOException; + ServiceResponse> getMultiplePagesRetrySecond() throws CloudException, IOException; /** * A paging operation that includes a nextLink that has 10 pages, of which the 2nd call fails first with 500. The client should retry and finish all 10 pages eventually. @@ -170,7 +171,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getSinglePagesFailure() throws CloudException, IOException; + ServiceResponse> getSinglePagesFailure() throws CloudException, IOException; /** * A paging operation that receives a 400 on the first call. @@ -188,7 +189,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePagesFailure() throws CloudException, IOException; + ServiceResponse> getMultiplePagesFailure() throws CloudException, IOException; /** * A paging operation that receives a 400 on the second call. @@ -206,7 +207,7 @@ public interface PagingOperations { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - ServiceResponse> getMultiplePagesFailureUri() throws CloudException, IOException; + ServiceResponse> getMultiplePagesFailureUri() throws CloudException, IOException; /** * A paging operation that receives an invalid nextLink. diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java index ada24d5dfb..301119d3ee 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java @@ -14,6 +14,8 @@ import com.microsoft.azure.AzureServiceResponseBuilder; import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceResponse; import com.microsoft.rest.ServiceResponseCallback; @@ -134,14 +136,15 @@ interface PagingService { * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getSinglePages() throws CloudException, IOException { + public ServiceResponse> getSinglePages() throws CloudException, IOException { Call call = service.getSinglePages(this.client.getAcceptLanguage()); ServiceResponse> response = getSinglePagesDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getSinglePagesNext(response.getBody().getNextPageLink()); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getSinglePagesNext(nextPageLink).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -192,9 +195,9 @@ private ServiceResponse> getSinglePagesDelegate(Response> getMultiplePages() throws CloudException, IOException { - String clientRequestId = null; - PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions = null; + public ServiceResponse> getMultiplePages() throws CloudException, IOException { + final String clientRequestId = null; + final PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions = null; Integer maxresults = null; if (pagingGetMultiplePagesOptions != null) { maxresults = pagingGetMultiplePagesOptions.getMaxresults(); @@ -205,11 +208,12 @@ public ServiceResponse> getMultiplePages() throws CloudException, } Call call = service.getMultiplePages(clientRequestId, this.client.getAcceptLanguage(), maxresults, timeout); ServiceResponse> response = getMultiplePagesDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getMultiplePagesNext(response.getBody().getNextPageLink(), clientRequestId, pagingGetMultiplePagesOptions); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getMultiplePagesNext(nextPageLink, clientRequestId, pagingGetMultiplePagesOptions).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -265,7 +269,7 @@ public void onResponse(Call call, Response response) * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getMultiplePages(final String clientRequestId, final PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions) throws CloudException, IOException { + public ServiceResponse> getMultiplePages(final String clientRequestId, final PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions) throws CloudException, IOException { Validator.validate(pagingGetMultiplePagesOptions); Integer maxresults = null; if (pagingGetMultiplePagesOptions != null) { @@ -277,11 +281,12 @@ public ServiceResponse> getMultiplePages(final String clientReques } Call call = service.getMultiplePages(clientRequestId, this.client.getAcceptLanguage(), maxresults, timeout); ServiceResponse> response = getMultiplePagesDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getMultiplePagesNext(response.getBody().getNextPageLink(), clientRequestId, pagingGetMultiplePagesOptions); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getMultiplePagesNext(nextPageLink, clientRequestId, pagingGetMultiplePagesOptions).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -345,25 +350,26 @@ private ServiceResponse> getMultiplePagesDelegate(Response> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions) throws CloudException, IOException, IllegalArgumentException { + public ServiceResponse> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions) throws CloudException, IOException, IllegalArgumentException { if (pagingGetMultiplePagesWithOffsetOptions == null) { throw new IllegalArgumentException("Parameter pagingGetMultiplePagesWithOffsetOptions is required and cannot be null."); } Validator.validate(pagingGetMultiplePagesWithOffsetOptions); - String clientRequestId = null; + final String clientRequestId = null; Integer maxresults = pagingGetMultiplePagesWithOffsetOptions.getMaxresults(); int offset = pagingGetMultiplePagesWithOffsetOptions.getOffset(); Integer timeout = pagingGetMultiplePagesWithOffsetOptions.getTimeout(); Call call = service.getMultiplePagesWithOffset(offset, clientRequestId, this.client.getAcceptLanguage(), maxresults, timeout); ServiceResponse> response = getMultiplePagesWithOffsetDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = new PagingGetMultiplePagesWithOffsetNextOptions(); - pagingGetMultiplePagesWithOffsetNextOptions.setMaxresults(pagingGetMultiplePagesWithOffsetOptions.getMaxresults()); - pagingGetMultiplePagesWithOffsetNextOptions.setTimeout(pagingGetMultiplePagesWithOffsetOptions.getTimeout()); - response = getMultiplePagesWithOffsetNext(response.getBody().getNextPageLink(), clientRequestId, pagingGetMultiplePagesWithOffsetNextOptions); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = new PagingGetMultiplePagesWithOffsetNextOptions(); + pagingGetMultiplePagesWithOffsetNextOptions.setMaxresults(pagingGetMultiplePagesWithOffsetOptions.getMaxresults()); + pagingGetMultiplePagesWithOffsetNextOptions.setTimeout(pagingGetMultiplePagesWithOffsetOptions.getTimeout()); + return getMultiplePagesWithOffsetNext(nextPageLink, clientRequestId, pagingGetMultiplePagesWithOffsetNextOptions).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -423,7 +429,7 @@ public void onResponse(Call call, Response response) * @throws IllegalArgumentException exception thrown from invalid parameters * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions, final String clientRequestId) throws CloudException, IOException, IllegalArgumentException { + public ServiceResponse> getMultiplePagesWithOffset(final PagingGetMultiplePagesWithOffsetOptions pagingGetMultiplePagesWithOffsetOptions, final String clientRequestId) throws CloudException, IOException, IllegalArgumentException { if (pagingGetMultiplePagesWithOffsetOptions == null) { throw new IllegalArgumentException("Parameter pagingGetMultiplePagesWithOffsetOptions is required and cannot be null."); } @@ -433,14 +439,15 @@ public ServiceResponse> getMultiplePagesWithOffset(final PagingGet Integer timeout = pagingGetMultiplePagesWithOffsetOptions.getTimeout(); Call call = service.getMultiplePagesWithOffset(offset, clientRequestId, this.client.getAcceptLanguage(), maxresults, timeout); ServiceResponse> response = getMultiplePagesWithOffsetDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = new PagingGetMultiplePagesWithOffsetNextOptions(); - pagingGetMultiplePagesWithOffsetNextOptions.setMaxresults(pagingGetMultiplePagesWithOffsetOptions.getMaxresults()); - pagingGetMultiplePagesWithOffsetNextOptions.setTimeout(pagingGetMultiplePagesWithOffsetOptions.getTimeout()); - response = getMultiplePagesWithOffsetNext(response.getBody().getNextPageLink(), clientRequestId, pagingGetMultiplePagesWithOffsetNextOptions); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = new PagingGetMultiplePagesWithOffsetNextOptions(); + pagingGetMultiplePagesWithOffsetNextOptions.setMaxresults(pagingGetMultiplePagesWithOffsetOptions.getMaxresults()); + pagingGetMultiplePagesWithOffsetNextOptions.setTimeout(pagingGetMultiplePagesWithOffsetOptions.getTimeout()); + return getMultiplePagesWithOffsetNext(nextPageLink, clientRequestId, pagingGetMultiplePagesWithOffsetNextOptions).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -504,14 +511,15 @@ private ServiceResponse> getMultiplePagesWithOffsetDelegate(Re * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getMultiplePagesRetryFirst() throws CloudException, IOException { + public ServiceResponse> getMultiplePagesRetryFirst() throws CloudException, IOException { Call call = service.getMultiplePagesRetryFirst(this.client.getAcceptLanguage()); ServiceResponse> response = getMultiplePagesRetryFirstDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getMultiplePagesRetryFirstNext(response.getBody().getNextPageLink()); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getMultiplePagesRetryFirstNext(nextPageLink).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -562,14 +570,15 @@ private ServiceResponse> getMultiplePagesRetryFirstDelegate(Re * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getMultiplePagesRetrySecond() throws CloudException, IOException { + public ServiceResponse> getMultiplePagesRetrySecond() throws CloudException, IOException { Call call = service.getMultiplePagesRetrySecond(this.client.getAcceptLanguage()); ServiceResponse> response = getMultiplePagesRetrySecondDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getMultiplePagesRetrySecondNext(response.getBody().getNextPageLink()); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getMultiplePagesRetrySecondNext(nextPageLink).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -620,14 +629,15 @@ private ServiceResponse> getMultiplePagesRetrySecondDelegate(R * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getSinglePagesFailure() throws CloudException, IOException { + public ServiceResponse> getSinglePagesFailure() throws CloudException, IOException { Call call = service.getSinglePagesFailure(this.client.getAcceptLanguage()); ServiceResponse> response = getSinglePagesFailureDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getSinglePagesFailureNext(response.getBody().getNextPageLink()); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getSinglePagesFailureNext(nextPageLink).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -678,14 +688,15 @@ private ServiceResponse> getSinglePagesFailureDelegate(Respons * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getMultiplePagesFailure() throws CloudException, IOException { + public ServiceResponse> getMultiplePagesFailure() throws CloudException, IOException { Call call = service.getMultiplePagesFailure(this.client.getAcceptLanguage()); ServiceResponse> response = getMultiplePagesFailureDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getMultiplePagesFailureNext(response.getBody().getNextPageLink()); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getMultiplePagesFailureNext(nextPageLink).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -736,14 +747,15 @@ private ServiceResponse> getMultiplePagesFailureDelegate(Respo * @throws IOException exception thrown from serialization/deserialization * @return the List<Product> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> getMultiplePagesFailureUri() throws CloudException, IOException { + public ServiceResponse> getMultiplePagesFailureUri() throws CloudException, IOException { Call call = service.getMultiplePagesFailureUri(this.client.getAcceptLanguage()); ServiceResponse> response = getMultiplePagesFailureUriDelegate(call.execute()); - List result = response.getBody().getItems(); - while (response.getBody().getNextPageLink() != null) { - response = getMultiplePagesFailureUriNext(response.getBody().getNextPageLink()); - result.addAll(response.getBody().getItems()); - } + PagedList result = new PagedList(response.getBody()) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + return getMultiplePagesFailureUriNext(nextPageLink).getBody(); + } + }; return new ServiceResponse<>(result, response.getResponse()); } @@ -863,8 +875,8 @@ public ServiceResponse> getMultiplePagesNext(final String next if (nextPageLink == null) { throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); } - String clientRequestId = null; - PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions = null; + final String clientRequestId = null; + final PagingGetMultiplePagesOptions pagingGetMultiplePagesOptions = null; Integer maxresults = null; if (pagingGetMultiplePagesOptions != null) { maxresults = pagingGetMultiplePagesOptions.getMaxresults(); @@ -1024,8 +1036,8 @@ public ServiceResponse> getMultiplePagesWithOffsetNext(final S if (nextPageLink == null) { throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); } - String clientRequestId = null; - PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = null; + final String clientRequestId = null; + final PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = null; Integer maxresults = pagingGetMultiplePagesWithOffsetNextOptions.getMaxresults(); Integer timeout = pagingGetMultiplePagesWithOffsetNextOptions.getTimeout(); Call call = service.getMultiplePagesWithOffsetNext(nextPageLink, clientRequestId, this.client.getAcceptLanguage(), maxresults, timeout); diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java index 6e1e3fdb7c..742b202f90 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java @@ -14,6 +14,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import javax.xml.ws.WebServiceException; + import static org.junit.Assert.fail; public class PagingTests { @@ -98,9 +100,10 @@ public void getSinglePagesFailure() throws Exception { public void getMultiplePagesFailure() throws Exception { try { List response = client.getPagingOperations().getMultiplePagesFailure().getBody(); + response.size(); fail(); - } catch (CloudException ex) { - Assert.assertNotNull(ex.getResponse()); + } catch (WebServiceException ex) { + Assert.assertNotNull(ex.getCause()); } } @@ -108,9 +111,10 @@ public void getMultiplePagesFailure() throws Exception { public void getMultiplePagesFailureUri() throws Exception { try { List response = client.getPagingOperations().getMultiplePagesFailureUri().getBody(); + response.size(); fail(); - } catch (CloudException ex) { - Assert.assertNotNull(ex.getResponse()); + } catch (WebServiceException ex) { + Assert.assertNotNull(ex.getCause()); } } } diff --git a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs index e05e6449f9..dadbaaebb3 100644 --- a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs +++ b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs @@ -296,18 +296,18 @@ public override string ResponseGeneration var builder = new IndentedStringBuilder(); builder.AppendLine("{0} response = {1}Delegate(call.execute());", this.DelegateOperationResponseReturnTypeString, this.Name); - builder.AppendLine("{0} result = response.getBody().getItems();", ReturnType.Body.Name); - builder.AppendLine("while (response.getBody().getNextPageLink() != null) {"); - builder.Indent(); + string invocation; AzureMethodTemplateModel nextMethod = GetPagingNextMethod(out invocation); - TransformPagingGroupedParameter(builder, nextMethod); - var nextCall = string.Format(CultureInfo.InvariantCulture, "response = {0}(response.getBody().getNextPageLink(), {1});", - invocation, - nextMethod.MethodParameterInvocation); - builder.AppendLine(nextCall.Replace(", nextPageLink", "")); - builder.AppendLine("result.addAll(response.getBody().getItems());"); - builder.Outdent().AppendLine("}"); + + builder.AppendLine("PagedList<{0}> result = new PagedList<{0}>(response.getBody()) {{", ((SequenceType)ReturnType.Body).ElementType.Name) + .Indent().AppendLine("@Override") + .AppendLine("public Page<{0}> loadPage(String nextPageLink) throws CloudException, IOException {{", ((SequenceType)ReturnType.Body).ElementType.Name) + .Indent(); + TransformPagingGroupedParameter(builder, nextMethod); + builder.AppendLine("return {0}({1}).getBody();", invocation, nextMethod.MethodParameterInvocation) + .Outdent().AppendLine("}") + .Outdent().AppendLine("};"); return builder.ToString(); } else if (this.IsPagingNonPollingOperation) @@ -513,6 +513,10 @@ public override string GenericReturnTypeString { return string.Format(CultureInfo.InvariantCulture, "PageImpl<{0}>", ((SequenceType)ReturnType.Body).ElementType); } + else if (ReturnType.Body is SequenceType && this.IsPagingOperation) + { + return string.Format(CultureInfo.InvariantCulture, "PagedList<{0}>", ((SequenceType)ReturnType.Body).ElementType); + } return base.GenericReturnTypeString; } } @@ -560,6 +564,7 @@ public override List InterfaceImports { imports.Remove("com.microsoft.rest.ServiceCallback"); imports.Add("com.microsoft.azure.ListOperationCallback"); + imports.Add("com.microsoft.azure.PagedList"); imports.AddRange(new CompositeType { Name = "PageImpl" }.ImportFrom(ServiceClient.Namespace, Namer)); } return imports; @@ -588,6 +593,8 @@ public override List ImplImports { imports.Remove("com.microsoft.rest.ServiceCallback"); imports.Add("com.microsoft.azure.ListOperationCallback"); + imports.Add("com.microsoft.azure.Page"); + imports.Add("com.microsoft.azure.PagedList"); imports.AddRange(new CompositeType { Name = "PageImpl" }.ImportFrom(ServiceClient.Namespace, Namer)); } if (this.IsPagingNextOperation) diff --git a/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml b/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml index 24c4417456..cc0c3349ff 100644 --- a/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml +++ b/AutoRest/Generators/Java/Azure.Java/Templates/AzureMethodTemplate.cshtml @@ -180,7 +180,7 @@ public @Model.OperationResponseReturnTypeString @(Model.Name)(@Model.MethodParam { if (parameter.IsConstant) { -@: @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); +@: final @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); } } @Model.BuildInputMappings() diff --git a/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml b/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml index d978365791..59dd9c09d6 100644 --- a/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml +++ b/AutoRest/Generators/Java/Java/Templates/MethodTemplate.cshtml @@ -49,11 +49,11 @@ public @Model.OperationResponseReturnTypeString @(Model.Name)(@Model.MethodRequi { if (!parameter.IsRequired) { -@: @(parameter.Type.Name) @(parameter.Name) = null; +@: final @(parameter.Type.Name) @(parameter.Name) = null; } if (parameter.IsConstant) { -@: @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); +@: final @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); } } @Model.BuildInputMappings() @@ -183,7 +183,7 @@ public @Model.OperationResponseReturnTypeString @(Model.Name)(@Model.MethodParam { if (parameter.IsConstant) { -@: @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); +@: final @(parameter.Type.Name) @(parameter.Name) = @(parameter.DefaultValue); } } @Model.BuildInputMappings() diff --git a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java new file mode 100644 index 0000000000..72dba3664b --- /dev/null +++ b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -0,0 +1,245 @@ +/** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + */ + +package com.microsoft.azure; + +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; + +import javax.xml.bind.DataBindingException; +import javax.xml.ws.WebServiceException; + +/** + * Defines a page interface in Azure responses. + * + * @param the element type. + */ +public abstract class PagedList implements List { + private List items; + private int pageCount; + private String nextPageLink; + + public PagedList(Page page) { + items = page.getItems(); + nextPageLink = page.getNextPageLink(); + pageCount = 1; + } + + public abstract Page loadPage(String nextPageLink) throws CloudException, IOException; + + public void loadAll() { + while (nextPageLink != null) { + try { + Page nextPage = loadPage(nextPageLink); + nextPageLink = nextPage.getNextPageLink(); + addAll(nextPage.getItems()); + } catch (CloudException e) { + throw new WebServiceException(e.toString(), e); + } catch (IOException e) { + throw new DataBindingException(e.getMessage(), e); + } + } + } + + private class Itr implements Iterator { + Iterator itemsItr; + + public Itr() { + itemsItr = items.iterator(); + } + + @Override + public boolean hasNext() { + return itemsItr.hasNext() || nextPageLink != null; + } + + @Override + public E next() { + if (!itemsItr.hasNext()) { + if (nextPageLink == null) { + throw new NoSuchElementException(); + } else { + try { + loadPage(nextPageLink); + itemsItr = items.iterator(); + } catch (CloudException e) { + throw new WebServiceException(e.toString(), e); + } catch (IOException e) { + throw new DataBindingException(e.getMessage(), e); + } + } + } + return itemsItr.next(); + } + + @Override + public void remove() { + itemsItr.remove(); + } + } + + private class ListItr extends Itr implements ListIterator { + ListIterator itemsListItr; + + public ListItr(int index) { + itemsListItr = items.listIterator(index); + } + + @Override + public boolean hasPrevious() { + return itemsListItr.hasPrevious(); + } + + @Override + public E previous() { + return itemsListItr.previous(); + } + + @Override + public int nextIndex() { + return itemsListItr.nextIndex(); + } + + @Override + public int previousIndex() { + return itemsListItr.previousIndex(); + } + + @Override + public void set(E e) { + itemsListItr.set(e); + } + + @Override + public void add(E e) { + itemsListItr.add(e); + } + } + + @Override + public int size() { + loadAll(); + return items.size(); + } + + @Override + public boolean isEmpty() { + return items.isEmpty() && nextPageLink == null; + } + + @Override + public boolean contains(Object o) { + loadAll(); + return items.contains(o); + } + + @Override + public Iterator iterator() { + return new Itr(); + } + + @Override + public Object[] toArray() { + loadAll(); + return items.toArray(); + } + + @Override + public T[] toArray(T[] a) { + loadAll(); + return items.toArray(a); + } + + @Override + public boolean add(E e) { + return items.add(e); + } + + @Override + public boolean remove(Object o) { + return items.remove(o); + } + + @Override + public boolean containsAll(Collection c) { + return items.containsAll(c); + } + + @Override + public boolean addAll(Collection c) { + return items.addAll(c); + } + + @Override + public boolean addAll(int index, Collection c) { + return items.addAll(index, c); + } + + @Override + public boolean removeAll(Collection c) { + return items.removeAll(c); + } + + @Override + public boolean retainAll(Collection c) { + return items.retainAll(c); + } + + @Override + public void clear() { + items.clear(); + } + + @Override + public E get(int index) { + return items.get(index); + } + + @Override + public E set(int index, E element) { + return items.set(index, element); + } + + @Override + public void add(int index, E element) { + items.add(index, element); + } + + @Override + public E remove(int index) { + return items.remove(index); + } + + @Override + public int indexOf(Object o) { + return items.indexOf(o); + } + + @Override + public int lastIndexOf(Object o) { + return items.lastIndexOf(o); + } + + @Override + public ListIterator listIterator() { + return new ListItr(0); + } + + @Override + public ListIterator listIterator(int index) { + return new ListItr(index); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return items.subList(fromIndex, toIndex); + } +} From a48a647f5567376bcf1bd49d90b7d78c4f544ffd Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 16 Mar 2016 15:08:35 -0700 Subject: [PATCH 2/7] Add Javadoc and cleanup --- .../fixtures/paging/PagingOperations.java | 1 - .../AzureMethodTemplateModel.cs | 1 + .../java/com/microsoft/azure/PagedList.java | 49 ++++++++++++++++--- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java index 6c0fceccf4..cf95eb2f01 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperations.java @@ -21,7 +21,6 @@ import fixtures.paging.models.PagingGetMultiplePagesWithOffsetOptions; import fixtures.paging.models.Product; import java.io.IOException; -import java.util.List; /** * An instance of this class provides access to all the operations defined diff --git a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs index dadbaaebb3..0855307f9f 100644 --- a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs +++ b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs @@ -565,6 +565,7 @@ public override List InterfaceImports imports.Remove("com.microsoft.rest.ServiceCallback"); imports.Add("com.microsoft.azure.ListOperationCallback"); imports.Add("com.microsoft.azure.PagedList"); + imports.Remove("java.util.List"); imports.AddRange(new CompositeType { Name = "PageImpl" }.ImportFrom(ServiceClient.Namespace, Namer)); } return imports; diff --git a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index 72dba3664b..a300ff6a3e 100644 --- a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -18,23 +18,40 @@ import javax.xml.ws.WebServiceException; /** - * Defines a page interface in Azure responses. + * Defines a list response from a paging operation. The pages are + * lazy initialized when an instance of this class is iterated. * * @param the element type. */ public abstract class PagedList implements List { + /** The actual items in the list. */ private List items; - private int pageCount; + /** Stores the link to get the next page of items. */ private String nextPageLink; + /** + * Creates an instance of PagedList from a {@link Page} response. + * + * @param page the {@link Page} object. + */ public PagedList(Page page) { items = page.getItems(); nextPageLink = page.getNextPageLink(); - pageCount = 1; } + /** + * Override this method to load the next page of items from a next page link. + * + * @param nextPageLink the link to get the next page of items. + * @return the {@link Page} object storing a page of items and a link to the next page. + * @throws CloudException thrown if an error is raised from Azure. + * @throws IOException thrown if there's any failure in deserialization. + */ public abstract Page loadPage(String nextPageLink) throws CloudException, IOException; + /** + * Keep loading the next page from the next page link until all items are loaded. + */ public void loadAll() { while (nextPageLink != null) { try { @@ -49,9 +66,16 @@ public void loadAll() { } } + /** + * The implementation of {@link Iterator} for PagedList. + */ private class Itr implements Iterator { - Iterator itemsItr; + /** The iterator for the actual list of items. */ + private Iterator itemsItr; + /** + * Creates an instance of the iterator. + */ public Itr() { itemsItr = items.iterator(); } @@ -68,7 +92,9 @@ public E next() { throw new NoSuchElementException(); } else { try { - loadPage(nextPageLink); + Page nextPage = loadPage(nextPageLink); + nextPageLink = nextPage.getNextPageLink(); + addAll(nextPage.getItems()); itemsItr = items.iterator(); } catch (CloudException e) { throw new WebServiceException(e.toString(), e); @@ -86,9 +112,18 @@ public void remove() { } } + /** + * The implementation of {@link ListIterator} for PagedList. + */ private class ListItr extends Itr implements ListIterator { - ListIterator itemsListItr; - + /** The list iterator for the actual list of items. */ + private ListIterator itemsListItr; + + /** + * Creates an instance of the ListIterator. + * + * @param index the position in the list to start. + */ public ListItr(int index) { itemsListItr = items.listIterator(index); } From fb0db5732bab2428fbf77ec21503f6e89041e3a3 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 16 Mar 2016 15:33:44 -0700 Subject: [PATCH 3/7] Add lazy behavior in get() --- .../src/test/java/fixtures/paging/PagingTests.java | 11 +++++++++-- .../src/main/java/com/microsoft/azure/PagedList.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java index 742b202f90..6e71ccb91d 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java @@ -35,8 +35,15 @@ public void getSinglePages() throws Exception { @Test public void getMultiplePages() throws Exception { - List response = client.getPagingOperations().getMultiplePages("client-id", null).getBody(); - Assert.assertEquals(10, response.size()); + List response = client.getPagingOperations().getMultiplePages().getBody(); + Product p1 = new Product(); + response.add(p1); + response.get(3); + Product p4 = new Product(); + response.add(p4); + Assert.assertEquals(12, response.size()); + Assert.assertEquals(1, response.indexOf(p1)); + Assert.assertEquals(4, response.indexOf(p4)); } @Test diff --git a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index a300ff6a3e..cdd38a5ca3 100644 --- a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -235,6 +235,17 @@ public void clear() { @Override public E get(int index) { + while (index >= items.size() && nextPageLink != null) { + try { + Page nextPage = loadPage(nextPageLink); + nextPageLink = nextPage.getNextPageLink(); + addAll(nextPage.getItems()); + } catch (CloudException e) { + throw new WebServiceException(e.toString(), e); + } catch (IOException e) { + throw new DataBindingException(e.getMessage(), e); + } + } return items.get(index); } From b43985272a7688a74bc9244fb7056b0d678735b7 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 17 Mar 2016 11:30:29 -0700 Subject: [PATCH 4/7] Fix iterator and add tests for PagedList --- .../java/fixtures/paging/PagingTests.java | 13 ++- .../java/com/microsoft/azure/PagedList.java | 46 ++++------ .../com/microsoft/azure/PagedListTests.java | 91 +++++++++++++++++++ 3 files changed, 119 insertions(+), 31 deletions(-) create mode 100644 ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java index 6e71ccb91d..04581c5950 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/test/java/fixtures/paging/PagingTests.java @@ -3,6 +3,8 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; import com.microsoft.rest.ServiceResponse; + +import fixtures.paging.models.ProductProperties; import okhttp3.logging.HttpLoggingInterceptor; import fixtures.paging.models.PagingGetMultiplePagesWithOffsetOptions; import fixtures.paging.models.Product; @@ -24,7 +26,7 @@ public class PagingTests { @BeforeClass public static void setup() { client = new AutoRestPagingTestServiceImpl("http://localhost.:3000", null); - client.setLogLevel(HttpLoggingInterceptor.Level.BODY); + client.setLogLevel(HttpLoggingInterceptor.Level.BASIC); } @Test @@ -37,10 +39,19 @@ public void getSinglePages() throws Exception { public void getMultiplePages() throws Exception { List response = client.getPagingOperations().getMultiplePages().getBody(); Product p1 = new Product(); + p1.setProperties(new ProductProperties()); response.add(p1); response.get(3); Product p4 = new Product(); + p4.setProperties(new ProductProperties()); response.add(p4); + int i = 0; + for (Product p : response) { + if (++i == 7) { + break; + } + } + System.out.println("Asserting..."); Assert.assertEquals(12, response.size()); Assert.assertEquals(1, response.indexOf(p1)); Assert.assertEquals(4, response.indexOf(p4)); diff --git a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index cdd38a5ca3..a2b9b67933 100644 --- a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -67,35 +67,38 @@ public void loadAll() { } /** - * The implementation of {@link Iterator} for PagedList. + * The implementation of {@link ListIterator} for PagedList. */ - private class Itr implements Iterator { - /** The iterator for the actual list of items. */ - private Iterator itemsItr; + private class ListItr implements ListIterator { + /** The list iterator for the actual list of items. */ + private ListIterator itemsListItr; /** - * Creates an instance of the iterator. + * Creates an instance of the ListIterator. + * + * @param index the position in the list to start. */ - public Itr() { - itemsItr = items.iterator(); + public ListItr(int index) { + itemsListItr = items.listIterator(index); } @Override public boolean hasNext() { - return itemsItr.hasNext() || nextPageLink != null; + return itemsListItr.hasNext() || nextPageLink != null; } @Override public E next() { - if (!itemsItr.hasNext()) { + if (!itemsListItr.hasNext()) { if (nextPageLink == null) { throw new NoSuchElementException(); } else { try { Page nextPage = loadPage(nextPageLink); nextPageLink = nextPage.getNextPageLink(); + int size = items.size(); addAll(nextPage.getItems()); - itemsItr = items.iterator(); + itemsListItr = items.listIterator(size); } catch (CloudException e) { throw new WebServiceException(e.toString(), e); } catch (IOException e) { @@ -103,29 +106,12 @@ public E next() { } } } - return itemsItr.next(); + return itemsListItr.next(); } @Override public void remove() { - itemsItr.remove(); - } - } - - /** - * The implementation of {@link ListIterator} for PagedList. - */ - private class ListItr extends Itr implements ListIterator { - /** The list iterator for the actual list of items. */ - private ListIterator itemsListItr; - - /** - * Creates an instance of the ListIterator. - * - * @param index the position in the list to start. - */ - public ListItr(int index) { - itemsListItr = items.listIterator(index); + itemsListItr.remove(); } @Override @@ -178,7 +164,7 @@ public boolean contains(Object o) { @Override public Iterator iterator() { - return new Itr(); + return new ListItr(0); } @Override diff --git a/ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java b/ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java new file mode 100644 index 0000000000..6ddc0c61ea --- /dev/null +++ b/ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java @@ -0,0 +1,91 @@ +/** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + */ + +package com.microsoft.azure; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class PagedListTests { + private PagedList list; + + @Before + public void setupList() { + list = new PagedList(new TestPage(0, 20)) { + @Override + public Page loadPage(String nextPageLink) throws CloudException, IOException { + int pageNum = Integer.parseInt(nextPageLink); + return new TestPage(pageNum, 20); + } + }; + } + + @Test + public void sizeTest() { + Assert.assertEquals(20, list.size()); + } + + @Test + public void getTest() { + Assert.assertEquals(15, (int) list.get(15)); + } + + @Test + public void iterateTest() { + int j = 0; + for (int i : list) { + Assert.assertEquals(i, j++); + } + } + + @Test + public void removeTest() { + Integer i = list.get(10); + list.remove(10); + Assert.assertEquals(19, list.size()); + Assert.assertEquals(19, (int) list.get(18)); + } + + @Test + public void addTest() { + Integer i = list.get(10); + list.add(100); + Assert.assertEquals(21, list.size()); + Assert.assertEquals(100, (int) list.get(11)); + Assert.assertEquals(19, (int) list.get(20)); + } + + public static class TestPage implements Page { + private int page; + private int max; + + public TestPage(int page, int max) { + this.page = page; + this.max = max; + } + + @Override + public String getNextPageLink() { + if (page + 1 == max) { + return null; + } + return Integer.toString(page + 1); + } + + @Override + public List getItems() { + List items = new ArrayList<>(); + items.add(page); + return items; + } + } +} From 3ab0c6a60ed904c9ead43912149864da34be2023 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 18 Mar 2016 17:35:46 -0700 Subject: [PATCH 5/7] Add more laziness to PagedList --- .../java/com/microsoft/azure/PagedList.java | 96 ++++++++++++------- .../com/microsoft/azure/PagedListTests.java | 38 +++++++- 2 files changed, 96 insertions(+), 38 deletions(-) diff --git a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index a2b9b67933..5f1676ff2b 100644 --- a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -47,22 +47,31 @@ public PagedList(Page page) { * @throws CloudException thrown if an error is raised from Azure. * @throws IOException thrown if there's any failure in deserialization. */ - public abstract Page loadPage(String nextPageLink) throws CloudException, IOException; + public abstract Page nextPage(String nextPageLink) throws CloudException, IOException; + + public boolean hasNextPage() { + return this.nextPageLink != null; + } + + public void loadNextPage() { + try { + Page nextPage = nextPage(this.nextPageLink); + this.nextPageLink = nextPage.getNextPageLink(); + this.items.addAll(nextPage.getItems()); + } catch (CloudException e) { + throw new WebServiceException(e.toString(), e); + } catch (IOException e) { + throw new DataBindingException(e.getMessage(), e); + } + + } /** * Keep loading the next page from the next page link until all items are loaded. */ public void loadAll() { - while (nextPageLink != null) { - try { - Page nextPage = loadPage(nextPageLink); - nextPageLink = nextPage.getNextPageLink(); - addAll(nextPage.getItems()); - } catch (CloudException e) { - throw new WebServiceException(e.toString(), e); - } catch (IOException e) { - throw new DataBindingException(e.getMessage(), e); - } + while (hasNextPage()) { + loadNextPage(); } } @@ -90,20 +99,12 @@ public boolean hasNext() { @Override public E next() { if (!itemsListItr.hasNext()) { - if (nextPageLink == null) { + if (!hasNextPage()) { throw new NoSuchElementException(); } else { - try { - Page nextPage = loadPage(nextPageLink); - nextPageLink = nextPage.getNextPageLink(); - int size = items.size(); - addAll(nextPage.getItems()); - itemsListItr = items.listIterator(size); - } catch (CloudException e) { - throw new WebServiceException(e.toString(), e); - } catch (IOException e) { - throw new DataBindingException(e.getMessage(), e); - } + int size = items.size(); + loadNextPage(); + itemsListItr = items.listIterator(size); } } return itemsListItr.next(); @@ -158,8 +159,7 @@ public boolean isEmpty() { @Override public boolean contains(Object o) { - loadAll(); - return items.contains(o); + return indexOf(o) >= 0; } @Override @@ -191,7 +191,12 @@ public boolean remove(Object o) { @Override public boolean containsAll(Collection c) { - return items.containsAll(c); + for (Object e : c) { + if (!contains(e)) { + return false; + } + } + return true; } @Override @@ -221,16 +226,8 @@ public void clear() { @Override public E get(int index) { - while (index >= items.size() && nextPageLink != null) { - try { - Page nextPage = loadPage(nextPageLink); - nextPageLink = nextPage.getNextPageLink(); - addAll(nextPage.getItems()); - } catch (CloudException e) { - throw new WebServiceException(e.toString(), e); - } catch (IOException e) { - throw new DataBindingException(e.getMessage(), e); - } + while (index >= items.size() && hasNextPage()) { + loadNextPage(); } return items.get(index); } @@ -252,11 +249,28 @@ public E remove(int index) { @Override public int indexOf(Object o) { - return items.indexOf(o); + int index = 0; + if (o == null) { + for (E item : this) { + if (item == null) { + return index; + } + ++index; + } + } else { + for (E item : this) { + if (item == o) { + return index; + } + ++index; + } + } + return -1; } @Override public int lastIndexOf(Object o) { + loadAll(); return items.lastIndexOf(o); } @@ -267,11 +281,19 @@ public ListIterator listIterator() { @Override public ListIterator listIterator(int index) { + while (index >= items.size() && hasNextPage()) { + loadNextPage(); + } return new ListItr(index); } @Override public List subList(int fromIndex, int toIndex) { + while ((fromIndex >= items.size() + || toIndex >= items.size()) + && hasNextPage()) { + loadNextPage(); + } return items.subList(fromIndex, toIndex); } } diff --git a/ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java b/ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java index 6ddc0c61ea..b82c8d0628 100644 --- a/ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java +++ b/ClientRuntimes/Java/azure-client-runtime/src/test/java/com/microsoft/azure/PagedListTests.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class PagedListTests { @@ -22,7 +23,7 @@ public class PagedListTests { public void setupList() { list = new PagedList(new TestPage(0, 20)) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { int pageNum = Integer.parseInt(nextPageLink); return new TestPage(pageNum, 20); } @@ -64,6 +65,41 @@ public void addTest() { Assert.assertEquals(19, (int) list.get(20)); } + @Test + public void containsTest() { + Assert.assertTrue(list.contains(0)); + Assert.assertTrue(list.contains(3)); + Assert.assertTrue(list.contains(19)); + Assert.assertFalse(list.contains(20)); + } + + @Test + public void containsAllTest() { + List subList = new ArrayList<>(); + subList.addAll(Arrays.asList(0, 3, 19)); + Assert.assertTrue(list.containsAll(subList)); + subList.add(20); + Assert.assertFalse(list.containsAll(subList)); + } + + @Test + public void subListTest() { + List subList = list.subList(5, 15); + Assert.assertEquals(10, subList.size()); + Assert.assertTrue(list.containsAll(subList)); + Assert.assertEquals(7, (int) subList.get(2)); + } + + @Test + public void testIndexOf() { + Assert.assertEquals(15, list.indexOf(15)); + } + + @Test + public void testLastIndexOf() { + Assert.assertEquals(15, list.lastIndexOf(15)); + } + public static class TestPage implements Page { private int page; private int max; From ec5a338255db1afbe050b2e966d89555f8eb8b9c Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 18 Mar 2016 17:38:39 -0700 Subject: [PATCH 6/7] Re-generate --- .../fixtures/paging/PagingOperationsImpl.java | 20 +- .../AzureMethodTemplateModel.cs | 2 +- .../bodystring/StringOperationsImpl.java | 2 +- .../fixtures/header/HeaderOperationsImpl.java | 6 +- .../http/HttpClientFailureOperationsImpl.java | 26 +- .../http/HttpRedirectsOperationsImpl.java | 14 +- .../http/HttpRetryOperationsImpl.java | 12 +- .../http/HttpServerFailureOperationsImpl.java | 4 +- .../http/HttpSuccessOperationsImpl.java | 28 +- ...RestResourceFlatteningTestServiceImpl.java | 12 +- .../ExplicitOperationsImpl.java | 22 +- .../ImplicitOperationsImpl.java | 6 +- .../fixtures/url/PathItemsOperationsImpl.java | 16 +- .../fixtures/url/PathsOperationsImpl.java | 32 +- .../fixtures/url/QueriesOperationsImpl.java | 68 +- .../AutoRestValidationTestImpl.java | 10 +- Samples/petstore/Java/SwaggerPetstore.java | 256 +++++++ .../petstore/Java/SwaggerPetstoreImpl.java | 634 +++++++++++++++++- 18 files changed, 1012 insertions(+), 158 deletions(-) diff --git a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java index 301119d3ee..04e7b51103 100644 --- a/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java +++ b/AutoRest/Generators/Java/Azure.Java.Tests/src/main/java/fixtures/paging/PagingOperationsImpl.java @@ -141,7 +141,7 @@ public ServiceResponse> getSinglePages() throws CloudExceptio ServiceResponse> response = getSinglePagesDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getSinglePagesNext(nextPageLink).getBody(); } }; @@ -210,7 +210,7 @@ public ServiceResponse> getMultiplePages() throws CloudExcept ServiceResponse> response = getMultiplePagesDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getMultiplePagesNext(nextPageLink, clientRequestId, pagingGetMultiplePagesOptions).getBody(); } }; @@ -283,7 +283,7 @@ public ServiceResponse> getMultiplePages(final String clientR ServiceResponse> response = getMultiplePagesDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getMultiplePagesNext(nextPageLink, clientRequestId, pagingGetMultiplePagesOptions).getBody(); } }; @@ -363,7 +363,7 @@ public ServiceResponse> getMultiplePagesWithOffset(final Pagi ServiceResponse> response = getMultiplePagesWithOffsetDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = new PagingGetMultiplePagesWithOffsetNextOptions(); pagingGetMultiplePagesWithOffsetNextOptions.setMaxresults(pagingGetMultiplePagesWithOffsetOptions.getMaxresults()); pagingGetMultiplePagesWithOffsetNextOptions.setTimeout(pagingGetMultiplePagesWithOffsetOptions.getTimeout()); @@ -441,7 +441,7 @@ public ServiceResponse> getMultiplePagesWithOffset(final Pagi ServiceResponse> response = getMultiplePagesWithOffsetDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { PagingGetMultiplePagesWithOffsetNextOptions pagingGetMultiplePagesWithOffsetNextOptions = new PagingGetMultiplePagesWithOffsetNextOptions(); pagingGetMultiplePagesWithOffsetNextOptions.setMaxresults(pagingGetMultiplePagesWithOffsetOptions.getMaxresults()); pagingGetMultiplePagesWithOffsetNextOptions.setTimeout(pagingGetMultiplePagesWithOffsetOptions.getTimeout()); @@ -516,7 +516,7 @@ public ServiceResponse> getMultiplePagesRetryFirst() throws C ServiceResponse> response = getMultiplePagesRetryFirstDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getMultiplePagesRetryFirstNext(nextPageLink).getBody(); } }; @@ -575,7 +575,7 @@ public ServiceResponse> getMultiplePagesRetrySecond() throws ServiceResponse> response = getMultiplePagesRetrySecondDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getMultiplePagesRetrySecondNext(nextPageLink).getBody(); } }; @@ -634,7 +634,7 @@ public ServiceResponse> getSinglePagesFailure() throws CloudE ServiceResponse> response = getSinglePagesFailureDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getSinglePagesFailureNext(nextPageLink).getBody(); } }; @@ -693,7 +693,7 @@ public ServiceResponse> getMultiplePagesFailure() throws Clou ServiceResponse> response = getMultiplePagesFailureDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getMultiplePagesFailureNext(nextPageLink).getBody(); } }; @@ -752,7 +752,7 @@ public ServiceResponse> getMultiplePagesFailureUri() throws C ServiceResponse> response = getMultiplePagesFailureUriDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page loadPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextPageLink) throws CloudException, IOException { return getMultiplePagesFailureUriNext(nextPageLink).getBody(); } }; diff --git a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs index 0855307f9f..d810f9c78f 100644 --- a/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs +++ b/AutoRest/Generators/Java/Azure.Java/TemplateModels/AzureMethodTemplateModel.cs @@ -302,7 +302,7 @@ public override string ResponseGeneration builder.AppendLine("PagedList<{0}> result = new PagedList<{0}>(response.getBody()) {{", ((SequenceType)ReturnType.Body).ElementType.Name) .Indent().AppendLine("@Override") - .AppendLine("public Page<{0}> loadPage(String nextPageLink) throws CloudException, IOException {{", ((SequenceType)ReturnType.Body).ElementType.Name) + .AppendLine("public Page<{0}> nextPage(String nextPageLink) throws CloudException, IOException {{", ((SequenceType)ReturnType.Body).ElementType.Name) .Indent(); TransformPagingGroupedParameter(builder, nextMethod); builder.AppendLine("return {0}({1}).getBody();", invocation, nextMethod.MethodParameterInvocation) diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodystring/StringOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodystring/StringOperationsImpl.java index 14dd438be9..d4b1368b10 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodystring/StringOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/bodystring/StringOperationsImpl.java @@ -144,7 +144,7 @@ private ServiceResponse getNullDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putNull() throws ErrorException, IOException { - String stringBody = null; + final String stringBody = null; Call call = service.putNull(stringBody); return putNullDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java index bd5c61f8ce..9c0fa819e1 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/header/HeaderOperationsImpl.java @@ -964,7 +964,7 @@ public ServiceResponse paramString(String scenario) throws ErrorException, if (scenario == null) { throw new IllegalArgumentException("Parameter scenario is required and cannot be null."); } - String value = null; + final String value = null; Call call = service.paramString(scenario, value); return paramStringDelegate(call.execute()); } @@ -1364,7 +1364,7 @@ public ServiceResponse paramDatetimeRfc1123(String scenario) throws ErrorE if (scenario == null) { throw new IllegalArgumentException("Parameter scenario is required and cannot be null."); } - DateTimeRfc1123 value = null; + final DateTimeRfc1123 value = null; Call call = service.paramDatetimeRfc1123(scenario, value); return paramDatetimeRfc1123Delegate(call.execute()); } @@ -1764,7 +1764,7 @@ public ServiceResponse paramEnum(String scenario) throws ErrorException, I if (scenario == null) { throw new IllegalArgumentException("Parameter scenario is required and cannot be null."); } - GreyscaleColors value = null; + final GreyscaleColors value = null; Call call = service.paramEnum(scenario, this.client.getMapperAdapter().serializeRaw(value)); return paramEnumDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpClientFailureOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpClientFailureOperationsImpl.java index f626f90b45..bd6d6718be 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpClientFailureOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpClientFailureOperationsImpl.java @@ -248,7 +248,7 @@ private ServiceResponse get400Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse put400() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put400(booleanValue); return put400Delegate(call.execute()); } @@ -334,7 +334,7 @@ private ServiceResponse put400Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse patch400() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch400(booleanValue); return patch400Delegate(call.execute()); } @@ -420,7 +420,7 @@ private ServiceResponse patch400Delegate(Response response) * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse post400() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post400(booleanValue); return post400Delegate(call.execute()); } @@ -506,7 +506,7 @@ private ServiceResponse post400Delegate(Response response) * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse delete400() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete400(booleanValue); return delete400Delegate(call.execute()); } @@ -724,7 +724,7 @@ private ServiceResponse get403Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse put404() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put404(booleanValue); return put404Delegate(call.execute()); } @@ -810,7 +810,7 @@ private ServiceResponse put404Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse patch405() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch405(booleanValue); return patch405Delegate(call.execute()); } @@ -896,7 +896,7 @@ private ServiceResponse patch405Delegate(Response response) * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse post406() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post406(booleanValue); return post406Delegate(call.execute()); } @@ -982,7 +982,7 @@ private ServiceResponse post406Delegate(Response response) * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse delete407() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete407(booleanValue); return delete407Delegate(call.execute()); } @@ -1068,7 +1068,7 @@ private ServiceResponse delete407Delegate(Response response * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse put409() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put409(booleanValue); return put409Delegate(call.execute()); } @@ -1286,7 +1286,7 @@ private ServiceResponse get412Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse put413() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put413(booleanValue); return put413Delegate(call.execute()); } @@ -1372,7 +1372,7 @@ private ServiceResponse put413Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse patch414() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch414(booleanValue); return patch414Delegate(call.execute()); } @@ -1458,7 +1458,7 @@ private ServiceResponse patch414Delegate(Response response) * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse post415() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post415(booleanValue); return post415Delegate(call.execute()); } @@ -1588,7 +1588,7 @@ private ServiceResponse get416Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse delete417() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete417(booleanValue); return delete417Delegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRedirectsOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRedirectsOperationsImpl.java index 839b448488..d422aab756 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRedirectsOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRedirectsOperationsImpl.java @@ -328,7 +328,7 @@ private ServiceResponseWithHeaders get301Deleg * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders put301() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put301(booleanValue); return put301Delegate(call.execute()); } @@ -507,7 +507,7 @@ private ServiceResponseWithHeaders get302Deleg * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders patch302() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch302(booleanValue); return patch302Delegate(call.execute()); } @@ -594,7 +594,7 @@ private ServiceResponseWithHeaders patch302D * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders post303() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post303(booleanValue); return post303Delegate(call.execute()); } @@ -774,7 +774,7 @@ private ServiceResponseWithHeaders get307Deleg * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders put307() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put307(booleanValue); return put307Delegate(call.execute()); } @@ -862,7 +862,7 @@ private ServiceResponseWithHeaders put307Deleg * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders patch307() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch307(booleanValue); return patch307Delegate(call.execute()); } @@ -950,7 +950,7 @@ private ServiceResponseWithHeaders patch307D * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders post307() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post307(booleanValue); return post307Delegate(call.execute()); } @@ -1038,7 +1038,7 @@ private ServiceResponseWithHeaders post307Del * @return the {@link ServiceResponseWithHeaders} object if successful. */ public ServiceResponseWithHeaders delete307() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete307(booleanValue); return delete307Delegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRetryOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRetryOperationsImpl.java index 30dfe78a8a..d3ba17ef43 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRetryOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpRetryOperationsImpl.java @@ -145,7 +145,7 @@ private ServiceResponse head408Delegate(Response response) throws Er * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse put500() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put500(booleanValue); return put500Delegate(call.execute()); } @@ -232,7 +232,7 @@ private ServiceResponse put500Delegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse patch500() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch500(booleanValue); return patch500Delegate(call.execute()); } @@ -364,7 +364,7 @@ private ServiceResponse get502Delegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse post503() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post503(booleanValue); return post503Delegate(call.execute()); } @@ -451,7 +451,7 @@ private ServiceResponse post503Delegate(Response response) t * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse delete503() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete503(booleanValue); return delete503Delegate(call.execute()); } @@ -538,7 +538,7 @@ private ServiceResponse delete503Delegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse put504() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put504(booleanValue); return put504Delegate(call.execute()); } @@ -625,7 +625,7 @@ private ServiceResponse put504Delegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse patch504() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch504(booleanValue); return patch504Delegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpServerFailureOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpServerFailureOperationsImpl.java index 18b484f053..1ea87e8af1 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpServerFailureOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpServerFailureOperationsImpl.java @@ -170,7 +170,7 @@ private ServiceResponse get501Delegate(Response response) t * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse post505() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post505(booleanValue); return post505Delegate(call.execute()); } @@ -256,7 +256,7 @@ private ServiceResponse post505Delegate(Response response) * @return the Error object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse delete505() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete505(booleanValue); return delete505Delegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpSuccessOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpSuccessOperationsImpl.java index d8c44b9786..792e759ec6 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpSuccessOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/http/HttpSuccessOperationsImpl.java @@ -230,7 +230,7 @@ private ServiceResponse get200Delegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse put200() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put200(booleanValue); return put200Delegate(call.execute()); } @@ -317,7 +317,7 @@ private ServiceResponse put200Delegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse patch200() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch200(booleanValue); return patch200Delegate(call.execute()); } @@ -404,7 +404,7 @@ private ServiceResponse patch200Delegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse post200() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post200(booleanValue); return post200Delegate(call.execute()); } @@ -491,7 +491,7 @@ private ServiceResponse post200Delegate(Response response) t * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse delete200() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete200(booleanValue); return delete200Delegate(call.execute()); } @@ -578,7 +578,7 @@ private ServiceResponse delete200Delegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse put201() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put201(booleanValue); return put201Delegate(call.execute()); } @@ -665,7 +665,7 @@ private ServiceResponse put201Delegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse post201() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post201(booleanValue); return post201Delegate(call.execute()); } @@ -752,7 +752,7 @@ private ServiceResponse post201Delegate(Response response) t * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse put202() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put202(booleanValue); return put202Delegate(call.execute()); } @@ -839,7 +839,7 @@ private ServiceResponse put202Delegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse patch202() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch202(booleanValue); return patch202Delegate(call.execute()); } @@ -926,7 +926,7 @@ private ServiceResponse patch202Delegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse post202() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post202(booleanValue); return post202Delegate(call.execute()); } @@ -1013,7 +1013,7 @@ private ServiceResponse post202Delegate(Response response) t * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse delete202() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete202(booleanValue); return delete202Delegate(call.execute()); } @@ -1145,7 +1145,7 @@ private ServiceResponse head204Delegate(Response response) throws Er * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse put204() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.put204(booleanValue); return put204Delegate(call.execute()); } @@ -1232,7 +1232,7 @@ private ServiceResponse put204Delegate(Response response) th * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse patch204() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.patch204(booleanValue); return patch204Delegate(call.execute()); } @@ -1319,7 +1319,7 @@ private ServiceResponse patch204Delegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse post204() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.post204(booleanValue); return post204Delegate(call.execute()); } @@ -1406,7 +1406,7 @@ private ServiceResponse post204Delegate(Response response) t * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse delete204() throws ErrorException, IOException { - Boolean booleanValue = null; + final Boolean booleanValue = null; Call call = service.delete204(booleanValue); return delete204Delegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/AutoRestResourceFlatteningTestServiceImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/AutoRestResourceFlatteningTestServiceImpl.java index af6d9e3705..a85d96f940 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/AutoRestResourceFlatteningTestServiceImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/modelflattening/AutoRestResourceFlatteningTestServiceImpl.java @@ -169,7 +169,7 @@ interface AutoRestResourceFlatteningTestServiceService { * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putArray() throws ErrorException, IOException { - List resourceArray = null; + final List resourceArray = null; Call call = service.putArray(resourceArray); return putArrayDelegate(call.execute()); } @@ -303,7 +303,7 @@ private ServiceResponse> getArrayDelegate(Response putDictionary() throws ErrorException, IOException { - Map resourceDictionary = null; + final Map resourceDictionary = null; Call call = service.putDictionary(resourceDictionary); return putDictionaryDelegate(call.execute()); } @@ -437,7 +437,7 @@ private ServiceResponse> getDictionaryDelegate(Res * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putResourceCollection() throws ErrorException, IOException { - ResourceCollection resourceComplexObject = null; + final ResourceCollection resourceComplexObject = null; Call call = service.putResourceCollection(resourceComplexObject); return putResourceCollectionDelegate(call.execute()); } @@ -571,7 +571,7 @@ private ServiceResponse getResourceCollectionDelegate(Respon * @return the SimpleProduct object wrapped in {@link ServiceResponse} if successful. */ public ServiceResponse putSimpleProduct() throws ErrorException, IOException { - SimpleProduct simpleBodyProduct = null; + final SimpleProduct simpleBodyProduct = null; Call call = service.putSimpleProduct(simpleBodyProduct); return putSimpleProductDelegate(call.execute()); } @@ -669,8 +669,8 @@ public ServiceResponse postFlattenedSimpleProduct(String productI if (maxProductDisplayName == null) { throw new IllegalArgumentException("Parameter maxProductDisplayName is required and cannot be null."); } - String description = null; - String odatavalue = null; + final String description = null; + final String odatavalue = null; SimpleProduct simpleBodyProduct = null; if (description != null || odatavalue != null) { simpleBodyProduct = new SimpleProduct(); diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ExplicitOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ExplicitOperationsImpl.java index 13b3718955..9beced52bb 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ExplicitOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ExplicitOperationsImpl.java @@ -210,7 +210,7 @@ private ServiceResponse postRequiredIntegerParameterDelegate(Response postOptionalIntegerParameter() throws ErrorException, IOException { - Integer bodyParameter = null; + final Integer bodyParameter = null; Call call = service.postOptionalIntegerParameter(bodyParameter); return postOptionalIntegerParameterDelegate(call.execute()); } @@ -353,7 +353,7 @@ private ServiceResponse postRequiredIntegerPropertyDelegate(Response postOptionalIntegerProperty() throws ErrorException, IOException { - IntOptionalWrapper bodyParameter = null; + final IntOptionalWrapper bodyParameter = null; Call call = service.postOptionalIntegerProperty(bodyParameter); return postOptionalIntegerPropertyDelegate(call.execute()); } @@ -488,7 +488,7 @@ private ServiceResponse postRequiredIntegerHeaderDelegate(Response postOptionalIntegerHeader() throws ErrorException, IOException { - Integer headerParameter = null; + final Integer headerParameter = null; Call call = service.postOptionalIntegerHeader(headerParameter); return postOptionalIntegerHeaderDelegate(call.execute()); } @@ -629,7 +629,7 @@ private ServiceResponse postRequiredStringParameterDelegate(Response postOptionalStringParameter() throws ErrorException, IOException { - String bodyParameter = null; + final String bodyParameter = null; Call call = service.postOptionalStringParameter(bodyParameter); return postOptionalStringParameterDelegate(call.execute()); } @@ -772,7 +772,7 @@ private ServiceResponse postRequiredStringPropertyDelegate(Response postOptionalStringProperty() throws ErrorException, IOException { - StringOptionalWrapper bodyParameter = null; + final StringOptionalWrapper bodyParameter = null; Call call = service.postOptionalStringProperty(bodyParameter); return postOptionalStringPropertyDelegate(call.execute()); } @@ -915,7 +915,7 @@ private ServiceResponse postRequiredStringHeaderDelegate(Response postOptionalStringHeader() throws ErrorException, IOException { - String bodyParameter = null; + final String bodyParameter = null; Call call = service.postOptionalStringHeader(bodyParameter); return postOptionalStringHeaderDelegate(call.execute()); } @@ -1058,7 +1058,7 @@ private ServiceResponse postRequiredClassParameterDelegate(Response postOptionalClassParameter() throws ErrorException, IOException { - Product bodyParameter = null; + final Product bodyParameter = null; Call call = service.postOptionalClassParameter(bodyParameter); return postOptionalClassParameterDelegate(call.execute()); } @@ -1203,7 +1203,7 @@ private ServiceResponse postRequiredClassPropertyDelegate(Response postOptionalClassProperty() throws ErrorException, IOException { - ClassOptionalWrapper bodyParameter = null; + final ClassOptionalWrapper bodyParameter = null; Call call = service.postOptionalClassProperty(bodyParameter); return postOptionalClassPropertyDelegate(call.execute()); } @@ -1348,7 +1348,7 @@ private ServiceResponse postRequiredArrayParameterDelegate(Response postOptionalArrayParameter() throws ErrorException, IOException { - List bodyParameter = null; + final List bodyParameter = null; Call call = service.postOptionalArrayParameter(bodyParameter); return postOptionalArrayParameterDelegate(call.execute()); } @@ -1493,7 +1493,7 @@ private ServiceResponse postRequiredArrayPropertyDelegate(Response postOptionalArrayProperty() throws ErrorException, IOException { - ArrayOptionalWrapper bodyParameter = null; + final ArrayOptionalWrapper bodyParameter = null; Call call = service.postOptionalArrayProperty(bodyParameter); return postOptionalArrayPropertyDelegate(call.execute()); } @@ -1638,7 +1638,7 @@ private ServiceResponse postRequiredArrayHeaderDelegate(Response postOptionalArrayHeader() throws ErrorException, IOException { - List headerParameter = null; + final List headerParameter = null; Call call = service.postOptionalArrayHeader(this.client.getMapperAdapter().serializeList(headerParameter, CollectionFormat.CSV)); return postOptionalArrayHeaderDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ImplicitOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ImplicitOperationsImpl.java index f5f973ca85..4b8c4626cc 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ImplicitOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/requiredoptional/ImplicitOperationsImpl.java @@ -149,7 +149,7 @@ private ServiceResponse getRequiredPathDelegate(Response re * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putOptionalQuery() throws ErrorException, IOException { - String queryParameter = null; + final String queryParameter = null; Call call = service.putOptionalQuery(queryParameter); return putOptionalQueryDelegate(call.execute()); } @@ -236,7 +236,7 @@ private ServiceResponse putOptionalQueryDelegate(Response re * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putOptionalHeader() throws ErrorException, IOException { - String queryParameter = null; + final String queryParameter = null; Call call = service.putOptionalHeader(queryParameter); return putOptionalHeaderDelegate(call.execute()); } @@ -323,7 +323,7 @@ private ServiceResponse putOptionalHeaderDelegate(Response r * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse putOptionalBody() throws ErrorException, IOException { - String bodyParameter = null; + final String bodyParameter = null; Call call = service.putOptionalBody(bodyParameter); return putOptionalBodyDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathItemsOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathItemsOperationsImpl.java index 4ac4403103..c7085c3507 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathItemsOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathItemsOperationsImpl.java @@ -91,8 +91,8 @@ public ServiceResponse getAllWithValues(String localStringPath, String pat if (this.client.getGlobalStringPath() == null) { throw new IllegalArgumentException("Parameter this.client.getGlobalStringPath() is required and cannot be null."); } - String localStringQuery = null; - String pathItemStringQuery = null; + final String localStringQuery = null; + final String pathItemStringQuery = null; Call call = service.getAllWithValues(localStringPath, pathItemStringPath, this.client.getGlobalStringPath(), localStringQuery, pathItemStringQuery, this.client.getGlobalStringQuery()); return getAllWithValuesDelegate(call.execute()); } @@ -234,8 +234,8 @@ public ServiceResponse getGlobalQueryNull(String localStringPath, String p if (this.client.getGlobalStringPath() == null) { throw new IllegalArgumentException("Parameter this.client.getGlobalStringPath() is required and cannot be null."); } - String localStringQuery = null; - String pathItemStringQuery = null; + final String localStringQuery = null; + final String pathItemStringQuery = null; Call call = service.getGlobalQueryNull(localStringPath, pathItemStringPath, this.client.getGlobalStringPath(), localStringQuery, pathItemStringQuery, this.client.getGlobalStringQuery()); return getGlobalQueryNullDelegate(call.execute()); } @@ -377,8 +377,8 @@ public ServiceResponse getGlobalAndLocalQueryNull(String localStringPath, if (this.client.getGlobalStringPath() == null) { throw new IllegalArgumentException("Parameter this.client.getGlobalStringPath() is required and cannot be null."); } - String localStringQuery = null; - String pathItemStringQuery = null; + final String localStringQuery = null; + final String pathItemStringQuery = null; Call call = service.getGlobalAndLocalQueryNull(localStringPath, pathItemStringPath, this.client.getGlobalStringPath(), localStringQuery, pathItemStringQuery, this.client.getGlobalStringQuery()); return getGlobalAndLocalQueryNullDelegate(call.execute()); } @@ -520,8 +520,8 @@ public ServiceResponse getLocalPathItemQueryNull(String localStringPath, S if (this.client.getGlobalStringPath() == null) { throw new IllegalArgumentException("Parameter this.client.getGlobalStringPath() is required and cannot be null."); } - String localStringQuery = null; - String pathItemStringQuery = null; + final String localStringQuery = null; + final String pathItemStringQuery = null; Call call = service.getLocalPathItemQueryNull(localStringPath, pathItemStringPath, this.client.getGlobalStringPath(), localStringQuery, pathItemStringQuery, this.client.getGlobalStringQuery()); return getLocalPathItemQueryNullDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathsOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathsOperationsImpl.java index 16218b0597..0786c24f6b 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathsOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/PathsOperationsImpl.java @@ -158,7 +158,7 @@ interface PathsService { * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getBooleanTrue() throws ErrorException, IOException { - boolean boolPath = true; + final boolean boolPath = true; Call call = service.getBooleanTrue(boolPath); return getBooleanTrueDelegate(call.execute()); } @@ -205,7 +205,7 @@ private ServiceResponse getBooleanTrueDelegate(Response resp * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getBooleanFalse() throws ErrorException, IOException { - boolean boolPath = false; + final boolean boolPath = false; Call call = service.getBooleanFalse(boolPath); return getBooleanFalseDelegate(call.execute()); } @@ -252,7 +252,7 @@ private ServiceResponse getBooleanFalseDelegate(Response res * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getIntOneMillion() throws ErrorException, IOException { - int intPath = 1000000; + final int intPath = 1000000; Call call = service.getIntOneMillion(intPath); return getIntOneMillionDelegate(call.execute()); } @@ -299,7 +299,7 @@ private ServiceResponse getIntOneMillionDelegate(Response re * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getIntNegativeOneMillion() throws ErrorException, IOException { - int intPath = -1000000; + final int intPath = -1000000; Call call = service.getIntNegativeOneMillion(intPath); return getIntNegativeOneMillionDelegate(call.execute()); } @@ -346,7 +346,7 @@ private ServiceResponse getIntNegativeOneMillionDelegate(Response getTenBillion() throws ErrorException, IOException { - long longPath = 10000000000L; + final long longPath = 10000000000L; Call call = service.getTenBillion(longPath); return getTenBillionDelegate(call.execute()); } @@ -393,7 +393,7 @@ private ServiceResponse getTenBillionDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getNegativeTenBillion() throws ErrorException, IOException { - long longPath = -10000000000L; + final long longPath = -10000000000L; Call call = service.getNegativeTenBillion(longPath); return getNegativeTenBillionDelegate(call.execute()); } @@ -440,7 +440,7 @@ private ServiceResponse getNegativeTenBillionDelegate(Response floatScientificPositive() throws ErrorException, IOException { - double floatPath = 1.034E+20; + final double floatPath = 1.034E+20; Call call = service.floatScientificPositive(floatPath); return floatScientificPositiveDelegate(call.execute()); } @@ -487,7 +487,7 @@ private ServiceResponse floatScientificPositiveDelegate(Response floatScientificNegative() throws ErrorException, IOException { - double floatPath = -1.034E-20; + final double floatPath = -1.034E-20; Call call = service.floatScientificNegative(floatPath); return floatScientificNegativeDelegate(call.execute()); } @@ -534,7 +534,7 @@ private ServiceResponse floatScientificNegativeDelegate(Response doubleDecimalPositive() throws ErrorException, IOException { - double doublePath = 9999999.999; + final double doublePath = 9999999.999; Call call = service.doubleDecimalPositive(doublePath); return doubleDecimalPositiveDelegate(call.execute()); } @@ -581,7 +581,7 @@ private ServiceResponse doubleDecimalPositiveDelegate(Response doubleDecimalNegative() throws ErrorException, IOException { - double doublePath = -9999999.999; + final double doublePath = -9999999.999; Call call = service.doubleDecimalNegative(doublePath); return doubleDecimalNegativeDelegate(call.execute()); } @@ -628,7 +628,7 @@ private ServiceResponse doubleDecimalNegativeDelegate(Response stringUnicode() throws ErrorException, IOException { - String stringPath = "啊齄丂狛狜隣郎隣兀﨩"; + final String stringPath = "啊齄丂狛狜隣郎隣兀﨩"; Call call = service.stringUnicode(stringPath); return stringUnicodeDelegate(call.execute()); } @@ -675,7 +675,7 @@ private ServiceResponse stringUnicodeDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse stringUrlEncoded() throws ErrorException, IOException { - String stringPath = "begin!*'();:@ &=+$,/?#[]end"; + final String stringPath = "begin!*'();:@ &=+$,/?#[]end"; Call call = service.stringUrlEncoded(stringPath); return stringUrlEncodedDelegate(call.execute()); } @@ -722,7 +722,7 @@ private ServiceResponse stringUrlEncodedDelegate(Response re * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse stringEmpty() throws ErrorException, IOException { - String stringPath = ""; + final String stringPath = ""; Call call = service.stringEmpty(stringPath); return stringEmptyDelegate(call.execute()); } @@ -989,7 +989,7 @@ private ServiceResponse byteMultiByteDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse byteEmpty() throws ErrorException, IOException { - byte[] bytePath = "".getBytes(); + final byte[] bytePath = "".getBytes(); Call call = service.byteEmpty(Base64.encodeBase64String(bytePath)); return byteEmptyDelegate(call.execute()); } @@ -1091,7 +1091,7 @@ private ServiceResponse byteNullDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse dateValid() throws ErrorException, IOException { - LocalDate datePath = LocalDate.parse("2012-01-01"); + final LocalDate datePath = LocalDate.parse("2012-01-01"); Call call = service.dateValid(this.client.getMapperAdapter().serializeRaw(datePath)); return dateValidDelegate(call.execute()); } @@ -1193,7 +1193,7 @@ private ServiceResponse dateNullDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse dateTimeValid() throws ErrorException, IOException { - DateTime dateTimePath = DateTime.parse("2012-01-01T01:01:01Z"); + final DateTime dateTimePath = DateTime.parse("2012-01-01T01:01:01Z"); Call call = service.dateTimeValid(this.client.getMapperAdapter().serializeRaw(dateTimePath)); return dateTimeValidDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/QueriesOperationsImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/QueriesOperationsImpl.java index 3fc4dc407d..864bbb1bad 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/QueriesOperationsImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/url/QueriesOperationsImpl.java @@ -205,7 +205,7 @@ interface QueriesService { * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getBooleanTrue() throws ErrorException, IOException { - boolean boolQuery = true; + final boolean boolQuery = true; Call call = service.getBooleanTrue(boolQuery); return getBooleanTrueDelegate(call.execute()); } @@ -252,7 +252,7 @@ private ServiceResponse getBooleanTrueDelegate(Response resp * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getBooleanFalse() throws ErrorException, IOException { - boolean boolQuery = false; + final boolean boolQuery = false; Call call = service.getBooleanFalse(boolQuery); return getBooleanFalseDelegate(call.execute()); } @@ -299,7 +299,7 @@ private ServiceResponse getBooleanFalseDelegate(Response res * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getBooleanNull() throws ErrorException, IOException { - Boolean boolQuery = null; + final Boolean boolQuery = null; Call call = service.getBooleanNull(boolQuery); return getBooleanNullDelegate(call.execute()); } @@ -386,7 +386,7 @@ private ServiceResponse getBooleanNullDelegate(Response resp * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getIntOneMillion() throws ErrorException, IOException { - int intQuery = 1000000; + final int intQuery = 1000000; Call call = service.getIntOneMillion(intQuery); return getIntOneMillionDelegate(call.execute()); } @@ -433,7 +433,7 @@ private ServiceResponse getIntOneMillionDelegate(Response re * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getIntNegativeOneMillion() throws ErrorException, IOException { - int intQuery = -1000000; + final int intQuery = -1000000; Call call = service.getIntNegativeOneMillion(intQuery); return getIntNegativeOneMillionDelegate(call.execute()); } @@ -480,7 +480,7 @@ private ServiceResponse getIntNegativeOneMillionDelegate(Response getIntNull() throws ErrorException, IOException { - Integer intQuery = null; + final Integer intQuery = null; Call call = service.getIntNull(intQuery); return getIntNullDelegate(call.execute()); } @@ -567,7 +567,7 @@ private ServiceResponse getIntNullDelegate(Response response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getTenBillion() throws ErrorException, IOException { - long longQuery = 10000000000L; + final long longQuery = 10000000000L; Call call = service.getTenBillion(longQuery); return getTenBillionDelegate(call.execute()); } @@ -614,7 +614,7 @@ private ServiceResponse getTenBillionDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getNegativeTenBillion() throws ErrorException, IOException { - long longQuery = -10000000000L; + final long longQuery = -10000000000L; Call call = service.getNegativeTenBillion(longQuery); return getNegativeTenBillionDelegate(call.execute()); } @@ -661,7 +661,7 @@ private ServiceResponse getNegativeTenBillionDelegate(Response getLongNull() throws ErrorException, IOException { - Long longQuery = null; + final Long longQuery = null; Call call = service.getLongNull(longQuery); return getLongNullDelegate(call.execute()); } @@ -748,7 +748,7 @@ private ServiceResponse getLongNullDelegate(Response respons * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse floatScientificPositive() throws ErrorException, IOException { - double floatQuery = 1.034E+20; + final double floatQuery = 1.034E+20; Call call = service.floatScientificPositive(floatQuery); return floatScientificPositiveDelegate(call.execute()); } @@ -795,7 +795,7 @@ private ServiceResponse floatScientificPositiveDelegate(Response floatScientificNegative() throws ErrorException, IOException { - double floatQuery = -1.034E-20; + final double floatQuery = -1.034E-20; Call call = service.floatScientificNegative(floatQuery); return floatScientificNegativeDelegate(call.execute()); } @@ -842,7 +842,7 @@ private ServiceResponse floatScientificNegativeDelegate(Response floatNull() throws ErrorException, IOException { - Double floatQuery = null; + final Double floatQuery = null; Call call = service.floatNull(floatQuery); return floatNullDelegate(call.execute()); } @@ -929,7 +929,7 @@ private ServiceResponse floatNullDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse doubleDecimalPositive() throws ErrorException, IOException { - double doubleQuery = 9999999.999; + final double doubleQuery = 9999999.999; Call call = service.doubleDecimalPositive(doubleQuery); return doubleDecimalPositiveDelegate(call.execute()); } @@ -976,7 +976,7 @@ private ServiceResponse doubleDecimalPositiveDelegate(Response doubleDecimalNegative() throws ErrorException, IOException { - double doubleQuery = -9999999.999; + final double doubleQuery = -9999999.999; Call call = service.doubleDecimalNegative(doubleQuery); return doubleDecimalNegativeDelegate(call.execute()); } @@ -1023,7 +1023,7 @@ private ServiceResponse doubleDecimalNegativeDelegate(Response doubleNull() throws ErrorException, IOException { - Double doubleQuery = null; + final Double doubleQuery = null; Call call = service.doubleNull(doubleQuery); return doubleNullDelegate(call.execute()); } @@ -1110,7 +1110,7 @@ private ServiceResponse doubleNullDelegate(Response response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse stringUnicode() throws ErrorException, IOException { - String stringQuery = "啊齄丂狛狜隣郎隣兀﨩"; + final String stringQuery = "啊齄丂狛狜隣郎隣兀﨩"; Call call = service.stringUnicode(stringQuery); return stringUnicodeDelegate(call.execute()); } @@ -1157,7 +1157,7 @@ private ServiceResponse stringUnicodeDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse stringUrlEncoded() throws ErrorException, IOException { - String stringQuery = "begin!*'();:@ &=+$,/?#[]end"; + final String stringQuery = "begin!*'();:@ &=+$,/?#[]end"; Call call = service.stringUrlEncoded(stringQuery); return stringUrlEncodedDelegate(call.execute()); } @@ -1204,7 +1204,7 @@ private ServiceResponse stringUrlEncodedDelegate(Response re * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse stringEmpty() throws ErrorException, IOException { - String stringQuery = ""; + final String stringQuery = ""; Call call = service.stringEmpty(stringQuery); return stringEmptyDelegate(call.execute()); } @@ -1251,7 +1251,7 @@ private ServiceResponse stringEmptyDelegate(Response respons * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse stringNull() throws ErrorException, IOException { - String stringQuery = null; + final String stringQuery = null; Call call = service.stringNull(stringQuery); return stringNullDelegate(call.execute()); } @@ -1338,7 +1338,7 @@ private ServiceResponse stringNullDelegate(Response response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse enumValid() throws ErrorException, IOException { - UriColor enumQuery = null; + final UriColor enumQuery = null; Call call = service.enumValid(this.client.getMapperAdapter().serializeRaw(enumQuery)); return enumValidDelegate(call.execute()); } @@ -1425,7 +1425,7 @@ private ServiceResponse enumValidDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse enumNull() throws ErrorException, IOException { - UriColor enumQuery = null; + final UriColor enumQuery = null; Call call = service.enumNull(this.client.getMapperAdapter().serializeRaw(enumQuery)); return enumNullDelegate(call.execute()); } @@ -1512,7 +1512,7 @@ private ServiceResponse enumNullDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse byteMultiByte() throws ErrorException, IOException { - byte[] byteQuery = null; + final byte[] byteQuery = null; Call call = service.byteMultiByte(Base64.encodeBase64String(byteQuery)); return byteMultiByteDelegate(call.execute()); } @@ -1599,7 +1599,7 @@ private ServiceResponse byteMultiByteDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse byteEmpty() throws ErrorException, IOException { - byte[] byteQuery = "".getBytes(); + final byte[] byteQuery = "".getBytes(); Call call = service.byteEmpty(Base64.encodeBase64String(byteQuery)); return byteEmptyDelegate(call.execute()); } @@ -1646,7 +1646,7 @@ private ServiceResponse byteEmptyDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse byteNull() throws ErrorException, IOException { - byte[] byteQuery = null; + final byte[] byteQuery = null; Call call = service.byteNull(Base64.encodeBase64String(byteQuery)); return byteNullDelegate(call.execute()); } @@ -1733,7 +1733,7 @@ private ServiceResponse byteNullDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse dateValid() throws ErrorException, IOException { - LocalDate dateQuery = LocalDate.parse("2012-01-01"); + final LocalDate dateQuery = LocalDate.parse("2012-01-01"); Call call = service.dateValid(this.client.getMapperAdapter().serializeRaw(dateQuery)); return dateValidDelegate(call.execute()); } @@ -1780,7 +1780,7 @@ private ServiceResponse dateValidDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse dateNull() throws ErrorException, IOException { - LocalDate dateQuery = null; + final LocalDate dateQuery = null; Call call = service.dateNull(this.client.getMapperAdapter().serializeRaw(dateQuery)); return dateNullDelegate(call.execute()); } @@ -1867,7 +1867,7 @@ private ServiceResponse dateNullDelegate(Response response) * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse dateTimeValid() throws ErrorException, IOException { - DateTime dateTimeQuery = DateTime.parse("2012-01-01T01:01:01Z"); + final DateTime dateTimeQuery = DateTime.parse("2012-01-01T01:01:01Z"); Call call = service.dateTimeValid(this.client.getMapperAdapter().serializeRaw(dateTimeQuery)); return dateTimeValidDelegate(call.execute()); } @@ -1914,7 +1914,7 @@ private ServiceResponse dateTimeValidDelegate(Response respo * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse dateTimeNull() throws ErrorException, IOException { - DateTime dateTimeQuery = null; + final DateTime dateTimeQuery = null; Call call = service.dateTimeNull(this.client.getMapperAdapter().serializeRaw(dateTimeQuery)); return dateTimeNullDelegate(call.execute()); } @@ -2001,7 +2001,7 @@ private ServiceResponse dateTimeNullDelegate(Response respon * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse arrayStringCsvValid() throws ErrorException, IOException { - List arrayQuery = null; + final List arrayQuery = null; Call call = service.arrayStringCsvValid(this.client.getMapperAdapter().serializeList(arrayQuery, CollectionFormat.CSV)); return arrayStringCsvValidDelegate(call.execute()); } @@ -2090,7 +2090,7 @@ private ServiceResponse arrayStringCsvValidDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse arrayStringCsvNull() throws ErrorException, IOException { - List arrayQuery = null; + final List arrayQuery = null; Call call = service.arrayStringCsvNull(this.client.getMapperAdapter().serializeList(arrayQuery, CollectionFormat.CSV)); return arrayStringCsvNullDelegate(call.execute()); } @@ -2179,7 +2179,7 @@ private ServiceResponse arrayStringCsvNullDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse arrayStringCsvEmpty() throws ErrorException, IOException { - List arrayQuery = null; + final List arrayQuery = null; Call call = service.arrayStringCsvEmpty(this.client.getMapperAdapter().serializeList(arrayQuery, CollectionFormat.CSV)); return arrayStringCsvEmptyDelegate(call.execute()); } @@ -2268,7 +2268,7 @@ private ServiceResponse arrayStringCsvEmptyDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse arrayStringSsvValid() throws ErrorException, IOException { - List arrayQuery = null; + final List arrayQuery = null; Call call = service.arrayStringSsvValid(this.client.getMapperAdapter().serializeList(arrayQuery, CollectionFormat.SSV)); return arrayStringSsvValidDelegate(call.execute()); } @@ -2357,7 +2357,7 @@ private ServiceResponse arrayStringSsvValidDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse arrayStringTsvValid() throws ErrorException, IOException { - List arrayQuery = null; + final List arrayQuery = null; Call call = service.arrayStringTsvValid(this.client.getMapperAdapter().serializeList(arrayQuery, CollectionFormat.TSV)); return arrayStringTsvValidDelegate(call.execute()); } @@ -2446,7 +2446,7 @@ private ServiceResponse arrayStringTsvValidDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse arrayStringPipesValid() throws ErrorException, IOException { - List arrayQuery = null; + final List arrayQuery = null; Call call = service.arrayStringPipesValid(this.client.getMapperAdapter().serializeList(arrayQuery, CollectionFormat.PIPES)); return arrayStringPipesValidDelegate(call.execute()); } diff --git a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/validation/AutoRestValidationTestImpl.java b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/validation/AutoRestValidationTestImpl.java index f3b2b8b089..e063d58222 100644 --- a/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/validation/AutoRestValidationTestImpl.java +++ b/AutoRest/Generators/Java/Java.Tests/src/main/java/fixtures/validation/AutoRestValidationTestImpl.java @@ -270,7 +270,7 @@ public ServiceResponse validationOfBody(String resourceGroupName, int i if (this.getApiVersion() == null) { throw new IllegalArgumentException("Parameter this.getApiVersion() is required and cannot be null."); } - Product body = null; + final Product body = null; Call call = service.validationOfBody(this.getSubscriptionId(), resourceGroupName, id, body, this.getApiVersion()); return validationOfBodyDelegate(call.execute()); } @@ -398,7 +398,7 @@ private ServiceResponse validationOfBodyDelegate(Response * @return the {@link ServiceResponse} object if successful. */ public ServiceResponse getWithConstantInPath() throws ServiceException, IOException { - String constantParam = "constant"; + final String constantParam = "constant"; Call call = service.getWithConstantInPath(constantParam); return getWithConstantInPathDelegate(call.execute()); } @@ -442,8 +442,8 @@ private ServiceResponse getWithConstantInPathDelegate(Response postWithConstantInBody() throws ServiceException, IOException { - String constantParam = "constant"; - Product body = null; + final String constantParam = "constant"; + final Product body = null; Call call = service.postWithConstantInBody(constantParam, body); return postWithConstantInBodyDelegate(call.execute()); } @@ -484,7 +484,7 @@ public void onResponse(Call call, Response response) */ public ServiceResponse postWithConstantInBody(Product body) throws ServiceException, IOException { Validator.validate(body); - String constantParam = "constant"; + final String constantParam = "constant"; Call call = service.postWithConstantInBody(constantParam, body); return postWithConstantInBodyDelegate(call.execute()); } diff --git a/Samples/petstore/Java/SwaggerPetstore.java b/Samples/petstore/Java/SwaggerPetstore.java index 1bff703e70..2dd3d2755d 100644 --- a/Samples/petstore/Java/SwaggerPetstore.java +++ b/Samples/petstore/Java/SwaggerPetstore.java @@ -52,6 +52,23 @@ public interface SwaggerPetstore { */ JacksonMapperAdapter getMapperAdapter(); + /** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse addPetUsingByteArray() throws ServiceException, IOException; + + /** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall addPetUsingByteArrayAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Fake endpoint to test byte array in body parameter for adding a new pet to the store. * @@ -72,6 +89,23 @@ public interface SwaggerPetstore { */ ServiceCall addPetUsingByteArrayAsync(String body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Add a new pet to the store. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse addPet() throws ServiceException, IOException; + + /** + * Add a new pet to the store. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall addPetAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Add a new pet to the store. * @@ -92,6 +126,23 @@ public interface SwaggerPetstore { */ ServiceCall addPetAsync(Pet body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Update an existing pet. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse updatePet() throws ServiceException, IOException; + + /** + * Update an existing pet. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall updatePetAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Update an existing pet. * @@ -112,6 +163,25 @@ public interface SwaggerPetstore { */ ServiceCall updatePetAsync(Pet body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Finds Pets by status. + * Multiple status values can be provided with comma seperated strings. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the List<Pet> object wrapped in {@link ServiceResponse} if successful. + */ + ServiceResponse> findPetsByStatus() throws ServiceException, IOException; + + /** + * Finds Pets by status. + * Multiple status values can be provided with comma seperated strings. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall findPetsByStatusAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; /** * Finds Pets by status. * Multiple status values can be provided with comma seperated strings. @@ -134,6 +204,25 @@ public interface SwaggerPetstore { */ ServiceCall findPetsByStatusAsync(List status, final ServiceCallback> serviceCallback) throws IllegalArgumentException; + /** + * Finds Pets by tags. + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the List<Pet> object wrapped in {@link ServiceResponse} if successful. + */ + ServiceResponse> findPetsByTags() throws ServiceException, IOException; + + /** + * Finds Pets by tags. + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall findPetsByTagsAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; /** * Finds Pets by tags. * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. @@ -200,6 +289,26 @@ public interface SwaggerPetstore { */ ServiceCall getPetByIdAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Updates a pet in the store with form data. + * + * @param petId ID of pet that needs to be updated + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse updatePetWithForm(String petId) throws ServiceException, IOException, IllegalArgumentException; + + /** + * Updates a pet in the store with form data. + * + * @param petId ID of pet that needs to be updated + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall updatePetWithFormAsync(String petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Updates a pet in the store with form data. * @@ -225,6 +334,25 @@ public interface SwaggerPetstore { */ ServiceCall updatePetWithFormAsync(String petId, String name, String status, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse deletePet(long petId) throws ServiceException, IOException; + + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall deletePetAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Deletes a pet. * @@ -247,6 +375,25 @@ public interface SwaggerPetstore { */ ServiceCall deletePetAsync(long petId, String apiKey, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * uploads an image. + * + * @param petId ID of pet to update + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse uploadFile(long petId) throws ServiceException, IOException; + + /** + * uploads an image. + * + * @param petId ID of pet to update + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall uploadFileAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * uploads an image. * @@ -291,6 +438,23 @@ public interface SwaggerPetstore { */ ServiceCall getInventoryAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException; + /** + * Place an order for a pet. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the Order object wrapped in {@link ServiceResponse} if successful. + */ + ServiceResponse placeOrder() throws ServiceException, IOException; + + /** + * Place an order for a pet. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall placeOrderAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Place an order for a pet. * @@ -357,6 +521,25 @@ public interface SwaggerPetstore { */ ServiceCall deleteOrderAsync(String orderId, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Create user. + * This can only be done by the logged in user. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse createUser() throws ServiceException, IOException; + + /** + * Create user. + * This can only be done by the logged in user. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall createUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Create user. * This can only be done by the logged in user. @@ -379,6 +562,23 @@ public interface SwaggerPetstore { */ ServiceCall createUserAsync(User body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Creates list of users with given input array. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse createUsersWithArrayInput() throws ServiceException, IOException; + + /** + * Creates list of users with given input array. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall createUsersWithArrayInputAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Creates list of users with given input array. * @@ -399,6 +599,23 @@ public interface SwaggerPetstore { */ ServiceCall createUsersWithArrayInputAsync(List body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Creates list of users with given input array. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse createUsersWithListInput() throws ServiceException, IOException; + + /** + * Creates list of users with given input array. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall createUsersWithListInputAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Creates list of users with given input array. * @@ -419,6 +636,23 @@ public interface SwaggerPetstore { */ ServiceCall createUsersWithListInputAsync(List body, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Logs user into the system. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the String object wrapped in {@link ServiceResponse} if successful. + */ + ServiceResponse loginUser() throws ServiceException, IOException; + + /** + * Logs user into the system. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall loginUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Logs user into the system. * @@ -480,6 +714,28 @@ public interface SwaggerPetstore { */ ServiceCall getUserByNameAsync(String username, final ServiceCallback serviceCallback) throws IllegalArgumentException; + /** + * Updated user. + * This can only be done by the logged in user. + * + * @param username name that need to be deleted + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + ServiceResponse updateUser(String username) throws ServiceException, IOException, IllegalArgumentException; + + /** + * Updated user. + * This can only be done by the logged in user. + * + * @param username name that need to be deleted + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link ServiceCall} object + */ + ServiceCall updateUserAsync(String username, final ServiceCallback serviceCallback) throws IllegalArgumentException; /** * Updated user. * This can only be done by the logged in user. diff --git a/Samples/petstore/Java/SwaggerPetstoreImpl.java b/Samples/petstore/Java/SwaggerPetstoreImpl.java index 0e7fa0defa..cb89c101fc 100644 --- a/Samples/petstore/Java/SwaggerPetstoreImpl.java +++ b/Samples/petstore/Java/SwaggerPetstoreImpl.java @@ -209,6 +209,46 @@ interface SwaggerPetstoreService { } + /** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse addPetUsingByteArray() throws ServiceException, IOException { + final String body = null; + Call call = service.addPetUsingByteArray(body); + return addPetUsingByteArrayDelegate(call.execute()); + } + + /** + * Fake endpoint to test byte array in body parameter for adding a new pet to the store. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall addPetUsingByteArrayAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final String body = null; + Call call = service.addPetUsingByteArray(body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(addPetUsingByteArrayDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Fake endpoint to test byte array in body parameter for adding a new pet to the store. * @@ -255,6 +295,46 @@ private ServiceResponse addPetUsingByteArrayDelegate(Response addPet() throws ServiceException, IOException { + final Pet body = null; + Call call = service.addPet(body); + return addPetDelegate(call.execute()); + } + + /** + * Add a new pet to the store. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall addPetAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final Pet body = null; + Call call = service.addPet(body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(addPetDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Add a new pet to the store. * @@ -303,6 +383,46 @@ private ServiceResponse addPetDelegate(Response response) th .build(response); } + /** + * Update an existing pet. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updatePet() throws ServiceException, IOException { + final Pet body = null; + Call call = service.updatePet(body); + return updatePetDelegate(call.execute()); + } + + /** + * Update an existing pet. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall updatePetAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final Pet body = null; + Call call = service.updatePet(body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(updatePetDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Update an existing pet. * @@ -353,6 +473,48 @@ private ServiceResponse updatePetDelegate(Response response) .build(response); } + /** + * Finds Pets by status. + * Multiple status values can be provided with comma seperated strings. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the List<Pet> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> findPetsByStatus() throws ServiceException, IOException { + final List status = null; + Call call = service.findPetsByStatus(this.getMapperAdapter().serializeList(status, CollectionFormat.CSV)); + return findPetsByStatusDelegate(call.execute()); + } + + /** + * Finds Pets by status. + * Multiple status values can be provided with comma seperated strings. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall findPetsByStatusAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final List status = null; + Call call = service.findPetsByStatus(this.getMapperAdapter().serializeList(status, CollectionFormat.CSV)); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(findPetsByStatusDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Finds Pets by status. * Multiple status values can be provided with comma seperated strings. @@ -404,6 +566,48 @@ private ServiceResponse> findPetsByStatusDelegate(Response> findPetsByTags() throws ServiceException, IOException { + final List tags = null; + Call call = service.findPetsByTags(this.getMapperAdapter().serializeList(tags, CollectionFormat.CSV)); + return findPetsByTagsDelegate(call.execute()); + } + + /** + * Finds Pets by tags. + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall findPetsByTagsAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final List tags = null; + Call call = service.findPetsByTags(this.getMapperAdapter().serializeList(tags, CollectionFormat.CSV)); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(findPetsByTagsDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Finds Pets by tags. * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. @@ -555,6 +759,58 @@ private ServiceResponse getPetByIdDelegate(Response response) .build(response); } + /** + * Updates a pet in the store with form data. + * + * @param petId ID of pet that needs to be updated + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updatePetWithForm(String petId) throws ServiceException, IOException, IllegalArgumentException { + if (petId == null) { + throw new IllegalArgumentException("Parameter petId is required and cannot be null."); + } + final String name = null; + final String status = null; + Call call = service.updatePetWithForm(petId, name, status); + return updatePetWithFormDelegate(call.execute()); + } + + /** + * Updates a pet in the store with form data. + * + * @param petId ID of pet that needs to be updated + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall updatePetWithFormAsync(String petId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (petId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter petId is required and cannot be null.")); + return null; + } + final String name = null; + final String status = null; + Call call = service.updatePetWithForm(petId, name, status); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(updatePetWithFormDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Updates a pet in the store with form data. * @@ -614,39 +870,131 @@ private ServiceResponse updatePetWithFormDelegate(Response r } /** - * Deletes a pet. + * Deletes a pet. + * + * @param petId Pet id to delete + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse deletePet(long petId) throws ServiceException, IOException { + final String apiKey = null; + Call call = service.deletePet(petId, apiKey); + return deletePetDelegate(call.execute()); + } + + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall deletePetAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final String apiKey = null; + Call call = service.deletePet(petId, apiKey); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(deletePetDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @param apiKey + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse deletePet(long petId, String apiKey) throws ServiceException, IOException { + Call call = service.deletePet(petId, apiKey); + return deletePetDelegate(call.execute()); + } + + /** + * Deletes a pet. + * + * @param petId Pet id to delete + * @param apiKey + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall deletePetAsync(long petId, String apiKey, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + Call call = service.deletePet(petId, apiKey); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(deletePetDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse deletePetDelegate(Response response) throws ServiceException, IOException { + return new ServiceResponseBuilder(this.getMapperAdapter()) + .register(400, new TypeToken() { }.getType()) + .build(response); + } + + /** + * uploads an image. * - * @param petId Pet id to delete - * @param apiKey + * @param petId ID of pet to update * @throws ServiceException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse deletePet(long petId, String apiKey) throws ServiceException, IOException { - Call call = service.deletePet(petId, apiKey); - return deletePetDelegate(call.execute()); + public ServiceResponse uploadFile(long petId) throws ServiceException, IOException { + final String additionalMetadata = null; + final InputStream file = null; + Call call = service.uploadFile(petId, additionalMetadata, file); + return uploadFileDelegate(call.execute()); } /** - * Deletes a pet. + * uploads an image. * - * @param petId Pet id to delete - * @param apiKey + * @param petId ID of pet to update * @param serviceCallback the async ServiceCallback to handle successful and failed responses. * @throws IllegalArgumentException thrown if callback is null * @return the {@link Call} object */ - public ServiceCall deletePetAsync(long petId, String apiKey, final ServiceCallback serviceCallback) throws IllegalArgumentException { + public ServiceCall uploadFileAsync(long petId, final ServiceCallback serviceCallback) throws IllegalArgumentException { if (serviceCallback == null) { throw new IllegalArgumentException("ServiceCallback is required for async calls."); } - Call call = service.deletePet(petId, apiKey); + final String additionalMetadata = null; + final InputStream file = null; + Call call = service.uploadFile(petId, additionalMetadata, file); final ServiceCall serviceCall = new ServiceCall(call); call.enqueue(new ServiceResponseCallback(serviceCallback) { @Override public void onResponse(Call call, Response response) { try { - serviceCallback.success(deletePetDelegate(response)); + serviceCallback.success(uploadFileDelegate(response)); } catch (ServiceException | IOException exception) { serviceCallback.failure(exception); } @@ -655,12 +1003,6 @@ public void onResponse(Call call, Response response) return serviceCall; } - private ServiceResponse deletePetDelegate(Response response) throws ServiceException, IOException { - return new ServiceResponseBuilder(this.getMapperAdapter()) - .register(400, new TypeToken() { }.getType()) - .build(response); - } - /** * uploads an image. * @@ -756,6 +1098,46 @@ private ServiceResponse> getInventoryDelegate(Response placeOrder() throws ServiceException, IOException { + final Order body = null; + Call call = service.placeOrder(body); + return placeOrderDelegate(call.execute()); + } + + /** + * Place an order for a pet. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall placeOrderAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final Order body = null; + Call call = service.placeOrder(body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(placeOrderDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Place an order for a pet. * @@ -920,6 +1302,48 @@ private ServiceResponse deleteOrderDelegate(Response respons .build(response); } + /** + * Create user. + * This can only be done by the logged in user. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse createUser() throws ServiceException, IOException { + final User body = null; + Call call = service.createUser(body); + return createUserDelegate(call.execute()); + } + + /** + * Create user. + * This can only be done by the logged in user. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final User body = null; + Call call = service.createUser(body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createUserDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Create user. * This can only be done by the logged in user. @@ -969,6 +1393,46 @@ private ServiceResponse createUserDelegate(Response response .build(response); } + /** + * Creates list of users with given input array. + * + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse createUsersWithArrayInput() throws ServiceException, IOException { + final List body = null; + Call call = service.createUsersWithArrayInput(body); + return createUsersWithArrayInputDelegate(call.execute()); + } + + /** + * Creates list of users with given input array. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createUsersWithArrayInputAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final List body = null; + Call call = service.createUsersWithArrayInput(body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createUsersWithArrayInputDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Creates list of users with given input array. * @@ -1016,6 +1480,46 @@ private ServiceResponse createUsersWithArrayInputDelegate(Response createUsersWithListInput() throws ServiceException, IOException { + final List body = null; + Call call = service.createUsersWithListInput(body); + return createUsersWithListInputDelegate(call.execute()); + } + + /** + * Creates list of users with given input array. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createUsersWithListInputAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final List body = null; + Call call = service.createUsersWithListInput(body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createUsersWithListInputDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Creates list of users with given input array. * @@ -1063,6 +1567,48 @@ private ServiceResponse createUsersWithListInputDelegate(Response loginUser() throws ServiceException, IOException { + final String username = null; + final String password = null; + Call call = service.loginUser(username, password); + return loginUserDelegate(call.execute()); + } + + /** + * Logs user into the system. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall loginUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + final String username = null; + final String password = null; + Call call = service.loginUser(username, password); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(loginUserDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Logs user into the system. * @@ -1211,6 +1757,58 @@ private ServiceResponse getUserByNameDelegate(Response respo .build(response); } + /** + * Updated user. + * This can only be done by the logged in user. + * + * @param username name that need to be deleted + * @throws ServiceException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse updateUser(String username) throws ServiceException, IOException, IllegalArgumentException { + if (username == null) { + throw new IllegalArgumentException("Parameter username is required and cannot be null."); + } + final User body = null; + Call call = service.updateUser(username, body); + return updateUserDelegate(call.execute()); + } + + /** + * Updated user. + * This can only be done by the logged in user. + * + * @param username name that need to be deleted + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall updateUserAsync(String username, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (username == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter username is required and cannot be null.")); + return null; + } + final User body = null; + Call call = service.updateUser(username, body); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(updateUserDelegate(response)); + } catch (ServiceException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + /** * Updated user. * This can only be done by the logged in user. From 2b47ec98f5dd737fad6017c57ee0a30db5300cc2 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 18 Mar 2016 17:43:00 -0700 Subject: [PATCH 7/7] Add missing javadoc --- .../src/main/java/com/microsoft/azure/PagedList.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index 5f1676ff2b..8c42851d4e 100644 --- a/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/ClientRuntimes/Java/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -49,10 +49,19 @@ public PagedList(Page page) { */ public abstract Page nextPage(String nextPageLink) throws CloudException, IOException; + /** + * If there are more pages available. + * + * @return true if there are more pages to load. False otherwise. + */ public boolean hasNextPage() { return this.nextPageLink != null; } + /** + * Loads a page from next page link. + * The exceptions are wrapped into Java Runtime exceptions. + */ public void loadNextPage() { try { Page nextPage = nextPage(this.nextPageLink);