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