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.v2; 18 19 import com.google.api.core.ApiFuture; 20 import com.google.api.core.ApiFutures; 21 import com.google.api.gax.core.BackgroundResource; 22 import com.google.api.gax.paging.AbstractFixedSizeCollection; 23 import com.google.api.gax.paging.AbstractPage; 24 import com.google.api.gax.paging.AbstractPagedListResponse; 25 import com.google.api.gax.rpc.PageContext; 26 import com.google.api.gax.rpc.UnaryCallable; 27 import com.google.cloud.dialogflow.v2.stub.AnswerRecordsStub; 28 import com.google.cloud.dialogflow.v2.stub.AnswerRecordsStubSettings; 29 import com.google.cloud.location.GetLocationRequest; 30 import com.google.cloud.location.ListLocationsRequest; 31 import com.google.cloud.location.ListLocationsResponse; 32 import com.google.cloud.location.Location; 33 import com.google.common.util.concurrent.MoreExecutors; 34 import com.google.protobuf.FieldMask; 35 import java.io.IOException; 36 import java.util.List; 37 import java.util.concurrent.TimeUnit; 38 import javax.annotation.Generated; 39 40 // AUTO-GENERATED DOCUMENTATION AND CLASS. 41 /** 42 * Service Description: Service for managing 43 * [AnswerRecords][google.cloud.dialogflow.v2.AnswerRecord]. 44 * 45 * <p>This class provides the ability to make remote calls to the backing service through method 46 * calls that map to API methods. Sample code to get started: 47 * 48 * <pre>{@code 49 * // This snippet has been automatically generated and should be regarded as a code template only. 50 * // It will require modifications to work: 51 * // - It may require correct/in-range values for request initialization. 52 * // - It may require specifying regional endpoints when creating the service client as shown in 53 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 54 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 55 * AnswerRecord answerRecord = AnswerRecord.newBuilder().build(); 56 * FieldMask updateMask = FieldMask.newBuilder().build(); 57 * AnswerRecord response = answerRecordsClient.updateAnswerRecord(answerRecord, updateMask); 58 * } 59 * }</pre> 60 * 61 * <p>Note: close() needs to be called on the AnswerRecordsClient 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 AnswerRecordsSettings 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 * AnswerRecordsSettings answerRecordsSettings = 96 * AnswerRecordsSettings.newBuilder() 97 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 98 * .build(); 99 * AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create(answerRecordsSettings); 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 * AnswerRecordsSettings answerRecordsSettings = 111 * AnswerRecordsSettings.newBuilder().setEndpoint(myEndpoint).build(); 112 * AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create(answerRecordsSettings); 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 * AnswerRecordsSettings answerRecordsSettings = 125 * AnswerRecordsSettings.newHttpJsonBuilder().build(); 126 * AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create(answerRecordsSettings); 127 * }</pre> 128 * 129 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 130 */ 131 @Generated("by gapic-generator-java") 132 public class AnswerRecordsClient implements BackgroundResource { 133 private final AnswerRecordsSettings settings; 134 private final AnswerRecordsStub stub; 135 136 /** Constructs an instance of AnswerRecordsClient with default settings. */ create()137 public static final AnswerRecordsClient create() throws IOException { 138 return create(AnswerRecordsSettings.newBuilder().build()); 139 } 140 141 /** 142 * Constructs an instance of AnswerRecordsClient, 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(AnswerRecordsSettings settings)145 public static final AnswerRecordsClient create(AnswerRecordsSettings settings) 146 throws IOException { 147 return new AnswerRecordsClient(settings); 148 } 149 150 /** 151 * Constructs an instance of AnswerRecordsClient, using the given stub for making calls. This is 152 * for advanced usage - prefer using create(AnswerRecordsSettings). 153 */ create(AnswerRecordsStub stub)154 public static final AnswerRecordsClient create(AnswerRecordsStub stub) { 155 return new AnswerRecordsClient(stub); 156 } 157 158 /** 159 * Constructs an instance of AnswerRecordsClient, using the given settings. This is protected so 160 * that it is easy to make a subclass, but otherwise, the static factory methods should be 161 * preferred. 162 */ AnswerRecordsClient(AnswerRecordsSettings settings)163 protected AnswerRecordsClient(AnswerRecordsSettings settings) throws IOException { 164 this.settings = settings; 165 this.stub = ((AnswerRecordsStubSettings) settings.getStubSettings()).createStub(); 166 } 167 AnswerRecordsClient(AnswerRecordsStub stub)168 protected AnswerRecordsClient(AnswerRecordsStub stub) { 169 this.settings = null; 170 this.stub = stub; 171 } 172 getSettings()173 public final AnswerRecordsSettings getSettings() { 174 return settings; 175 } 176 getStub()177 public AnswerRecordsStub getStub() { 178 return stub; 179 } 180 181 // AUTO-GENERATED DOCUMENTATION AND METHOD. 182 /** 183 * Returns the list of all answer records in the specified project in reverse chronological order. 184 * 185 * <p>Sample code: 186 * 187 * <pre>{@code 188 * // This snippet has been automatically generated and should be regarded as a code template only. 189 * // It will require modifications to work: 190 * // - It may require correct/in-range values for request initialization. 191 * // - It may require specifying regional endpoints when creating the service client as shown in 192 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 193 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 194 * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); 195 * for (AnswerRecord element : answerRecordsClient.listAnswerRecords(parent).iterateAll()) { 196 * // doThingsWith(element); 197 * } 198 * } 199 * }</pre> 200 * 201 * @param parent Required. The project to list all answer records for in reverse chronological 202 * order. Format: `projects/<Project ID>/locations/<Location ID>`. 203 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 204 */ listAnswerRecords(LocationName parent)205 public final ListAnswerRecordsPagedResponse listAnswerRecords(LocationName parent) { 206 ListAnswerRecordsRequest request = 207 ListAnswerRecordsRequest.newBuilder() 208 .setParent(parent == null ? null : parent.toString()) 209 .build(); 210 return listAnswerRecords(request); 211 } 212 213 // AUTO-GENERATED DOCUMENTATION AND METHOD. 214 /** 215 * Returns the list of all answer records in the specified project in reverse chronological order. 216 * 217 * <p>Sample code: 218 * 219 * <pre>{@code 220 * // This snippet has been automatically generated and should be regarded as a code template only. 221 * // It will require modifications to work: 222 * // - It may require correct/in-range values for request initialization. 223 * // - It may require specifying regional endpoints when creating the service client as shown in 224 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 225 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 226 * ProjectName parent = ProjectName.of("[PROJECT]"); 227 * for (AnswerRecord element : answerRecordsClient.listAnswerRecords(parent).iterateAll()) { 228 * // doThingsWith(element); 229 * } 230 * } 231 * }</pre> 232 * 233 * @param parent Required. The project to list all answer records for in reverse chronological 234 * order. Format: `projects/<Project ID>/locations/<Location ID>`. 235 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 236 */ listAnswerRecords(ProjectName parent)237 public final ListAnswerRecordsPagedResponse listAnswerRecords(ProjectName parent) { 238 ListAnswerRecordsRequest request = 239 ListAnswerRecordsRequest.newBuilder() 240 .setParent(parent == null ? null : parent.toString()) 241 .build(); 242 return listAnswerRecords(request); 243 } 244 245 // AUTO-GENERATED DOCUMENTATION AND METHOD. 246 /** 247 * Returns the list of all answer records in the specified project in reverse chronological order. 248 * 249 * <p>Sample code: 250 * 251 * <pre>{@code 252 * // This snippet has been automatically generated and should be regarded as a code template only. 253 * // It will require modifications to work: 254 * // - It may require correct/in-range values for request initialization. 255 * // - It may require specifying regional endpoints when creating the service client as shown in 256 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 257 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 258 * String parent = ProjectName.of("[PROJECT]").toString(); 259 * for (AnswerRecord element : answerRecordsClient.listAnswerRecords(parent).iterateAll()) { 260 * // doThingsWith(element); 261 * } 262 * } 263 * }</pre> 264 * 265 * @param parent Required. The project to list all answer records for in reverse chronological 266 * order. Format: `projects/<Project ID>/locations/<Location ID>`. 267 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 268 */ listAnswerRecords(String parent)269 public final ListAnswerRecordsPagedResponse listAnswerRecords(String parent) { 270 ListAnswerRecordsRequest request = 271 ListAnswerRecordsRequest.newBuilder().setParent(parent).build(); 272 return listAnswerRecords(request); 273 } 274 275 // AUTO-GENERATED DOCUMENTATION AND METHOD. 276 /** 277 * Returns the list of all answer records in the specified project in reverse chronological order. 278 * 279 * <p>Sample code: 280 * 281 * <pre>{@code 282 * // This snippet has been automatically generated and should be regarded as a code template only. 283 * // It will require modifications to work: 284 * // - It may require correct/in-range values for request initialization. 285 * // - It may require specifying regional endpoints when creating the service client as shown in 286 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 287 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 288 * ListAnswerRecordsRequest request = 289 * ListAnswerRecordsRequest.newBuilder() 290 * .setParent(ProjectName.of("[PROJECT]").toString()) 291 * .setFilter("filter-1274492040") 292 * .setPageSize(883849137) 293 * .setPageToken("pageToken873572522") 294 * .build(); 295 * for (AnswerRecord element : answerRecordsClient.listAnswerRecords(request).iterateAll()) { 296 * // doThingsWith(element); 297 * } 298 * } 299 * }</pre> 300 * 301 * @param request The request object containing all of the parameters for the API call. 302 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 303 */ listAnswerRecords(ListAnswerRecordsRequest request)304 public final ListAnswerRecordsPagedResponse listAnswerRecords(ListAnswerRecordsRequest request) { 305 return listAnswerRecordsPagedCallable().call(request); 306 } 307 308 // AUTO-GENERATED DOCUMENTATION AND METHOD. 309 /** 310 * Returns the list of all answer records in the specified project in reverse chronological order. 311 * 312 * <p>Sample code: 313 * 314 * <pre>{@code 315 * // This snippet has been automatically generated and should be regarded as a code template only. 316 * // It will require modifications to work: 317 * // - It may require correct/in-range values for request initialization. 318 * // - It may require specifying regional endpoints when creating the service client as shown in 319 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 320 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 321 * ListAnswerRecordsRequest request = 322 * ListAnswerRecordsRequest.newBuilder() 323 * .setParent(ProjectName.of("[PROJECT]").toString()) 324 * .setFilter("filter-1274492040") 325 * .setPageSize(883849137) 326 * .setPageToken("pageToken873572522") 327 * .build(); 328 * ApiFuture<AnswerRecord> future = 329 * answerRecordsClient.listAnswerRecordsPagedCallable().futureCall(request); 330 * // Do something. 331 * for (AnswerRecord element : future.get().iterateAll()) { 332 * // doThingsWith(element); 333 * } 334 * } 335 * }</pre> 336 */ 337 public final UnaryCallable<ListAnswerRecordsRequest, ListAnswerRecordsPagedResponse> listAnswerRecordsPagedCallable()338 listAnswerRecordsPagedCallable() { 339 return stub.listAnswerRecordsPagedCallable(); 340 } 341 342 // AUTO-GENERATED DOCUMENTATION AND METHOD. 343 /** 344 * Returns the list of all answer records in the specified project in reverse chronological order. 345 * 346 * <p>Sample code: 347 * 348 * <pre>{@code 349 * // This snippet has been automatically generated and should be regarded as a code template only. 350 * // It will require modifications to work: 351 * // - It may require correct/in-range values for request initialization. 352 * // - It may require specifying regional endpoints when creating the service client as shown in 353 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 354 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 355 * ListAnswerRecordsRequest request = 356 * ListAnswerRecordsRequest.newBuilder() 357 * .setParent(ProjectName.of("[PROJECT]").toString()) 358 * .setFilter("filter-1274492040") 359 * .setPageSize(883849137) 360 * .setPageToken("pageToken873572522") 361 * .build(); 362 * while (true) { 363 * ListAnswerRecordsResponse response = 364 * answerRecordsClient.listAnswerRecordsCallable().call(request); 365 * for (AnswerRecord element : response.getAnswerRecordsList()) { 366 * // doThingsWith(element); 367 * } 368 * String nextPageToken = response.getNextPageToken(); 369 * if (!Strings.isNullOrEmpty(nextPageToken)) { 370 * request = request.toBuilder().setPageToken(nextPageToken).build(); 371 * } else { 372 * break; 373 * } 374 * } 375 * } 376 * }</pre> 377 */ 378 public final UnaryCallable<ListAnswerRecordsRequest, ListAnswerRecordsResponse> listAnswerRecordsCallable()379 listAnswerRecordsCallable() { 380 return stub.listAnswerRecordsCallable(); 381 } 382 383 // AUTO-GENERATED DOCUMENTATION AND METHOD. 384 /** 385 * Updates the specified answer record. 386 * 387 * <p>Sample code: 388 * 389 * <pre>{@code 390 * // This snippet has been automatically generated and should be regarded as a code template only. 391 * // It will require modifications to work: 392 * // - It may require correct/in-range values for request initialization. 393 * // - It may require specifying regional endpoints when creating the service client as shown in 394 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 395 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 396 * AnswerRecord answerRecord = AnswerRecord.newBuilder().build(); 397 * FieldMask updateMask = FieldMask.newBuilder().build(); 398 * AnswerRecord response = answerRecordsClient.updateAnswerRecord(answerRecord, updateMask); 399 * } 400 * }</pre> 401 * 402 * @param answerRecord Required. Answer record to update. 403 * @param updateMask Required. The mask to control which fields get updated. 404 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 405 */ updateAnswerRecord(AnswerRecord answerRecord, FieldMask updateMask)406 public final AnswerRecord updateAnswerRecord(AnswerRecord answerRecord, FieldMask updateMask) { 407 UpdateAnswerRecordRequest request = 408 UpdateAnswerRecordRequest.newBuilder() 409 .setAnswerRecord(answerRecord) 410 .setUpdateMask(updateMask) 411 .build(); 412 return updateAnswerRecord(request); 413 } 414 415 // AUTO-GENERATED DOCUMENTATION AND METHOD. 416 /** 417 * Updates the specified answer record. 418 * 419 * <p>Sample code: 420 * 421 * <pre>{@code 422 * // This snippet has been automatically generated and should be regarded as a code template only. 423 * // It will require modifications to work: 424 * // - It may require correct/in-range values for request initialization. 425 * // - It may require specifying regional endpoints when creating the service client as shown in 426 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 427 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 428 * UpdateAnswerRecordRequest request = 429 * UpdateAnswerRecordRequest.newBuilder() 430 * .setAnswerRecord(AnswerRecord.newBuilder().build()) 431 * .setUpdateMask(FieldMask.newBuilder().build()) 432 * .build(); 433 * AnswerRecord response = answerRecordsClient.updateAnswerRecord(request); 434 * } 435 * }</pre> 436 * 437 * @param request The request object containing all of the parameters for the API call. 438 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 439 */ updateAnswerRecord(UpdateAnswerRecordRequest request)440 public final AnswerRecord updateAnswerRecord(UpdateAnswerRecordRequest request) { 441 return updateAnswerRecordCallable().call(request); 442 } 443 444 // AUTO-GENERATED DOCUMENTATION AND METHOD. 445 /** 446 * Updates the specified answer record. 447 * 448 * <p>Sample code: 449 * 450 * <pre>{@code 451 * // This snippet has been automatically generated and should be regarded as a code template only. 452 * // It will require modifications to work: 453 * // - It may require correct/in-range values for request initialization. 454 * // - It may require specifying regional endpoints when creating the service client as shown in 455 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 456 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 457 * UpdateAnswerRecordRequest request = 458 * UpdateAnswerRecordRequest.newBuilder() 459 * .setAnswerRecord(AnswerRecord.newBuilder().build()) 460 * .setUpdateMask(FieldMask.newBuilder().build()) 461 * .build(); 462 * ApiFuture<AnswerRecord> future = 463 * answerRecordsClient.updateAnswerRecordCallable().futureCall(request); 464 * // Do something. 465 * AnswerRecord response = future.get(); 466 * } 467 * }</pre> 468 */ updateAnswerRecordCallable()469 public final UnaryCallable<UpdateAnswerRecordRequest, AnswerRecord> updateAnswerRecordCallable() { 470 return stub.updateAnswerRecordCallable(); 471 } 472 473 // AUTO-GENERATED DOCUMENTATION AND METHOD. 474 /** 475 * Lists information about the supported locations for this service. 476 * 477 * <p>Sample code: 478 * 479 * <pre>{@code 480 * // This snippet has been automatically generated and should be regarded as a code template only. 481 * // It will require modifications to work: 482 * // - It may require correct/in-range values for request initialization. 483 * // - It may require specifying regional endpoints when creating the service client as shown in 484 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 485 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 486 * ListLocationsRequest request = 487 * ListLocationsRequest.newBuilder() 488 * .setName("name3373707") 489 * .setFilter("filter-1274492040") 490 * .setPageSize(883849137) 491 * .setPageToken("pageToken873572522") 492 * .build(); 493 * for (Location element : answerRecordsClient.listLocations(request).iterateAll()) { 494 * // doThingsWith(element); 495 * } 496 * } 497 * }</pre> 498 * 499 * @param request The request object containing all of the parameters for the API call. 500 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 501 */ listLocations(ListLocationsRequest request)502 public final ListLocationsPagedResponse listLocations(ListLocationsRequest request) { 503 return listLocationsPagedCallable().call(request); 504 } 505 506 // AUTO-GENERATED DOCUMENTATION AND METHOD. 507 /** 508 * Lists information about the supported locations for this service. 509 * 510 * <p>Sample code: 511 * 512 * <pre>{@code 513 * // This snippet has been automatically generated and should be regarded as a code template only. 514 * // It will require modifications to work: 515 * // - It may require correct/in-range values for request initialization. 516 * // - It may require specifying regional endpoints when creating the service client as shown in 517 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 518 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 519 * ListLocationsRequest request = 520 * ListLocationsRequest.newBuilder() 521 * .setName("name3373707") 522 * .setFilter("filter-1274492040") 523 * .setPageSize(883849137) 524 * .setPageToken("pageToken873572522") 525 * .build(); 526 * ApiFuture<Location> future = 527 * answerRecordsClient.listLocationsPagedCallable().futureCall(request); 528 * // Do something. 529 * for (Location element : future.get().iterateAll()) { 530 * // doThingsWith(element); 531 * } 532 * } 533 * }</pre> 534 */ 535 public final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()536 listLocationsPagedCallable() { 537 return stub.listLocationsPagedCallable(); 538 } 539 540 // AUTO-GENERATED DOCUMENTATION AND METHOD. 541 /** 542 * Lists information about the supported locations for this service. 543 * 544 * <p>Sample code: 545 * 546 * <pre>{@code 547 * // This snippet has been automatically generated and should be regarded as a code template only. 548 * // It will require modifications to work: 549 * // - It may require correct/in-range values for request initialization. 550 * // - It may require specifying regional endpoints when creating the service client as shown in 551 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 552 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 553 * ListLocationsRequest request = 554 * ListLocationsRequest.newBuilder() 555 * .setName("name3373707") 556 * .setFilter("filter-1274492040") 557 * .setPageSize(883849137) 558 * .setPageToken("pageToken873572522") 559 * .build(); 560 * while (true) { 561 * ListLocationsResponse response = answerRecordsClient.listLocationsCallable().call(request); 562 * for (Location element : response.getLocationsList()) { 563 * // doThingsWith(element); 564 * } 565 * String nextPageToken = response.getNextPageToken(); 566 * if (!Strings.isNullOrEmpty(nextPageToken)) { 567 * request = request.toBuilder().setPageToken(nextPageToken).build(); 568 * } else { 569 * break; 570 * } 571 * } 572 * } 573 * }</pre> 574 */ listLocationsCallable()575 public final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 576 return stub.listLocationsCallable(); 577 } 578 579 // AUTO-GENERATED DOCUMENTATION AND METHOD. 580 /** 581 * Gets information about a location. 582 * 583 * <p>Sample code: 584 * 585 * <pre>{@code 586 * // This snippet has been automatically generated and should be regarded as a code template only. 587 * // It will require modifications to work: 588 * // - It may require correct/in-range values for request initialization. 589 * // - It may require specifying regional endpoints when creating the service client as shown in 590 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 591 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 592 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 593 * Location response = answerRecordsClient.getLocation(request); 594 * } 595 * }</pre> 596 * 597 * @param request The request object containing all of the parameters for the API call. 598 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 599 */ getLocation(GetLocationRequest request)600 public final Location getLocation(GetLocationRequest request) { 601 return getLocationCallable().call(request); 602 } 603 604 // AUTO-GENERATED DOCUMENTATION AND METHOD. 605 /** 606 * Gets information about a location. 607 * 608 * <p>Sample code: 609 * 610 * <pre>{@code 611 * // This snippet has been automatically generated and should be regarded as a code template only. 612 * // It will require modifications to work: 613 * // - It may require correct/in-range values for request initialization. 614 * // - It may require specifying regional endpoints when creating the service client as shown in 615 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 616 * try (AnswerRecordsClient answerRecordsClient = AnswerRecordsClient.create()) { 617 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 618 * ApiFuture<Location> future = answerRecordsClient.getLocationCallable().futureCall(request); 619 * // Do something. 620 * Location response = future.get(); 621 * } 622 * }</pre> 623 */ getLocationCallable()624 public final UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 625 return stub.getLocationCallable(); 626 } 627 628 @Override close()629 public final void close() { 630 stub.close(); 631 } 632 633 @Override shutdown()634 public void shutdown() { 635 stub.shutdown(); 636 } 637 638 @Override isShutdown()639 public boolean isShutdown() { 640 return stub.isShutdown(); 641 } 642 643 @Override isTerminated()644 public boolean isTerminated() { 645 return stub.isTerminated(); 646 } 647 648 @Override shutdownNow()649 public void shutdownNow() { 650 stub.shutdownNow(); 651 } 652 653 @Override awaitTermination(long duration, TimeUnit unit)654 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 655 return stub.awaitTermination(duration, unit); 656 } 657 658 public static class ListAnswerRecordsPagedResponse 659 extends AbstractPagedListResponse< 660 ListAnswerRecordsRequest, 661 ListAnswerRecordsResponse, 662 AnswerRecord, 663 ListAnswerRecordsPage, 664 ListAnswerRecordsFixedSizeCollection> { 665 createAsync( PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, ApiFuture<ListAnswerRecordsResponse> futureResponse)666 public static ApiFuture<ListAnswerRecordsPagedResponse> createAsync( 667 PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, 668 ApiFuture<ListAnswerRecordsResponse> futureResponse) { 669 ApiFuture<ListAnswerRecordsPage> futurePage = 670 ListAnswerRecordsPage.createEmptyPage().createPageAsync(context, futureResponse); 671 return ApiFutures.transform( 672 futurePage, 673 input -> new ListAnswerRecordsPagedResponse(input), 674 MoreExecutors.directExecutor()); 675 } 676 ListAnswerRecordsPagedResponse(ListAnswerRecordsPage page)677 private ListAnswerRecordsPagedResponse(ListAnswerRecordsPage page) { 678 super(page, ListAnswerRecordsFixedSizeCollection.createEmptyCollection()); 679 } 680 } 681 682 public static class ListAnswerRecordsPage 683 extends AbstractPage< 684 ListAnswerRecordsRequest, 685 ListAnswerRecordsResponse, 686 AnswerRecord, 687 ListAnswerRecordsPage> { 688 ListAnswerRecordsPage( PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, ListAnswerRecordsResponse response)689 private ListAnswerRecordsPage( 690 PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, 691 ListAnswerRecordsResponse response) { 692 super(context, response); 693 } 694 createEmptyPage()695 private static ListAnswerRecordsPage createEmptyPage() { 696 return new ListAnswerRecordsPage(null, null); 697 } 698 699 @Override createPage( PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, ListAnswerRecordsResponse response)700 protected ListAnswerRecordsPage createPage( 701 PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, 702 ListAnswerRecordsResponse response) { 703 return new ListAnswerRecordsPage(context, response); 704 } 705 706 @Override createPageAsync( PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, ApiFuture<ListAnswerRecordsResponse> futureResponse)707 public ApiFuture<ListAnswerRecordsPage> createPageAsync( 708 PageContext<ListAnswerRecordsRequest, ListAnswerRecordsResponse, AnswerRecord> context, 709 ApiFuture<ListAnswerRecordsResponse> futureResponse) { 710 return super.createPageAsync(context, futureResponse); 711 } 712 } 713 714 public static class ListAnswerRecordsFixedSizeCollection 715 extends AbstractFixedSizeCollection< 716 ListAnswerRecordsRequest, 717 ListAnswerRecordsResponse, 718 AnswerRecord, 719 ListAnswerRecordsPage, 720 ListAnswerRecordsFixedSizeCollection> { 721 ListAnswerRecordsFixedSizeCollection( List<ListAnswerRecordsPage> pages, int collectionSize)722 private ListAnswerRecordsFixedSizeCollection( 723 List<ListAnswerRecordsPage> pages, int collectionSize) { 724 super(pages, collectionSize); 725 } 726 createEmptyCollection()727 private static ListAnswerRecordsFixedSizeCollection createEmptyCollection() { 728 return new ListAnswerRecordsFixedSizeCollection(null, 0); 729 } 730 731 @Override createCollection( List<ListAnswerRecordsPage> pages, int collectionSize)732 protected ListAnswerRecordsFixedSizeCollection createCollection( 733 List<ListAnswerRecordsPage> pages, int collectionSize) { 734 return new ListAnswerRecordsFixedSizeCollection(pages, collectionSize); 735 } 736 } 737 738 public static class ListLocationsPagedResponse 739 extends AbstractPagedListResponse< 740 ListLocationsRequest, 741 ListLocationsResponse, 742 Location, 743 ListLocationsPage, 744 ListLocationsFixedSizeCollection> { 745 createAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)746 public static ApiFuture<ListLocationsPagedResponse> createAsync( 747 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 748 ApiFuture<ListLocationsResponse> futureResponse) { 749 ApiFuture<ListLocationsPage> futurePage = 750 ListLocationsPage.createEmptyPage().createPageAsync(context, futureResponse); 751 return ApiFutures.transform( 752 futurePage, 753 input -> new ListLocationsPagedResponse(input), 754 MoreExecutors.directExecutor()); 755 } 756 ListLocationsPagedResponse(ListLocationsPage page)757 private ListLocationsPagedResponse(ListLocationsPage page) { 758 super(page, ListLocationsFixedSizeCollection.createEmptyCollection()); 759 } 760 } 761 762 public static class ListLocationsPage 763 extends AbstractPage< 764 ListLocationsRequest, ListLocationsResponse, Location, ListLocationsPage> { 765 ListLocationsPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)766 private ListLocationsPage( 767 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 768 ListLocationsResponse response) { 769 super(context, response); 770 } 771 createEmptyPage()772 private static ListLocationsPage createEmptyPage() { 773 return new ListLocationsPage(null, null); 774 } 775 776 @Override createPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)777 protected ListLocationsPage createPage( 778 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 779 ListLocationsResponse response) { 780 return new ListLocationsPage(context, response); 781 } 782 783 @Override createPageAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)784 public ApiFuture<ListLocationsPage> createPageAsync( 785 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 786 ApiFuture<ListLocationsResponse> futureResponse) { 787 return super.createPageAsync(context, futureResponse); 788 } 789 } 790 791 public static class ListLocationsFixedSizeCollection 792 extends AbstractFixedSizeCollection< 793 ListLocationsRequest, 794 ListLocationsResponse, 795 Location, 796 ListLocationsPage, 797 ListLocationsFixedSizeCollection> { 798 ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize)799 private ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize) { 800 super(pages, collectionSize); 801 } 802 createEmptyCollection()803 private static ListLocationsFixedSizeCollection createEmptyCollection() { 804 return new ListLocationsFixedSizeCollection(null, 0); 805 } 806 807 @Override createCollection( List<ListLocationsPage> pages, int collectionSize)808 protected ListLocationsFixedSizeCollection createCollection( 809 List<ListLocationsPage> pages, int collectionSize) { 810 return new ListLocationsFixedSizeCollection(pages, collectionSize); 811 } 812 } 813 } 814