Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4ebe2022658a7ef4c44b441b7f53ad18ec76df54 (plain) (blame)
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
/*******************************************************************************
 *  Copyright (c) 2011 GitHub Inc.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *    Kevin Sawicki (GitHub Inc.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.egit.github.core.client;

import static org.eclipse.egit.github.core.client.IGitHubConstants.PARAM_PAGE;
import static org.eclipse.egit.github.core.client.IGitHubConstants.PARAM_PER_PAGE;

import org.eclipse.egit.github.core.util.UrlUtils;

/**
 * Paged request class that contains the initial page size and page number of
 * the request.
 *
 * @param <V>
 */
public class PagedRequest<V> extends GitHubRequest {

	/**
	 * First page
	 */
	public static final int PAGE_FIRST = 1;

	/**
	 * Default page size
	 */
	public static final int PAGE_SIZE = 100;

	private final int pageSize;

	private final int page;

	/**
	 * Create paged request with default size
	 */
	public PagedRequest() {
		this(PAGE_FIRST, PAGE_SIZE);
	}

	/**
	 * Create paged request with given starting page and page size.
	 *
	 * @param start
	 * @param size
	 */
	public PagedRequest(int start, int size) {
		page = start;
		pageSize = size;
	}

	/**
	 * Get initial page size
	 *
	 * @return pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	@Override
	protected void addParams(final StringBuilder uri) {
		super.addParams(uri);
		final int size = getPageSize();
		if (size > 0)
			UrlUtils.addParam(PARAM_PER_PAGE, Integer.toString(size), uri);
		final int number = getPage();
		if (number > 0)
			UrlUtils.addParam(PARAM_PAGE, Integer.toString(number), uri);
	}

	/**
	 * Get initial page number
	 *
	 * @return page
	 */
	public int getPage() {
		return page;
	}
}

Back to the top