|
| 1 | +/** |
| 2 | + * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | + */ |
| 4 | +package com.oracle.bmc.announcementsservice; |
| 5 | + |
| 6 | +import com.oracle.bmc.announcementsservice.requests.*; |
| 7 | +import com.oracle.bmc.announcementsservice.responses.*; |
| 8 | + |
| 9 | +/** |
| 10 | + * Collection of helper methods that can be used to provide an {@link java.lang.Iterable} interface |
| 11 | + * to any list operations of Announcement where multiple pages of data may be fetched. |
| 12 | + * Two styles of iteration are supported: |
| 13 | + * |
| 14 | + * <ul> |
| 15 | + * <li>Iterating over the Response objects returned by the list operation. These are referred to as ResponseIterators, and the methods are suffixed with ResponseIterator. For example: <i>listUsersResponseIterator</i></li> |
| 16 | + * <li>Iterating over the resources/records being listed. These are referred to as RecordIterators, and the methods are suffixed with RecordIterator. For example: <i>listUsersRecordIterator</i></li> |
| 17 | + * </ul> |
| 18 | + * |
| 19 | + * These iterables abstract away the need to write code to manually handle pagination via looping and using the page tokens. |
| 20 | + * They will automatically fetch more data from the service when required. |
| 21 | + * |
| 22 | + * As an example, if we were using the ListUsers operation in IdentityService, then the {@link java.lang.Iterable} returned by calling a |
| 23 | + * ResponseIterator method would iterate over the ListUsersResponse objects returned by each ListUsers call, whereas the {@link java.lang.Iterable} |
| 24 | + * returned by calling a RecordIterator method would iterate over the User records and we don't have to deal with ListUsersResponse objects at all. |
| 25 | + * In either case, pagination will be automatically handled so we can iterate until there are no more responses or no more resources/records available. |
| 26 | + */ |
| 27 | +@javax.annotation.Generated(value = "OracleSDKGenerator", comments = "API Version: 0.0.1") |
| 28 | +@lombok.RequiredArgsConstructor |
| 29 | +public class AnnouncementPaginators { |
| 30 | + private final Announcement client; |
| 31 | + |
| 32 | + /** |
| 33 | + * Creates a new iterable which will iterate over the responses received from the listAnnouncements operation. This iterable |
| 34 | + * will fetch more data from the server as needed. |
| 35 | + * |
| 36 | + * @param request a request which can be sent to the service operation |
| 37 | + * @return an {@link java.lang.Iterable} which can be used to iterate over the responses received from the service. |
| 38 | + */ |
| 39 | + public Iterable<ListAnnouncementsResponse> listAnnouncementsResponseIterator( |
| 40 | + final ListAnnouncementsRequest request) { |
| 41 | + return new com.oracle.bmc.paginator.internal.ResponseIterable< |
| 42 | + ListAnnouncementsRequest.Builder, ListAnnouncementsRequest, |
| 43 | + ListAnnouncementsResponse>( |
| 44 | + new com.google.common.base.Supplier<ListAnnouncementsRequest.Builder>() { |
| 45 | + @Override |
| 46 | + public ListAnnouncementsRequest.Builder get() { |
| 47 | + return ListAnnouncementsRequest.builder().copy(request); |
| 48 | + } |
| 49 | + }, |
| 50 | + new com.google.common.base.Function<ListAnnouncementsResponse, String>() { |
| 51 | + @Override |
| 52 | + public String apply(ListAnnouncementsResponse response) { |
| 53 | + return response.getOpcNextPage(); |
| 54 | + } |
| 55 | + }, |
| 56 | + new com.google.common.base.Function< |
| 57 | + com.oracle.bmc.paginator.internal.RequestBuilderAndToken< |
| 58 | + ListAnnouncementsRequest.Builder>, |
| 59 | + ListAnnouncementsRequest>() { |
| 60 | + @Override |
| 61 | + public ListAnnouncementsRequest apply( |
| 62 | + com.oracle.bmc.paginator.internal.RequestBuilderAndToken< |
| 63 | + ListAnnouncementsRequest.Builder> |
| 64 | + input) { |
| 65 | + if (input.getToken() == null) { |
| 66 | + return input.getRequestBuilder().build(); |
| 67 | + } else { |
| 68 | + return input.getRequestBuilder() |
| 69 | + .page(input.getToken().orNull()) |
| 70 | + .build(); |
| 71 | + } |
| 72 | + } |
| 73 | + }, |
| 74 | + new com.google.common.base.Function< |
| 75 | + ListAnnouncementsRequest, ListAnnouncementsResponse>() { |
| 76 | + @Override |
| 77 | + public ListAnnouncementsResponse apply(ListAnnouncementsRequest request) { |
| 78 | + return client.listAnnouncements(request); |
| 79 | + } |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Creates a new iterable which will iterate over the {@link com.oracle.bmc.announcementsservice.model.AnnouncementSummary} objects |
| 85 | + * contained in responses from the listAnnouncements operation. This iterable will fetch more data from the |
| 86 | + * server as needed. |
| 87 | + * |
| 88 | + * @param request a request which can be sent to the service operation |
| 89 | + * @return an {@link java.lang.Iterable} which can be used to iterate over the {@link com.oracle.bmc.announcementsservice.model.AnnouncementSummary} objects |
| 90 | + * contained in responses received from the service. |
| 91 | + */ |
| 92 | + public Iterable<com.oracle.bmc.announcementsservice.model.AnnouncementSummary> |
| 93 | + listAnnouncementsRecordIterator(final ListAnnouncementsRequest request) { |
| 94 | + return new com.oracle.bmc.paginator.internal.ResponseRecordIterable< |
| 95 | + ListAnnouncementsRequest.Builder, ListAnnouncementsRequest, |
| 96 | + ListAnnouncementsResponse, |
| 97 | + com.oracle.bmc.announcementsservice.model.AnnouncementSummary>( |
| 98 | + new com.google.common.base.Supplier<ListAnnouncementsRequest.Builder>() { |
| 99 | + @Override |
| 100 | + public ListAnnouncementsRequest.Builder get() { |
| 101 | + return ListAnnouncementsRequest.builder().copy(request); |
| 102 | + } |
| 103 | + }, |
| 104 | + new com.google.common.base.Function<ListAnnouncementsResponse, String>() { |
| 105 | + @Override |
| 106 | + public String apply(ListAnnouncementsResponse response) { |
| 107 | + return response.getOpcNextPage(); |
| 108 | + } |
| 109 | + }, |
| 110 | + new com.google.common.base.Function< |
| 111 | + com.oracle.bmc.paginator.internal.RequestBuilderAndToken< |
| 112 | + ListAnnouncementsRequest.Builder>, |
| 113 | + ListAnnouncementsRequest>() { |
| 114 | + @Override |
| 115 | + public ListAnnouncementsRequest apply( |
| 116 | + com.oracle.bmc.paginator.internal.RequestBuilderAndToken< |
| 117 | + ListAnnouncementsRequest.Builder> |
| 118 | + input) { |
| 119 | + if (input.getToken() == null) { |
| 120 | + return input.getRequestBuilder().build(); |
| 121 | + } else { |
| 122 | + return input.getRequestBuilder() |
| 123 | + .page(input.getToken().orNull()) |
| 124 | + .build(); |
| 125 | + } |
| 126 | + } |
| 127 | + }, |
| 128 | + new com.google.common.base.Function< |
| 129 | + ListAnnouncementsRequest, ListAnnouncementsResponse>() { |
| 130 | + @Override |
| 131 | + public ListAnnouncementsResponse apply(ListAnnouncementsRequest request) { |
| 132 | + return client.listAnnouncements(request); |
| 133 | + } |
| 134 | + }, |
| 135 | + new com.google.common.base.Function< |
| 136 | + ListAnnouncementsResponse, |
| 137 | + java.util.List< |
| 138 | + com.oracle.bmc.announcementsservice.model.AnnouncementSummary>>() { |
| 139 | + @Override |
| 140 | + public java.util.List< |
| 141 | + com.oracle.bmc.announcementsservice.model.AnnouncementSummary> |
| 142 | + apply(ListAnnouncementsResponse response) { |
| 143 | + return response.getAnnouncementsCollection().getItems(); |
| 144 | + } |
| 145 | + }); |
| 146 | + } |
| 147 | +} |
0 commit comments