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