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