1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.app.pager;
17
18 import java.io.Serializable;
19 import java.util.List;
20
21 import org.codelibs.fess.util.ComponentUtil;
22
23 /**
24 * Pager for KeyMatch.
25 */
26 public class KeyMatchPager implements Serializable {
27
28 private static final long serialVersionUID = 1L;
29
30 /**
31 * Default constructor.
32 */
33 public KeyMatchPager() {
34 // Default constructor
35 }
36
37 /** The default page size. */
38 public static final int DEFAULT_PAGE_SIZE = 20;
39
40 /** The default current page number. */
41 public static final int DEFAULT_CURRENT_PAGE_NUMBER = 1;
42
43 /** The total number of records. */
44 private int allRecordCount;
45
46 /** The total number of pages. */
47 private int allPageCount;
48
49 /** True if a previous page exists. */
50 private boolean existPrePage;
51
52 /** True if a next page exists. */
53 private boolean existNextPage;
54
55 /** The list of page numbers. */
56 private List<Integer> pageNumberList;
57
58 /** The size of a page. */
59 private int pageSize;
60
61 /** The current page number. */
62 private int currentPageNumber;
63
64 /** The ID of the key match. */
65 public String id;
66
67 /** The term of the key match. */
68 public String term;
69
70 /** The query of the key match. */
71 public String query;
72
73 /** The max size of the key match. */
74 public String maxSize;
75
76 /** The boost of the key match. */
77 public String boost;
78
79 /** The creator of the key match. */
80 public String createdBy;
81
82 /** The created time of the key match. */
83 public String createdTime;
84
85 /** The version number of the key match. */
86 public String versionNo;
87
88 /**
89 * Clears the pager fields.
90 */
91 public void clear() {
92 allRecordCount = 0;
93 allPageCount = 0;
94 existPrePage = false;
95 existNextPage = false;
96 pageSize = getDefaultPageSize();
97 currentPageNumber = getDefaultCurrentPageNumber();
98
99 id = null;
100 term = null;
101 query = null;
102 maxSize = null;
103 boost = null;
104 createdBy = null;
105 createdTime = null;
106 versionNo = null;
107
108 }
109
110 /**
111 * Returns the default current page number.
112 *
113 * @return The default current page number.
114 */
115 protected int getDefaultCurrentPageNumber() {
116 return DEFAULT_CURRENT_PAGE_NUMBER;
117 }
118
119 /**
120 * Returns the total number of records.
121 *
122 * @return The total number of records.
123 */
124 public int getAllRecordCount() {
125 return allRecordCount;
126 }
127
128 /**
129 * Sets the total number of records.
130 *
131 * @param allRecordCount The total number of records.
132 */
133 public void setAllRecordCount(final int allRecordCount) {
134 this.allRecordCount = allRecordCount;
135 }
136
137 /**
138 * Returns the total number of pages.
139 *
140 * @return The total number of pages.
141 */
142 public int getAllPageCount() {
143 return allPageCount;
144 }
145
146 /**
147 * Sets the total number of pages.
148 *
149 * @param allPageCount The total number of pages.
150 */
151 public void setAllPageCount(final int allPageCount) {
152 this.allPageCount = allPageCount;
153 }
154
155 /**
156 * Returns true if a previous page exists.
157 *
158 * @return True if a previous page exists.
159 */
160 public boolean isExistPrePage() {
161 return existPrePage;
162 }
163
164 /**
165 * Sets whether a previous page exists.
166 *
167 * @param existPrePage True if a previous page exists.
168 */
169 public void setExistPrePage(final boolean existPrePage) {
170 this.existPrePage = existPrePage;
171 }
172
173 /**
174 * Returns true if a next page exists.
175 *
176 * @return True if a next page exists.
177 */
178 public boolean isExistNextPage() {
179 return existNextPage;
180 }
181
182 /**
183 * Sets whether a next page exists.
184 *
185 * @param existNextPage True if a next page exists.
186 */
187 public void setExistNextPage(final boolean existNextPage) {
188 this.existNextPage = existNextPage;
189 }
190
191 /**
192 * Returns the page size.
193 *
194 * @return The page size.
195 */
196 public int getPageSize() {
197 if (pageSize <= 0) {
198 pageSize = getDefaultPageSize();
199 }
200 return pageSize;
201 }
202
203 /**
204 * Sets the page size.
205 *
206 * @param pageSize The page size.
207 */
208 public void setPageSize(final int pageSize) {
209 this.pageSize = pageSize;
210 }
211
212 /**
213 * Returns the current page number.
214 *
215 * @return The current page number.
216 */
217 public int getCurrentPageNumber() {
218 if (currentPageNumber <= 0) {
219 currentPageNumber = getDefaultCurrentPageNumber();
220 }
221 return currentPageNumber;
222 }
223
224 /**
225 * Sets the current page number.
226 *
227 * @param currentPageNumber The current page number.
228 */
229 public void setCurrentPageNumber(final int currentPageNumber) {
230 this.currentPageNumber = currentPageNumber;
231 }
232
233 /**
234 * Returns the list of page numbers.
235 *
236 * @return The list of page numbers.
237 */
238 public List<Integer> getPageNumberList() {
239 return pageNumberList;
240 }
241
242 /**
243 * Sets the list of page numbers.
244 *
245 * @param pageNumberList The list of page numbers.
246 */
247 public void setPageNumberList(final List<Integer> pageNumberList) {
248 this.pageNumberList = pageNumberList;
249 }
250
251 /**
252 * Returns the default page size.
253 *
254 * @return The default page size.
255 */
256 protected int getDefaultPageSize() {
257 return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
258 }
259
260 }