1515import java .io .*;
1616import java .nio .charset .StandardCharsets ;
1717import java .util .*;
18- import java . util . concurrent . CompletableFuture ;
18+
1919
2020/**
2121 * A class representing the content of a batch request response.
@@ -49,9 +49,9 @@ public BatchResponseContent(@Nonnull Response batchResponse, @Nullable Map<Strin
4949 * @return The responses of the batch request.
5050 */
5151 @ Nonnull
52- public CompletableFuture < HashMap <String , Response > > getResponses () {
52+ public HashMap <String , Response > getResponses () {
5353 HashMap <String , Response > responses = new HashMap <>();
54- jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent (). join () ;
54+ jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent ();
5555 if (jsonBatchResponseObject != null ) {
5656 JsonElement responsesElement = jsonBatchResponseObject .get (CoreConstants .BatchRequest .RESPONSES );
5757 if (responsesElement != null && responsesElement .isJsonArray ()) { //ensure "responses" is not null and is an array.
@@ -61,16 +61,16 @@ public CompletableFuture<HashMap<String, Response>> getResponses() {
6161 }
6262 }
6363 }
64- return CompletableFuture . completedFuture ( responses ) ;
64+ return responses ;
6565 }
6666 /**
6767 * Gets the status codes of the responses of the batch request.
6868 * @return The status codes of the responses of the batch request.
6969 */
7070 @ Nonnull
71- public CompletableFuture < HashMap <String , Integer > > getResponsesStatusCode () {
71+ public HashMap <String , Integer > getResponsesStatusCode () {
7272 HashMap <String , Integer > statusCodes = new HashMap <>();
73- jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent (). join () ;
73+ jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent ();
7474 if (jsonBatchResponseObject != null ) {
7575 JsonElement responsesElement = jsonBatchResponseObject .get (CoreConstants .BatchRequest .RESPONSES );
7676 if (responsesElement != null && responsesElement .isJsonArray ()) { //ensure "responses" is not null and is an array.
@@ -80,31 +80,31 @@ public CompletableFuture<HashMap<String, Integer>> getResponsesStatusCode() {
8080 }
8181 }
8282 }
83- return CompletableFuture . completedFuture ( statusCodes ) ;
83+ return statusCodes ;
8484 }
8585 /**
8686 * Gets the response within the batch response via specified id.
8787 * @param requestId The id of the request.
8888 * @return The response within the batch response via specified id, null if not found.
8989 */
9090 @ Nullable
91- public CompletableFuture < Response > getResponseById (@ Nonnull String requestId ) {
91+ public Response getResponseById (@ Nonnull String requestId ) {
9292 Objects .requireNonNull (requestId );
9393 if (!requestId .isEmpty ()) {
94- jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent (). join () ;
94+ jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent ();
9595 if (jsonBatchResponseObject != null ) {
9696 JsonElement responsesElement = jsonBatchResponseObject .get (CoreConstants .BatchRequest .RESPONSES );
9797 if (responsesElement != null && responsesElement .isJsonArray ()) { //ensure "responses" is not null and is an array.
9898 JsonArray responsesArray = responsesElement .getAsJsonArray ();
9999 for (JsonElement responseElement : responsesArray ) {
100100 if (responseElement .getAsJsonObject ().get ("id" ).getAsString ().equals (requestId )) {
101- return CompletableFuture . completedFuture ( getResponseFromJsonObject (responseElement ) );
101+ return getResponseFromJsonObject (responseElement );
102102 }
103103 }
104104 }
105105 }
106106 }
107- return CompletableFuture . completedFuture ( null ) ;
107+ return null ;
108108 }
109109 /**
110110 * Gets the response within the batch response via specified id.
@@ -114,12 +114,12 @@ public CompletableFuture<Response> getResponseById(@Nonnull String requestId) {
114114 * @param <T> The type of the response body.
115115 */
116116 @ Nullable
117- public <T extends Parsable > CompletableFuture < T > getResponseById (@ Nonnull String requestId , @ Nonnull ResponseHandler responseHandler ) {
118- Response response = getResponseById (requestId ). join () ;
117+ public <T extends Parsable > T getResponseById (@ Nonnull String requestId , @ Nonnull ResponseHandler responseHandler ) {
118+ Response response = getResponseById (requestId );
119119 if (response == null ) {
120- return CompletableFuture . completedFuture ( null ) ;
120+ return null ;
121121 }
122- return responseHandler .handleResponseAsync (response , apiErrorMappings );
122+ return responseHandler .handleResponse (response , apiErrorMappings );
123123 }
124124 /**
125125 * Gets the response within the batch response via specified id.
@@ -129,7 +129,7 @@ public <T extends Parsable> CompletableFuture<T> getResponseById(@Nonnull String
129129 * @param <T> The type of the response body.
130130 */
131131 @ Nullable
132- public <T extends Parsable > CompletableFuture < T > getResponseById (@ Nonnull String requestId , @ Nonnull ParsableFactory <T > factory ) {
132+ public <T extends Parsable > T getResponseById (@ Nonnull String requestId , @ Nonnull ParsableFactory <T > factory ) {
133133 return this .getResponseById (requestId , new ResponseBodyHandler <>(factory ));
134134 }
135135 /**
@@ -138,39 +138,39 @@ public <T extends Parsable> CompletableFuture<T> getResponseById(@Nonnull String
138138 * @return The response within the batch response via specified id as an InputStream, null if not found.
139139 */
140140 @ Nullable
141- public CompletableFuture < InputStream > getResponseStreamById (@ Nonnull String requestId ) {
142- Response response = getResponseById (requestId ). join () ;
141+ public InputStream getResponseStreamById (@ Nonnull String requestId ) {
142+ Response response = getResponseById (requestId );
143143 if (response != null && response .body () != null ) {
144144 InputStream in = response .body ().byteStream ();
145- return CompletableFuture . completedFuture ( in ) ;
145+ return in ;
146146 }
147- return CompletableFuture . completedFuture ( null ) ;
147+ return null ;
148148 }
149149 /**
150150 * Get the next link of the batch response.
151151 * @return The next link of the batch response.
152152 */
153153 @ Nullable
154- public CompletableFuture < String > getNextLink () {
155- jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent (). join () ;
154+ public String getNextLink () {
155+ jsonBatchResponseObject = jsonBatchResponseObject != null ? jsonBatchResponseObject : getBatchResponseContent ();
156156 if (jsonBatchResponseObject != null ) {
157157 JsonElement nextLinkElement = jsonBatchResponseObject .get (CoreConstants .Serialization .ODATA_NEXT_LINK );
158158 if (nextLinkElement != null && nextLinkElement .isJsonPrimitive ()) {
159- return CompletableFuture . completedFuture ( nextLinkElement .getAsString () );
159+ return nextLinkElement .getAsString ();
160160 }
161161 }
162- return CompletableFuture . completedFuture ( null ) ;
162+ return null ;
163163 }
164- private CompletableFuture < JsonObject > getBatchResponseContent () {
164+ private JsonObject getBatchResponseContent () {
165165 if (this .batchResponse .body () != null && this .batchResponse .body ().contentType () != null ) {
166166 InputStream in = this .batchResponse .body ().byteStream ();
167167 try (InputStreamReader reader = new InputStreamReader (in , StandardCharsets .UTF_8 )) {
168- return CompletableFuture . completedFuture ( JsonParser .parseReader (reader ).getAsJsonObject () );
168+ return JsonParser .parseReader (reader ).getAsJsonObject ();
169169 } catch (IOException e ) {
170- return CompletableFuture . completedFuture ( null ) ;
170+ return null ;
171171 }
172172 }
173- return CompletableFuture . completedFuture ( null ) ;
173+ return null ;
174174 }
175175 private Response getResponseFromJsonObject (JsonElement responseElement ) {
176176 Response .Builder response = new Response .Builder ();
0 commit comments