01: /**
02: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the latest version of the GNU Lesser General
06: * Public License as published by the Free Software Foundation;
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program (LICENSE.txt); if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: */package org.jamwiki.utils;
17:
18: /**
19: * Utility class useful for paginating through a result set.
20: */
21: public class Pagination {
22:
23: /** Logger */
24: public static final WikiLogger logger = WikiLogger
25: .getLogger(Pagination.class.getName());
26:
27: private final int numResults;
28: private final int offset;
29:
30: /**
31: * Create a pagination object with specified initial values.
32: *
33: * @param numResults The maximum number of results that can be retrieved or
34: * displayed.
35: * @param offset The offset for the pagination. An offset of 100 indicates
36: * that the first 100 results should be ignored and numResults should be
37: * returned starting at 100.
38: */
39: public Pagination(int numResults, int offset) {
40: this .numResults = numResults;
41: this .offset = offset;
42: }
43:
44: /**
45: * Return the last result of the current pagination, equivalent to offset + numResults.
46: *
47: * @return Return the last result of the current pagination, equivalent to
48: * offset + numResults.
49: */
50: public int getEnd() {
51: return this .offset + this .numResults;
52: }
53:
54: /**
55: * Return the number of results that this pagination allows.
56: *
57: * @return The number of results that this pagination allows.
58: */
59: public int getNumResults() {
60: return this .numResults;
61: }
62:
63: /**
64: * Return the offset that this pagination allows. Offset indicates
65: * the starting point of any result to return, for example an offset of
66: * 10 with numResults of 5 indicates results 10-14.
67: *
68: * @return The offset that this pagination allows.
69: */
70: public int getOffset() {
71: return this .offset;
72: }
73:
74: /**
75: * Return the starting point of any pagination, which is equivalent to the
76: * offset. Offset indicates the starting point of any result to return,
77: * for example an offset of 10 with numResults of 5 indicates results 10-14.
78: *
79: * @return The starting point of any pagination.
80: */
81: public int getStart() {
82: return this.offset;
83: }
84: }
|