forked from timols/java-gitlab-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPagination.java
More file actions
38 lines (31 loc) · 1.05 KB
/
Pagination.java
File metadata and controls
38 lines (31 loc) · 1.05 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
package org.gitlab.api;
import org.gitlab.api.http.Query;
import java.io.UnsupportedEncodingException;
public class Pagination {
public static final String PARAM_PAGE = "page";
public static final String PARAM_PER_PAGE = "per_page";
public static final int MAX_ITEMS_PER_PAGE = 100;
private final Query paginationQuery = new Query();
public void setPage(int page) {
try {
paginationQuery.append(PARAM_PAGE, String.valueOf(page));
} catch (UnsupportedEncodingException ignored) {
}
}
public void setPerPage(int perPage) {
if (perPage > MAX_ITEMS_PER_PAGE) {
throw new IllegalArgumentException("Max value for perPage is " + MAX_ITEMS_PER_PAGE);
}
try {
paginationQuery.append(PARAM_PER_PAGE, String.valueOf(perPage));
} catch (UnsupportedEncodingException ignored) {
}
}
public Query asQuery() {
return paginationQuery;
}
@Override
public String toString() {
return paginationQuery.toString();
}
}