/** * Copy method to populate the builder with values from the given instance. * @return this builder instance */ public Builder copy(ListUsersResponse o) { opcRequestId(o.getOpcRequestId()); opcNextPage(o.getOpcNextPage()); items(o.getItems()); return this; } }
/** * This method demonstrates how to do pagination yourself by manually managing the next page * tokens returned by service responses * * @param identityClient the client used to make service calls * @param compartmentId the OCID of the compartment we'll issue the ListUsers request against. This should be your tenancy OCID */ private static void doManualPagination( final IdentityClient identityClient, final String compartmentId) { System.out.println("Manual Pagination"); System.out.println("==================="); String nextPageToken = null; do { ListUsersResponse response = identityClient.listUsers( ListUsersRequest.builder() .compartmentId(compartmentId) .page(nextPageToken) .build()); for (User user : response.getItems()) { System.out.println(user); } nextPageToken = response.getOpcNextPage(); } while (nextPageToken != null); System.out.println(); System.out.println(); }
/** * This method demonstrates how to do pagination by using the Paginator offered by the service client. Each service * client has a getPaginators() method which will return a Paginator. The Paginator will have methods which vend a * {@link java.lang.Iterable} that can be used to iterate over either Response objects returned by a service call or * resources/records being listed. * * This method demonstrates how to iterate over the Response objects using the Paginator. The methods used to * get an iterable over Response objects are always of the form <operation>ResponseIterator(). */ private static void doPaginateWithResponsePaginator( final IdentityClient identityClient, final String compartmentId) { System.out.println("Pagination Using Response Paginator"); System.out.println("==================="); // Build a request object as normal, including any sorting or filtering you wish to do final ListUsersRequest request = ListUsersRequest.builder().compartmentId(compartmentId).build(); // Note that the iterable is over the Response objects final Iterable<ListUsersResponse> responseIterator = identityClient.getPaginators().listUsersResponseIterator(request); for (ListUsersResponse response : responseIterator) { for (User user : response.getItems()) { System.out.println(user); } } System.out.println(); System.out.println(); }