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 managing stopwords pagination.
25 * This class handles the state and logic for paginating through a list of stopwords,
26 * including total record count, page size, and current page number.
27 */
28 public class StopwordsPager implements Serializable {
29
30 /**
31 * Constructs a new pager for stopwords.
32 */
33 public StopwordsPager() {
34 // do nothing
35 }
36
37 private static final long serialVersionUID = 1L;
38
39 /** The total number of records. */
40 private int allRecordCount;
41
42 /** The total number of pages. */
43 private int allPageCount;
44
45 /** A flag indicating if a previous page exists. */
46 private boolean existPrePage;
47
48 /** A flag indicating if a next page exists. */
49 private boolean existNextPage;
50
51 /** A list of page numbers for navigation. */
52 private List<Integer> pageNumberList;
53
54 /** The number of records per page. */
55 private int pageSize;
56
57 /** The current page number. */
58 private int currentPageNumber;
59
60 /** The ID of the stopwords dictionary. */
61 public String id;
62
63 /**
64 * Clears the pager's state to its default values.
65 */
66 public void clear() {
67 allRecordCount = 0;
68 allPageCount = 0;
69 existPrePage = false;
70 existNextPage = false;
71 pageSize = getDefaultPageSize();
72 currentPageNumber = getDefaultCurrentPageNumber();
73
74 id = null;
75 }
76
77 /**
78 * Gets the default page size from the Fess configuration.
79 *
80 * @return The default page size.
81 */
82 protected int getDefaultPageSize() {
83 return ComponentUtil.getFessConfig().getPagingPageSizeAsInteger();
84 }
85
86 /**
87 * Gets the default current page number, which is 1.
88 *
89 * @return The default current page number.
90 */
91 protected int getDefaultCurrentPageNumber() {
92 return 1;
93 }
94
95 /**
96 * Gets the total number of records.
97 *
98 * @return The total record count.
99 */
100 public int getAllRecordCount() {
101 return allRecordCount;
102 }
103
104 /**
105 * Sets the total number of records.
106 *
107 * @param allRecordCount The total record count.
108 */
109 public void setAllRecordCount(final int allRecordCount) {
110 this.allRecordCount = allRecordCount;
111 }
112
113 /**
114 * Gets the total number of pages.
115 *
116 * @return The total page count.
117 */
118 public int getAllPageCount() {
119 return allPageCount;
120 }
121
122 /**
123 * Sets the total number of pages.
124 *
125 * @param allPageCount The total page count.
126 */
127 public void setAllPageCount(final int allPageCount) {
128 this.allPageCount = allPageCount;
129 }
130
131 /**
132 * Checks if a previous page exists.
133 *
134 * @return true if a previous page exists, false otherwise.
135 */
136 public boolean isExistPrePage() {
137 return existPrePage;
138 }
139
140 /**
141 * Sets the flag for the existence of a previous page.
142 *
143 * @param existPrePage true if a previous page exists.
144 */
145 public void setExistPrePage(final boolean existPrePage) {
146 this.existPrePage = existPrePage;
147 }
148
149 /**
150 * Checks if a next page exists.
151 *
152 * @return true if a next page exists, false otherwise.
153 */
154 public boolean isExistNextPage() {
155 return existNextPage;
156 }
157
158 /**
159 * Sets the flag for the existence of a next page.
160 *
161 * @param existNextPage true if a next page exists.
162 */
163 public void setExistNextPage(final boolean existNextPage) {
164 this.existNextPage = existNextPage;
165 }
166
167 /**
168 * Gets the page size.
169 *
170 * @return The page size.
171 */
172 public int getPageSize() {
173 if (pageSize <= 0) {
174 pageSize = getDefaultPageSize();
175 }
176 return pageSize;
177 }
178
179 /**
180 * Sets the page size.
181 *
182 * @param pageSize The page size.
183 */
184 public void setPageSize(final int pageSize) {
185 this.pageSize = pageSize;
186 }
187
188 /**
189 * Gets the current page number.
190 *
191 * @return The current page number.
192 */
193 public int getCurrentPageNumber() {
194 if (currentPageNumber <= 0) {
195 currentPageNumber = getDefaultCurrentPageNumber();
196 }
197 return currentPageNumber;
198 }
199
200 /**
201 * Sets the current page number.
202 *
203 * @param currentPageNumber The current page number.
204 */
205 public void setCurrentPageNumber(final int currentPageNumber) {
206 this.currentPageNumber = currentPageNumber;
207 }
208
209 /**
210 * Gets the list of page numbers for navigation.
211 *
212 * @return A list of page numbers.
213 */
214 public List<Integer> getPageNumberList() {
215 return pageNumberList;
216 }
217
218 /**
219 * Sets the list of page numbers for navigation.
220 *
221 * @param pageNumberList A list of page numbers.
222 */
223 public void setPageNumberList(final List<Integer> pageNumberList) {
224 this.pageNumberList = pageNumberList;
225 }
226 }