All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jdroid.github.client.PagedRequest Maven / Gradle / Ivy

There is a newer version: 0.9.4
Show newest version
/*******************************************************************************
 *  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 com.jdroid.github.client;

import static com.jdroid.github.client.IGitHubConstants.PARAM_PAGE;
import static com.jdroid.github.client.IGitHubConstants.PARAM_PER_PAGE;

import com.jdroid.github.util.UrlUtils;

/**
 * Paged request class that contains the initial page size and page number of
 * the request.
 *
 * @param 
 */
public class PagedRequest 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;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy