Java tutorial
/* * PageNavigator.java 2010.08.16 * * Copyright (c) 2010, MEI By Seok Kyun. Choi. () * http://syaku.tistory.com * * GNU Lesser General Public License * http://www.gnu.org/licenses/lgpl.html */ package com.syaku.commons; import org.apache.log4j.Logger; import org.apache.commons.lang.*; public class PageNavigator { private static Logger log = Logger.getLogger(PageNavigator.class); private int total_count = 0; private int page = 0, page_row = 0, page_link = 0; private int total_page = 0, start_page = 0, now_page = 0, end_page = 0, virtual_idx = 0; private int start_idx = 0; /** * @method : PageNavigator(parameter1,parameter2,parameter3) * @brief * @parameters { parameter1 : (int) parameter2 : (int) parameter3 : (int) } */ public PageNavigator(int page, int page_row, int page_link) { this.page = page; this.page_row = page_row; if (this.page_link == 0) this.page_link = page_link; } /** * @method : setPageIndex * @brief */ public void setPageIndex(int total_count) { this.total_count = total_count; total_page = ((this.total_count - 1) / page_row) + 1; start_page = ((page - 1) / page_link) * page_link + 1; now_page = (start_page / page_link) + 1; end_page = start_page + (page_link - 1); start_idx = (page - 1) * page_row; virtual_idx = total_count - (page_row * (page - 1)); log.info(StringUtils.join(new String[] { "{PageNavigator.setPageIndex}\r\n", "==========================================================================\r\n", "> total_count : ", ObjectUtils.toString(this.total_count), "\r\n", "> page_row : ", ObjectUtils.toString(page_row), "\r\n", "> page_link : ", ObjectUtils.toString(page_link), "\r\n", "> page : ", ObjectUtils.toString(page), "\r\n", "> total_page : ", ObjectUtils.toString(total_page), "\r\n", "> start_page : ", ObjectUtils.toString(start_page), "\r\n", "> now_page : ", ObjectUtils.toString(now_page), "\r\n", "> end_page : ", ObjectUtils.toString(end_page), "\r\n", "> start_idx : ", ObjectUtils.toString(start_idx), "\r\n", "> virtual_idx : ", ObjectUtils.toString(virtual_idx), "\r\n", "==========================================================================" })); } public int getPage() { return this.page; } public void setPage(int page) { this.page = page; } public int getPage_row() { return this.page_row; } public void setPage_row(int page_row) { this.page_row = page_row; } public int getPage_link() { return this.page_link; } public void setPage_link(int page_link) { this.page_link = page_link; } public int getTotal_count() { return this.total_count; } public int getTotal_page() { return this.total_page; } public int getStart_page() { return this.start_page; } public int getNow_page() { return this.now_page; } public int getEnd_page() { return this.end_page; } public int getStart_idx() { return this.start_idx; } public int getVirtual_idx() { return this.virtual_idx; } }