GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Updates to Paging surface by michaelbausor · Pull Request #255 · googleapis/gax-java
This repository was archived by the owner on Sep 26, 2023. It is now read-only.
Conversation
Contributor
Updates to paging that correspond to googleapis/gapic-generator#1139
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was an error while loading. Please reload this page.
Codecov Report
@@ Coverage Diff @@ ## master #255 +/- ## ============================================ + Coverage 70.89% 71.16% +0.26% - Complexity 541 554 +13 ============================================ Files 78 80 +2 Lines 2680 2736 +56 Branches 268 275 +7 ============================================ + Hits 1900 1947 +47 - Misses 676 683 +7 - Partials 104 106 +2
Continue to review full report at Codecov.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * API request and response objects. | ||
| */ | ||
| public interface Page<RequestT, ResponseT, ResourceT> extends Iterable<ResourceT> { | ||
| public interface Page<ResourceT> extends Iterable<ResourceT> { |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Assert.fail("No exception raised"); | ||
| } catch (ApiException e) { | ||
| Assert.assertEquals(Status.INTERNAL.getCode(), e.getStatusCode()); | ||
| Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode()); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| */ | ||
| package com.google.api.gax.core; | ||
|
|
||
| import java.util.Iterator; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| private final Iterator<PageContext<?, ?, ResourceT>> pageIterator = pageList.iterator(); | ||
| private Iterator<ResourceT> resourceIterator = | ||
| pageIterator.next().getResourceIterable().iterator(); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,164 @@ | |||
| /* | |||
| * Copyright 2016, Google Inc. All rights reserved. | |||
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| // Make the API call eagerly | ||
| this.response = | ||
| ApiExceptions.callAndTranslateApiException(callable.futureCall(request, context)); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| private PagedListDescriptor<RequestT, ResponseT, ResourceT> pageDescriptor; | ||
| private Page<RequestT, ResponseT, ResourceT> currentPage; | ||
| public class PagedListResponseContext<RequestT, ResponseT, ResourceT> | ||
| extends PageContext<RequestT, ResponseT, ResourceT> { |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| public ListIntegersPage(PageContext<Integer, List<Integer>, Integer> context) { | ||
| this.context = context; | ||
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| CallContext callContext) { | ||
| this.context = new PagedListResponseContext<>(callable, pageDescriptor, request, callContext); | ||
| this.page = new ListIntegersPage(this.context); | ||
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return Iterables.size(getResourceIterable()); | ||
| } | ||
| @Override | ||
| public abstract AbstractPage<RequestT, ResponseT, ResourceT> getNextPage(); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| private class AllResourcesIterator extends AbstractIterator<ResourceT> { | ||
| AbstractPage<RequestT, ResponseT, ResourceT> currentPage = AbstractPage.this; | ||
| Iterator<ResourceT> currentIterator = currentPage.getValues().iterator(); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| this.context = new PagedListResponseContext<>(callable, pageDescriptor, request, callContext); | ||
| this.page = new ListOperationsPage(this.context); | ||
| return new ListOperationsPagedResponse( | ||
| ListOperationsPage.callApiAndCreate(callable, pageDescriptor, request, callContext)); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ListOperationsRequest request, | ||
| CallContext context) { | ||
| return new ListOperationsPagedResponse( | ||
| return ListOperationsPagedResponse.callApiAndCreate( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| protected <PageT> PageT getNextPage(PageFactory<RequestT, ResponseT, ResourceT, PageT> provider) { | ||
| if (hasNextPage()) { | ||
| RequestT nextRequest = pageDescriptor.injectToken(request, getNextPageToken()); | ||
| return callApiAndCreate(provider, callable, pageDescriptor, nextRequest, context); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| RequestT request, | ||
| CallContext context, | ||
| ResponseT response); | ||
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| public abstract RequestT request(); | ||
|
|
||
| public abstract CallContext callContext(); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public ApiFuture<PagedListResponseT> futureCall(RequestT request, CallContext context) { | ||
| PagedListResponseT pagedListResponse = | ||
| pagedListResponseFactory.createPagedListResponse( | ||
| pagedListResponseFactory.callAndCreateResponse( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| private Iterable<ListOperationsPage> iteratePages() { | ||
| return iterate(PAGE_FACTORY, this); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,35 @@ | |||
| /* | |||
| * Copyright 2016, Google Inc. All rights reserved. | |||
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /** Returns the current page of results. Note: This method is not thread-safe. */ | ||
| Iterable<Page<RequestT, ResponseT, ResourceT>> iteratePages(); | ||
| /** | ||
| * Return an iterator over all Page objects. Page objects are retrieved lazily via API calls until |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import java.util.Iterator; | ||
| import java.util.List; | ||
|
|
||
| public abstract class AbstractFixedSizeCollection< |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| implements FixedSizeCollection<ResourceT> { | ||
|
|
||
| private List<PageT> pageList; | ||
| private int collectionSize; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } else { | ||
| return null; | ||
| } | ||
| } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| RequestT nextRequest = | ||
| context.pageDescriptor().injectToken(context.request(), getNextPageToken()); | ||
| final PageContext<RequestT, ResponseT, ResourceT> newContext = | ||
| context.withRequest(nextRequest); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| public abstract RequestT request(); | ||
|
|
||
| public abstract CallContext callContext(); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| PageContext<ListOperationsRequest, ListOperationsResponse, Operation> pageContext = | ||
| PageContext.create(callable, LIST_OPERATIONS_PAGE_STR_DESC, request, context); | ||
| ListOperationsResponse response = | ||
| ApiExceptions.callAndTranslateApiException(callable.futureCall(request, context)); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| public static ListIntegersPagedResponse create( | ||
| PageContext<Integer, List<Integer>, Integer> context, List<Integer> response) { | ||
| ListIntegersPage page = new ListIntegersPage(context, response); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| private static ListIntegersSizedPage createEmptyCollection() { | ||
| return new ListIntegersSizedPage(); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Address PR comments
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM - just a couple last things which you can address as you see fit.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| import java.util.List; | ||
|
|
||
| /** | ||
| * Partial implementation of {@see FixedSizeCollection}. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| public PageT getNextPage(int pageSize) { | ||
| public PageT getNextPageImpl(Integer pageSize) { |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.