View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib.to;
20  
21  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
23  import java.net.URI;
24  import java.util.ArrayList;
25  import java.util.List;
26  import org.apache.commons.lang3.builder.EqualsBuilder;
27  import org.apache.commons.lang3.builder.HashCodeBuilder;
28  import org.apache.syncope.common.lib.BaseBean;
29  
30  public class PagedResult<T extends BaseBean> implements BaseBean {
31  
32      private static final long serialVersionUID = 3472875885259250934L;
33  
34      private URI prev;
35  
36      private URI next;
37  
38      private final List<T> result = new ArrayList<>();
39  
40      private int page;
41  
42      private int size;
43  
44      private int totalCount;
45  
46      public URI getPrev() {
47          return prev;
48      }
49  
50      public void setPrev(final URI prev) {
51          this.prev = prev;
52      }
53  
54      public URI getNext() {
55          return next;
56      }
57  
58      public void setNext(final URI next) {
59          this.next = next;
60      }
61  
62      @JacksonXmlElementWrapper(localName = "result")
63      @JacksonXmlProperty(localName = "item")
64      public List<T> getResult() {
65          return result;
66      }
67  
68      public int getPage() {
69          return page;
70      }
71  
72      public void setPage(final int page) {
73          this.page = page;
74      }
75  
76      public int getSize() {
77          return size;
78      }
79  
80      public void setSize(final int size) {
81          this.size = size;
82      }
83  
84      public int getTotalCount() {
85          return totalCount;
86      }
87  
88      public void setTotalCount(final int totalCount) {
89          this.totalCount = totalCount;
90      }
91  
92      @Override
93      public int hashCode() {
94          return new HashCodeBuilder().
95                  append(prev).
96                  append(next).
97                  append(result).
98                  append(page).
99                  append(size).
100                 append(totalCount).
101                 build();
102     }
103 
104     @Override
105     public boolean equals(final Object obj) {
106         if (this == obj) {
107             return true;
108         }
109         if (obj == null) {
110             return false;
111         }
112         if (getClass() != obj.getClass()) {
113             return false;
114         }
115         @SuppressWarnings("unchecked")
116         final PagedResult<T> other = (PagedResult<T>) obj;
117         return new EqualsBuilder().
118                 append(prev, other.prev).
119                 append(next, other.next).
120                 append(result, other.result).
121                 append(page, other.page).
122                 append(size, other.size).
123                 append(totalCount, other.totalCount).
124                 build();
125     }
126 }