jsp学習ノート(10)

2000 ワード

package util;
	/**
	* <p> </p>
	*/
	public class PageUtil {
		private int pageSize; // 
		private int recordCount;// 
		private int currentPage;// 
		public PageUtil(int pageSize, int recordCount, int currentPage) {
			this.pageSize = pageSize;
			this.recordCount = recordCount;
			setCurrentPage(currentPage);
		} 
		public PageUtil(int pageSize, int recordCount) {
			this(pageSize, recordCount, 1);
		} 
		/**
		*<p> </p>
		* @return
		*/
		public int getPageCount() {
			int size = recordCount/pageSize;
			int mod = recordCount % pageSize;
			if(mod != 0)
				size++;
			return recordCount == 0 ? 1 : size;
		}
		/**
		* <p> </p>
		* @return
		*/
		public int getCurrentPage() {
			return currentPage;
		}
		/**
		* <p> </p>
		* @return
		*/
		public void setCurrentPage(int currentPage) {
			int validPage = currentPage <= 0 ? 1 : currentPage;
			validPage = validPage > getPageCount() ? getPageCount() : validPage;
			this.currentPage = validPage;
		}
		/**
         * <p> </p>
         * @return
         */
        public int getPageSize() {
            return pageSize;
        }
		/**
		* <p> </p>
		* @return
		 */
        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
        }
		/**
		* <p> </p>
		* @return
		*/
        public int getRecordCount() {
            return recordCount;
        }
        /**
         * <p> </p>
         * @return
         */
		public void setRecordCount(int recordCount) {
            this.recordCount = recordCount;
		}
	}