1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.dialogflow.v2beta1; 18 19 import com.google.api.core.ApiFuture; 20 import com.google.api.core.ApiFutures; 21 import com.google.api.core.BetaApi; 22 import com.google.api.gax.core.BackgroundResource; 23 import com.google.api.gax.paging.AbstractFixedSizeCollection; 24 import com.google.api.gax.paging.AbstractPage; 25 import com.google.api.gax.paging.AbstractPagedListResponse; 26 import com.google.api.gax.rpc.PageContext; 27 import com.google.api.gax.rpc.UnaryCallable; 28 import com.google.cloud.dialogflow.v2beta1.stub.FulfillmentsStub; 29 import com.google.cloud.dialogflow.v2beta1.stub.FulfillmentsStubSettings; 30 import com.google.cloud.location.GetLocationRequest; 31 import com.google.cloud.location.ListLocationsRequest; 32 import com.google.cloud.location.ListLocationsResponse; 33 import com.google.cloud.location.Location; 34 import com.google.common.util.concurrent.MoreExecutors; 35 import com.google.protobuf.FieldMask; 36 import java.io.IOException; 37 import java.util.List; 38 import java.util.concurrent.TimeUnit; 39 import javax.annotation.Generated; 40 41 // AUTO-GENERATED DOCUMENTATION AND CLASS. 42 /** 43 * Service Description: Service for managing 44 * [Fulfillments][google.cloud.dialogflow.v2beta1.Fulfillment]. 45 * 46 * <p>This class provides the ability to make remote calls to the backing service through method 47 * calls that map to API methods. Sample code to get started: 48 * 49 * <pre>{@code 50 * // This snippet has been automatically generated and should be regarded as a code template only. 51 * // It will require modifications to work: 52 * // - It may require correct/in-range values for request initialization. 53 * // - It may require specifying regional endpoints when creating the service client as shown in 54 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 55 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 56 * FulfillmentName name = FulfillmentName.ofProjectName("[PROJECT]"); 57 * Fulfillment response = fulfillmentsClient.getFulfillment(name); 58 * } 59 * }</pre> 60 * 61 * <p>Note: close() needs to be called on the FulfillmentsClient object to clean up resources such 62 * as threads. In the example above, try-with-resources is used, which automatically calls close(). 63 * 64 * <p>The surface of this class includes several types of Java methods for each of the API's 65 * methods: 66 * 67 * <ol> 68 * <li>A "flattened" method. With this type of method, the fields of the request type have been 69 * converted into function parameters. It may be the case that not all fields are available as 70 * parameters, and not every API method will have a flattened method entry point. 71 * <li>A "request object" method. This type of method only takes one parameter, a request object, 72 * which must be constructed before the call. Not every API method will have a request object 73 * method. 74 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 75 * callable object, which can be used to initiate calls to the service. 76 * </ol> 77 * 78 * <p>See the individual methods for example code. 79 * 80 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 81 * these names, this class includes a format method for each type of name, and additionally a parse 82 * method to extract the individual identifiers contained within names that are returned. 83 * 84 * <p>This class can be customized by passing in a custom instance of FulfillmentsSettings to 85 * create(). For example: 86 * 87 * <p>To customize credentials: 88 * 89 * <pre>{@code 90 * // This snippet has been automatically generated and should be regarded as a code template only. 91 * // It will require modifications to work: 92 * // - It may require correct/in-range values for request initialization. 93 * // - It may require specifying regional endpoints when creating the service client as shown in 94 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 95 * FulfillmentsSettings fulfillmentsSettings = 96 * FulfillmentsSettings.newBuilder() 97 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 98 * .build(); 99 * FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create(fulfillmentsSettings); 100 * }</pre> 101 * 102 * <p>To customize the endpoint: 103 * 104 * <pre>{@code 105 * // This snippet has been automatically generated and should be regarded as a code template only. 106 * // It will require modifications to work: 107 * // - It may require correct/in-range values for request initialization. 108 * // - It may require specifying regional endpoints when creating the service client as shown in 109 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 110 * FulfillmentsSettings fulfillmentsSettings = 111 * FulfillmentsSettings.newBuilder().setEndpoint(myEndpoint).build(); 112 * FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create(fulfillmentsSettings); 113 * }</pre> 114 * 115 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 116 * the wire: 117 * 118 * <pre>{@code 119 * // This snippet has been automatically generated and should be regarded as a code template only. 120 * // It will require modifications to work: 121 * // - It may require correct/in-range values for request initialization. 122 * // - It may require specifying regional endpoints when creating the service client as shown in 123 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 124 * FulfillmentsSettings fulfillmentsSettings = FulfillmentsSettings.newHttpJsonBuilder().build(); 125 * FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create(fulfillmentsSettings); 126 * }</pre> 127 * 128 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 129 */ 130 @BetaApi 131 @Generated("by gapic-generator-java") 132 public class FulfillmentsClient implements BackgroundResource { 133 private final FulfillmentsSettings settings; 134 private final FulfillmentsStub stub; 135 136 /** Constructs an instance of FulfillmentsClient with default settings. */ create()137 public static final FulfillmentsClient create() throws IOException { 138 return create(FulfillmentsSettings.newBuilder().build()); 139 } 140 141 /** 142 * Constructs an instance of FulfillmentsClient, using the given settings. The channels are 143 * created based on the settings passed in, or defaults for any settings that are not set. 144 */ create(FulfillmentsSettings settings)145 public static final FulfillmentsClient create(FulfillmentsSettings settings) throws IOException { 146 return new FulfillmentsClient(settings); 147 } 148 149 /** 150 * Constructs an instance of FulfillmentsClient, using the given stub for making calls. This is 151 * for advanced usage - prefer using create(FulfillmentsSettings). 152 */ create(FulfillmentsStub stub)153 public static final FulfillmentsClient create(FulfillmentsStub stub) { 154 return new FulfillmentsClient(stub); 155 } 156 157 /** 158 * Constructs an instance of FulfillmentsClient, using the given settings. This is protected so 159 * that it is easy to make a subclass, but otherwise, the static factory methods should be 160 * preferred. 161 */ FulfillmentsClient(FulfillmentsSettings settings)162 protected FulfillmentsClient(FulfillmentsSettings settings) throws IOException { 163 this.settings = settings; 164 this.stub = ((FulfillmentsStubSettings) settings.getStubSettings()).createStub(); 165 } 166 FulfillmentsClient(FulfillmentsStub stub)167 protected FulfillmentsClient(FulfillmentsStub stub) { 168 this.settings = null; 169 this.stub = stub; 170 } 171 getSettings()172 public final FulfillmentsSettings getSettings() { 173 return settings; 174 } 175 getStub()176 public FulfillmentsStub getStub() { 177 return stub; 178 } 179 180 // AUTO-GENERATED DOCUMENTATION AND METHOD. 181 /** 182 * Retrieves the fulfillment. 183 * 184 * <p>Sample code: 185 * 186 * <pre>{@code 187 * // This snippet has been automatically generated and should be regarded as a code template only. 188 * // It will require modifications to work: 189 * // - It may require correct/in-range values for request initialization. 190 * // - It may require specifying regional endpoints when creating the service client as shown in 191 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 192 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 193 * FulfillmentName name = FulfillmentName.ofProjectName("[PROJECT]"); 194 * Fulfillment response = fulfillmentsClient.getFulfillment(name); 195 * } 196 * }</pre> 197 * 198 * @param name Required. The name of the fulfillment. Supported formats: 199 * <p>- `projects/<Project ID>/agent/fulfillment` - `projects/<Project 200 * ID>/locations/<Location ID>/agent/fulfillment` 201 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 202 */ getFulfillment(FulfillmentName name)203 public final Fulfillment getFulfillment(FulfillmentName name) { 204 GetFulfillmentRequest request = 205 GetFulfillmentRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 206 return getFulfillment(request); 207 } 208 209 // AUTO-GENERATED DOCUMENTATION AND METHOD. 210 /** 211 * Retrieves the fulfillment. 212 * 213 * <p>Sample code: 214 * 215 * <pre>{@code 216 * // This snippet has been automatically generated and should be regarded as a code template only. 217 * // It will require modifications to work: 218 * // - It may require correct/in-range values for request initialization. 219 * // - It may require specifying regional endpoints when creating the service client as shown in 220 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 221 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 222 * String name = FulfillmentName.ofProjectName("[PROJECT]").toString(); 223 * Fulfillment response = fulfillmentsClient.getFulfillment(name); 224 * } 225 * }</pre> 226 * 227 * @param name Required. The name of the fulfillment. Supported formats: 228 * <p>- `projects/<Project ID>/agent/fulfillment` - `projects/<Project 229 * ID>/locations/<Location ID>/agent/fulfillment` 230 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 231 */ getFulfillment(String name)232 public final Fulfillment getFulfillment(String name) { 233 GetFulfillmentRequest request = GetFulfillmentRequest.newBuilder().setName(name).build(); 234 return getFulfillment(request); 235 } 236 237 // AUTO-GENERATED DOCUMENTATION AND METHOD. 238 /** 239 * Retrieves the fulfillment. 240 * 241 * <p>Sample code: 242 * 243 * <pre>{@code 244 * // This snippet has been automatically generated and should be regarded as a code template only. 245 * // It will require modifications to work: 246 * // - It may require correct/in-range values for request initialization. 247 * // - It may require specifying regional endpoints when creating the service client as shown in 248 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 249 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 250 * GetFulfillmentRequest request = 251 * GetFulfillmentRequest.newBuilder() 252 * .setName(FulfillmentName.ofProjectName("[PROJECT]").toString()) 253 * .build(); 254 * Fulfillment response = fulfillmentsClient.getFulfillment(request); 255 * } 256 * }</pre> 257 * 258 * @param request The request object containing all of the parameters for the API call. 259 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 260 */ getFulfillment(GetFulfillmentRequest request)261 public final Fulfillment getFulfillment(GetFulfillmentRequest request) { 262 return getFulfillmentCallable().call(request); 263 } 264 265 // AUTO-GENERATED DOCUMENTATION AND METHOD. 266 /** 267 * Retrieves the fulfillment. 268 * 269 * <p>Sample code: 270 * 271 * <pre>{@code 272 * // This snippet has been automatically generated and should be regarded as a code template only. 273 * // It will require modifications to work: 274 * // - It may require correct/in-range values for request initialization. 275 * // - It may require specifying regional endpoints when creating the service client as shown in 276 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 277 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 278 * GetFulfillmentRequest request = 279 * GetFulfillmentRequest.newBuilder() 280 * .setName(FulfillmentName.ofProjectName("[PROJECT]").toString()) 281 * .build(); 282 * ApiFuture<Fulfillment> future = 283 * fulfillmentsClient.getFulfillmentCallable().futureCall(request); 284 * // Do something. 285 * Fulfillment response = future.get(); 286 * } 287 * }</pre> 288 */ getFulfillmentCallable()289 public final UnaryCallable<GetFulfillmentRequest, Fulfillment> getFulfillmentCallable() { 290 return stub.getFulfillmentCallable(); 291 } 292 293 // AUTO-GENERATED DOCUMENTATION AND METHOD. 294 /** 295 * Updates the fulfillment. 296 * 297 * <p>Sample code: 298 * 299 * <pre>{@code 300 * // This snippet has been automatically generated and should be regarded as a code template only. 301 * // It will require modifications to work: 302 * // - It may require correct/in-range values for request initialization. 303 * // - It may require specifying regional endpoints when creating the service client as shown in 304 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 305 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 306 * Fulfillment fulfillment = Fulfillment.newBuilder().build(); 307 * FieldMask updateMask = FieldMask.newBuilder().build(); 308 * Fulfillment response = fulfillmentsClient.updateFulfillment(fulfillment, updateMask); 309 * } 310 * }</pre> 311 * 312 * @param fulfillment Required. The fulfillment to update. 313 * @param updateMask Required. The mask to control which fields get updated. If the mask is not 314 * present, all fields will be updated. 315 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 316 */ updateFulfillment(Fulfillment fulfillment, FieldMask updateMask)317 public final Fulfillment updateFulfillment(Fulfillment fulfillment, FieldMask updateMask) { 318 UpdateFulfillmentRequest request = 319 UpdateFulfillmentRequest.newBuilder() 320 .setFulfillment(fulfillment) 321 .setUpdateMask(updateMask) 322 .build(); 323 return updateFulfillment(request); 324 } 325 326 // AUTO-GENERATED DOCUMENTATION AND METHOD. 327 /** 328 * Updates the fulfillment. 329 * 330 * <p>Sample code: 331 * 332 * <pre>{@code 333 * // This snippet has been automatically generated and should be regarded as a code template only. 334 * // It will require modifications to work: 335 * // - It may require correct/in-range values for request initialization. 336 * // - It may require specifying regional endpoints when creating the service client as shown in 337 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 338 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 339 * UpdateFulfillmentRequest request = 340 * UpdateFulfillmentRequest.newBuilder() 341 * .setFulfillment(Fulfillment.newBuilder().build()) 342 * .setUpdateMask(FieldMask.newBuilder().build()) 343 * .build(); 344 * Fulfillment response = fulfillmentsClient.updateFulfillment(request); 345 * } 346 * }</pre> 347 * 348 * @param request The request object containing all of the parameters for the API call. 349 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 350 */ updateFulfillment(UpdateFulfillmentRequest request)351 public final Fulfillment updateFulfillment(UpdateFulfillmentRequest request) { 352 return updateFulfillmentCallable().call(request); 353 } 354 355 // AUTO-GENERATED DOCUMENTATION AND METHOD. 356 /** 357 * Updates the fulfillment. 358 * 359 * <p>Sample code: 360 * 361 * <pre>{@code 362 * // This snippet has been automatically generated and should be regarded as a code template only. 363 * // It will require modifications to work: 364 * // - It may require correct/in-range values for request initialization. 365 * // - It may require specifying regional endpoints when creating the service client as shown in 366 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 367 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 368 * UpdateFulfillmentRequest request = 369 * UpdateFulfillmentRequest.newBuilder() 370 * .setFulfillment(Fulfillment.newBuilder().build()) 371 * .setUpdateMask(FieldMask.newBuilder().build()) 372 * .build(); 373 * ApiFuture<Fulfillment> future = 374 * fulfillmentsClient.updateFulfillmentCallable().futureCall(request); 375 * // Do something. 376 * Fulfillment response = future.get(); 377 * } 378 * }</pre> 379 */ updateFulfillmentCallable()380 public final UnaryCallable<UpdateFulfillmentRequest, Fulfillment> updateFulfillmentCallable() { 381 return stub.updateFulfillmentCallable(); 382 } 383 384 // AUTO-GENERATED DOCUMENTATION AND METHOD. 385 /** 386 * Lists information about the supported locations for this service. 387 * 388 * <p>Sample code: 389 * 390 * <pre>{@code 391 * // This snippet has been automatically generated and should be regarded as a code template only. 392 * // It will require modifications to work: 393 * // - It may require correct/in-range values for request initialization. 394 * // - It may require specifying regional endpoints when creating the service client as shown in 395 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 396 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 397 * ListLocationsRequest request = 398 * ListLocationsRequest.newBuilder() 399 * .setName("name3373707") 400 * .setFilter("filter-1274492040") 401 * .setPageSize(883849137) 402 * .setPageToken("pageToken873572522") 403 * .build(); 404 * for (Location element : fulfillmentsClient.listLocations(request).iterateAll()) { 405 * // doThingsWith(element); 406 * } 407 * } 408 * }</pre> 409 * 410 * @param request The request object containing all of the parameters for the API call. 411 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 412 */ listLocations(ListLocationsRequest request)413 public final ListLocationsPagedResponse listLocations(ListLocationsRequest request) { 414 return listLocationsPagedCallable().call(request); 415 } 416 417 // AUTO-GENERATED DOCUMENTATION AND METHOD. 418 /** 419 * Lists information about the supported locations for this service. 420 * 421 * <p>Sample code: 422 * 423 * <pre>{@code 424 * // This snippet has been automatically generated and should be regarded as a code template only. 425 * // It will require modifications to work: 426 * // - It may require correct/in-range values for request initialization. 427 * // - It may require specifying regional endpoints when creating the service client as shown in 428 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 429 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 430 * ListLocationsRequest request = 431 * ListLocationsRequest.newBuilder() 432 * .setName("name3373707") 433 * .setFilter("filter-1274492040") 434 * .setPageSize(883849137) 435 * .setPageToken("pageToken873572522") 436 * .build(); 437 * ApiFuture<Location> future = 438 * fulfillmentsClient.listLocationsPagedCallable().futureCall(request); 439 * // Do something. 440 * for (Location element : future.get().iterateAll()) { 441 * // doThingsWith(element); 442 * } 443 * } 444 * }</pre> 445 */ 446 public final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()447 listLocationsPagedCallable() { 448 return stub.listLocationsPagedCallable(); 449 } 450 451 // AUTO-GENERATED DOCUMENTATION AND METHOD. 452 /** 453 * Lists information about the supported locations for this service. 454 * 455 * <p>Sample code: 456 * 457 * <pre>{@code 458 * // This snippet has been automatically generated and should be regarded as a code template only. 459 * // It will require modifications to work: 460 * // - It may require correct/in-range values for request initialization. 461 * // - It may require specifying regional endpoints when creating the service client as shown in 462 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 463 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 464 * ListLocationsRequest request = 465 * ListLocationsRequest.newBuilder() 466 * .setName("name3373707") 467 * .setFilter("filter-1274492040") 468 * .setPageSize(883849137) 469 * .setPageToken("pageToken873572522") 470 * .build(); 471 * while (true) { 472 * ListLocationsResponse response = fulfillmentsClient.listLocationsCallable().call(request); 473 * for (Location element : response.getLocationsList()) { 474 * // doThingsWith(element); 475 * } 476 * String nextPageToken = response.getNextPageToken(); 477 * if (!Strings.isNullOrEmpty(nextPageToken)) { 478 * request = request.toBuilder().setPageToken(nextPageToken).build(); 479 * } else { 480 * break; 481 * } 482 * } 483 * } 484 * }</pre> 485 */ listLocationsCallable()486 public final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 487 return stub.listLocationsCallable(); 488 } 489 490 // AUTO-GENERATED DOCUMENTATION AND METHOD. 491 /** 492 * Gets information about a location. 493 * 494 * <p>Sample code: 495 * 496 * <pre>{@code 497 * // This snippet has been automatically generated and should be regarded as a code template only. 498 * // It will require modifications to work: 499 * // - It may require correct/in-range values for request initialization. 500 * // - It may require specifying regional endpoints when creating the service client as shown in 501 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 502 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 503 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 504 * Location response = fulfillmentsClient.getLocation(request); 505 * } 506 * }</pre> 507 * 508 * @param request The request object containing all of the parameters for the API call. 509 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 510 */ getLocation(GetLocationRequest request)511 public final Location getLocation(GetLocationRequest request) { 512 return getLocationCallable().call(request); 513 } 514 515 // AUTO-GENERATED DOCUMENTATION AND METHOD. 516 /** 517 * Gets information about a location. 518 * 519 * <p>Sample code: 520 * 521 * <pre>{@code 522 * // This snippet has been automatically generated and should be regarded as a code template only. 523 * // It will require modifications to work: 524 * // - It may require correct/in-range values for request initialization. 525 * // - It may require specifying regional endpoints when creating the service client as shown in 526 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 527 * try (FulfillmentsClient fulfillmentsClient = FulfillmentsClient.create()) { 528 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 529 * ApiFuture<Location> future = fulfillmentsClient.getLocationCallable().futureCall(request); 530 * // Do something. 531 * Location response = future.get(); 532 * } 533 * }</pre> 534 */ getLocationCallable()535 public final UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 536 return stub.getLocationCallable(); 537 } 538 539 @Override close()540 public final void close() { 541 stub.close(); 542 } 543 544 @Override shutdown()545 public void shutdown() { 546 stub.shutdown(); 547 } 548 549 @Override isShutdown()550 public boolean isShutdown() { 551 return stub.isShutdown(); 552 } 553 554 @Override isTerminated()555 public boolean isTerminated() { 556 return stub.isTerminated(); 557 } 558 559 @Override shutdownNow()560 public void shutdownNow() { 561 stub.shutdownNow(); 562 } 563 564 @Override awaitTermination(long duration, TimeUnit unit)565 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 566 return stub.awaitTermination(duration, unit); 567 } 568 569 public static class ListLocationsPagedResponse 570 extends AbstractPagedListResponse< 571 ListLocationsRequest, 572 ListLocationsResponse, 573 Location, 574 ListLocationsPage, 575 ListLocationsFixedSizeCollection> { 576 createAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)577 public static ApiFuture<ListLocationsPagedResponse> createAsync( 578 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 579 ApiFuture<ListLocationsResponse> futureResponse) { 580 ApiFuture<ListLocationsPage> futurePage = 581 ListLocationsPage.createEmptyPage().createPageAsync(context, futureResponse); 582 return ApiFutures.transform( 583 futurePage, 584 input -> new ListLocationsPagedResponse(input), 585 MoreExecutors.directExecutor()); 586 } 587 ListLocationsPagedResponse(ListLocationsPage page)588 private ListLocationsPagedResponse(ListLocationsPage page) { 589 super(page, ListLocationsFixedSizeCollection.createEmptyCollection()); 590 } 591 } 592 593 public static class ListLocationsPage 594 extends AbstractPage< 595 ListLocationsRequest, ListLocationsResponse, Location, ListLocationsPage> { 596 ListLocationsPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)597 private ListLocationsPage( 598 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 599 ListLocationsResponse response) { 600 super(context, response); 601 } 602 createEmptyPage()603 private static ListLocationsPage createEmptyPage() { 604 return new ListLocationsPage(null, null); 605 } 606 607 @Override createPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)608 protected ListLocationsPage createPage( 609 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 610 ListLocationsResponse response) { 611 return new ListLocationsPage(context, response); 612 } 613 614 @Override createPageAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)615 public ApiFuture<ListLocationsPage> createPageAsync( 616 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 617 ApiFuture<ListLocationsResponse> futureResponse) { 618 return super.createPageAsync(context, futureResponse); 619 } 620 } 621 622 public static class ListLocationsFixedSizeCollection 623 extends AbstractFixedSizeCollection< 624 ListLocationsRequest, 625 ListLocationsResponse, 626 Location, 627 ListLocationsPage, 628 ListLocationsFixedSizeCollection> { 629 ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize)630 private ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize) { 631 super(pages, collectionSize); 632 } 633 createEmptyCollection()634 private static ListLocationsFixedSizeCollection createEmptyCollection() { 635 return new ListLocationsFixedSizeCollection(null, 0); 636 } 637 638 @Override createCollection( List<ListLocationsPage> pages, int collectionSize)639 protected ListLocationsFixedSizeCollection createCollection( 640 List<ListLocationsPage> pages, int collectionSize) { 641 return new ListLocationsFixedSizeCollection(pages, collectionSize); 642 } 643 } 644 } 645