fd7665f557eafaead1b097b54fc431863dc68042
[usecase-ui/server.git] / src / main / java / org / onap / usecaseui / server / util / Page.java
1 /*
2  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.usecaseui.server.util;
17
18 import java.util.List;
19
20 public class Page<E> {
21
22         private List<E> list;
23
24         private int totalRecords;
25
26         private int pageSize;
27
28         private int pageNo;
29         
30         
31         
32         
33         public List<E> getList() {
34                 return list;
35         }
36
37         public void setList(List<E> list) {
38                 this.list = list;
39         }
40
41         public int getTotalRecords() {
42                 return totalRecords;
43         }
44
45         public void setTotalRecords(int totalRecords) {
46                 this.totalRecords = totalRecords;
47         }
48
49         public int getPageSize() {
50                 return pageSize;
51         }
52
53         public void setPageSize(int pageSize) {
54                 this.pageSize = pageSize;
55         }
56
57         public int getPageNo() {
58                 return pageNo;
59         }
60
61         public void setPageNo(int pageNo) {
62                 this.pageNo = pageNo;
63         }
64
65
66         public int getTotalPages() {
67                 return (totalRecords+pageSize-1)/pageSize;
68         }       
69         
70
71         public int countOffset(int currentPage,int pageSize) {
72                 int offset =pageSize*(currentPage-1);
73                 return offset;
74         }
75
76         public int getTopageNo() {
77                 return 1;
78         }
79
80         public int getPreviousPageNo() {
81                 if(pageNo<=1) {
82                         return 1;
83                 }
84                 return pageNo-1;
85         }
86
87         public int getNextPageNo() {
88                 if(pageNo>=getBottomPageNo()) {
89                         return getBottomPageNo();
90                 }
91                 return pageNo+1;
92         }
93
94         public int getBottomPageNo() {
95                 return getTotalPages();
96         }
97         
98 }