-
Notifications
You must be signed in to change notification settings - Fork 775
Expand file tree
/
Copy pathGHAppInstallationsIterable.java
More file actions
130 lines (110 loc) · 3.63 KB
/
GHAppInstallationsIterable.java
File metadata and controls
130 lines (110 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package org.kohsuke.github;
import java.util.Iterator;
import javax.annotation.Nonnull;
// TODO: Auto-generated Javadoc
/**
* Iterable for GHAppInstallation listing.
*/
class GHAppInstallationsIterable extends PagedIterable<GHAppInstallation> {
/** The Constant APP_INSTALLATIONS_URL. */
public static final String APP_INSTALLATIONS_URL = "/user/installations";
private final transient GitHub root;
private GHAppInstallationsPage result;
/**
* Instantiates a new GH app installations iterable.
*
* @param root
* the root
*/
public GHAppInstallationsIterable(GitHub root) {
this.root = root;
}
@Nonnull
@Override
public Paginator<GHAppInstallation> _paginator(int pageSize, int startPage) {
final GitHubRequest request = root.createRequest().withUrlPath(APP_INSTALLATIONS_URL).build();
return new Paginator<>(
adapt(GitHubPaginator
.create(root.getClient(), GHAppInstallationsPage.class, request, pageSize, startPage)),
null);
}
/**
* Iterator.
*
* @param pageSize
* the page size
* @return the paged iterator
*/
@Nonnull
@Override
public PagedIterator<GHAppInstallation> _iterator(int pageSize) {
final GitHubRequest request = root.createRequest().withUrlPath(APP_INSTALLATIONS_URL).build();
return new PagedIterator<>(
adapt(GitHubPageIterator.create(root.getClient(), GHAppInstallationsPage.class, request, pageSize)),
null);
}
/**
* Adapt.
*
* @param base
* the base
* @return the iterator
*/
protected Iterator<GHAppInstallation[]> adapt(final Iterator<GHAppInstallationsPage> base) {
return new Iterator<GHAppInstallation[]>() {
public boolean hasNext() {
return base.hasNext();
}
public GHAppInstallation[] next() {
GHAppInstallationsPage v = base.next();
if (result == null) {
result = v;
}
return v.getInstallations();
}
};
}
protected NavigablePageIterator<GHAppInstallation[]> adapt(
final NavigablePageIterator<GHAppInstallationsPage> base) {
return new NavigablePageIterator<GHAppInstallation[]>() {
@Override
public boolean hasPrevious() {
return base.hasPrevious();
}
@Override
public GHAppInstallation[] previous() {
return base.previous().getInstallations();
}
@Override
public GHAppInstallation[] first() {
return base.first().getInstallations();
}
@Override
public GHAppInstallation[] last() {
return base.last().getInstallations();
}
@Override
public int totalCount() {
return base.totalCount();
}
@Override
public int currentPage() {
return base.currentPage();
}
@Override
public GHAppInstallation[] jumpToPage(int page) {
return base.jumpToPage(page).getInstallations();
}
@Override
public void refresh() {
base.refresh();
}
public boolean hasNext() {
return base.hasNext();
}
public GHAppInstallation[] next() {
return base.next().getInstallations();
}
};
}
}