push addional code
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / openecomp-sdc-common-rest / src / main / java / org / openecomp / sdcrests / wrappers / GenericCollectionWrapper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdcrests.wrappers;
22
23 import java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 /**
28  * This class represents a generic collection wrapper to be used by paginated results.
29  *
30  * @param <T> the type parameter
31  */
32 public class GenericCollectionWrapper<T> implements Serializable {
33   private static final long serialVersionUID = 1L;
34
35   private List<T> results;
36   private int listCount;
37
38   /**
39    * Instantiates a new Generic collection wrapper.
40    */
41   public GenericCollectionWrapper() {
42     this.results = new ArrayList<>();
43   }
44
45   /**
46    * Instantiates a new Generic collection wrapper.
47    *
48    * @param list      the list
49    * @param listCount the list count
50    */
51   public GenericCollectionWrapper(List<T> list, int listCount) {
52     if (!list.isEmpty()) {
53       this.results = list;
54       this.listCount = listCount;
55     }
56   }
57
58   /**
59    * Gets results.
60    *
61    * @return the results
62    */
63   public List<T> getResults() {
64     return results;
65   }
66
67   /**
68    * Sets results.
69    *
70    * @param results the results
71    */
72   public void setResults(List<T> results) {
73     this.results = results;
74   }
75
76   /**
77    * Gets list count.
78    *
79    * @return the list count
80    */
81   public int getListCount() {
82     return listCount;
83   }
84
85   /**
86    * Sets list count.
87    *
88    * @param listCount the list count
89    */
90   public void setListCount(int listCount) {
91     this.listCount = listCount;
92   }
93
94   /**
95    * Add boolean.
96    *
97    * @param e0 the e 0
98    * @return the boolean
99    */
100   public boolean add(T e0) {
101     if (this.getResults().add(e0)) {
102       this.setListCount(this.getResults().size());
103       return true;
104     }
105     return false;
106   }
107 }