11package org .kohsuke .github ;
22
3- import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
4- import org .jetbrains .annotations .NotNull ;
5-
63import java .io .IOException ;
74import java .lang .reflect .Array ;
85import java .util .*;
2320 */
2421class PaginatedEndpoint <Page extends GitHubPage <Item >, Item > implements Iterable <Item > {
2522
26- private static class ArrayIterable <I > extends PaginatedEndpoint <GitHubArrayPage <I >, I > {
27-
28- private class ArrayIterator extends PaginatedEndpointPages <GitHubArrayPage <I >, I > {
29-
30- ArrayIterator (GitHubClient client ,
31- Class <GitHubArrayPage <I >> pageType ,
32- GitHubRequest request ,
33- int pageSize ,
34- Consumer <I > itemInitializer ) {
35- super (client , pageType , request , pageSize , itemInitializer );
36- }
37-
38- @ Override
39- @ NotNull protected GitHubResponse <GitHubArrayPage <I >> sendNextRequest () throws IOException {
40- GitHubResponse <I []> response = client .sendRequest (nextRequest ,
41- (connectorResponse ) -> GitHubResponse .parseBody (connectorResponse , receiverType ));
42- return new GitHubResponse <>(response , new GitHubArrayPage <>(response .body ()));
43- }
44-
45- }
46-
47- private final Class <I []> receiverType ;
48-
49- private ArrayIterable (GitHubClient client ,
50- GitHubRequest request ,
51- Class <I []> receiverType ,
52- Class <I > itemType ,
53- Consumer <I > itemInitializer ) {
54- super (client , request , GitHubArrayPage .getArrayPageClass (itemType ), itemType , itemInitializer );
55- this .receiverType = receiverType ;
56- }
57-
58- @ Nonnull
59- @ Override
60- public PaginatedEndpointPages <GitHubArrayPage <I >, I > pages () {
61- return new ArrayIterator (client , pageType , request , pageSize , itemInitializer );
62- }
63- }
64-
65- /**
66- * Represents a page of results
67- *
68- * @author Kohsuke Kawaguchi
69- * @param <I>
70- * the generic type
71- */
72- private static class GitHubArrayPage <I > implements GitHubPage <I > {
73-
74- @ SuppressFBWarnings (value = { "DM_NEW_FOR_GETCLASS" }, justification = "BUG?" )
75- private static <P extends GitHubPage <I >, I > Class <P > getArrayPageClass (Class <I > itemType ) {
76- return (Class <P >) new GitHubArrayPage <>(itemType ).getClass ();
77- }
78-
79- private final I [] items ;
80-
81- public GitHubArrayPage (I [] items ) {
82- this .items = items ;
83- }
84-
85- private GitHubArrayPage (Class <I > itemType ) {
86- this .items = null ;
87- }
88-
89- public I [] getItems () {
90- return items ;
91- }
92- }
93-
94- private static class SinglePageEndpoint <P extends GitHubPage <I >, I > extends PaginatedEndpoint <P , I > {
23+ static class SinglePageEndpoint <P extends GitHubPage <I >, I > extends PaginatedEndpoint <P , I > {
9524 private final P page ;
9625
9726 SinglePageEndpoint (P page , Class <I > itemType ) {
@@ -107,23 +36,20 @@ public PaginatedEndpointPages<P, I> pages() {
10736
10837 }
10938
110- static <I > PaginatedEndpoint <GitHubArrayPage <I >, I > fromSinglePage (I [] array , Class <I > itemType ) {
111- return fromSinglePage (new GitHubArrayPage <>(array ), itemType );
39+ static <I > PaginatedEndpoint <GitHubPageArrayAdapter <I >, I > fromSinglePage (I [] array , Class <I > itemType ) {
40+ return fromSinglePage (new GitHubPageArrayAdapter <>(array ), itemType );
11241 }
11342
11443 static <P extends GitHubPage <I >, I > PaginatedEndpoint <P , I > fromSinglePage (P page , Class <I > itemType ) {
11544 return new SinglePageEndpoint <>(page , itemType );
11645 }
11746
118- static <I > PaginatedEndpoint <GitHubArrayPage <I >, I > ofArrayEndpoint (GitHubClient client ,
47+ static <I > PaginatedEndpoint <GitHubPage <I >, I > ofArrayEndpoint (GitHubClient client ,
11948 GitHubRequest request ,
12049 Class <I []> receiverType ,
12150 Consumer <I > itemInitializer ) {
122- return new ArrayIterable <I >(client ,
123- request ,
124- (Class <I []>) receiverType ,
125- (Class <I >) receiverType .getComponentType (),
126- itemInitializer );
51+ Class <I > itemType = (Class <I >) receiverType .getComponentType ();
52+ return new PaginatedArrayEndpoint <I >(client , request , receiverType , itemType , itemInitializer );
12753 }
12854
12955 protected final GitHubClient client ;
@@ -134,7 +60,6 @@ static <I> PaginatedEndpoint<GitHubArrayPage<I>, I> ofArrayEndpoint(GitHubClient
13460 * Page size. 0 is default.
13561 */
13662 protected int pageSize = 0 ;
137-
13863 protected final Class <Page > pageType ;
13964
14065 protected final GitHubRequest request ;
@@ -164,7 +89,7 @@ static <I> PaginatedEndpoint<GitHubArrayPage<I>, I> ofArrayEndpoint(GitHubClient
16489 }
16590
16691 @ Nonnull
167- public final PaginatedEndpointItems <Item > items () {
92+ public final PaginatedEndpointItems <Page , Item > items () {
16893 return new PaginatedEndpointItems <>(this .pages ());
16994 }
17095
0 commit comments