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

top.jfunc.common.db.bean.Page Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2011-2015, James Zhan 詹波 ([email protected]).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package top.jfunc.common.db.bean;

import java.io.Serializable;
import java.util.List;

/**
 * Page is the result of Model.paginate(......) or Db.paginate(......)
 */
public class Page implements Serializable {
	
	private static final long serialVersionUID = -5395997221963176643L;
	
	private List list;				// list result of this page
	private int pageNumber;				// page number
	private int pageSize=10;				// result amount of this page
	private int totalPage;				// total page
	private int totalRow;				// total row


	public Page(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	/**
	 * Constructor.
	 * @param list the list of paginate result
	 * @param pageNumber the page number
	 * @param pageSize the page size
	 * @param totalPage the total page of paginate
	 * @param totalRow the total row of paginate
	 */
	public Page(List list, int pageNumber, int pageSize, int totalPage, int totalRow) {
		this.list = list;
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
		this.totalPage = totalPage;
		this.totalRow = totalRow;
	}

	public Page(int pageNumber, int pageSize) {
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
	}
	
	/**
	 * Return list of this page.
	 */
	public List getList() {
		return list;
	}
	
	/**
	 * Return page number.
	 */
	public int getPageNumber() {
		return pageNumber;
	}
	
	/**
	 * Return page size.
	 */
	public int getPageSize() {
		return pageSize;
	}
	
	/**
	 * Return total page.
	 */
	public int getTotalPage() {

		totalPage = totalRow / pageSize;
		if (totalRow % pageSize > 0) {
			totalPage++;
		}
		return totalPage;
	}
	
	/**
	 * Return total row.
	 */
	public int getTotalRow() {
		return totalRow;
	}
	
	public boolean isFirstPage() {
		return pageNumber == 1;
	}
	
	public boolean isLastPage() {
		return pageNumber == totalPage;
	}

	public void setList(List list) {
		this.list = list;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public void setTotalRow(int totalRow) {
		this.totalRow = totalRow;
	}

	@Override
	public String toString() {
		return "Page{" +
				"list=" + list +
				", pageNumber=" + pageNumber +
				", pageSize=" + pageSize +
				", totalPage=" + totalPage +
				", totalRow=" + totalRow +
				'}';
	}
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy