b73d2d93c5182cc766d9b20425ccbd22892f443b
[sdc.git] /
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 public class GenericCollectionWrapper<T> implements Serializable {
28   private static final long serialVersionUID = 1L;
29
30   private transient List<T> results;
31   private int listCount;
32
33   public GenericCollectionWrapper() {
34     this.results = new ArrayList<>();
35   }
36
37   /**
38    * Instantiates a new Generic collection wrapper.
39    *
40    * @param list      the list
41    */
42   public GenericCollectionWrapper(List<T> list) {
43     if (!list.isEmpty()) {
44       this.results = list;
45       this.listCount = list.size();
46     }
47     else {
48       this.results = new ArrayList<>();
49     }
50   }
51
52   public List<T> getResults() {
53     return results;
54   }
55
56   public void setResults(List<T> results) {
57     this.results = results;
58   }
59
60   public int getListCount() {
61     return listCount;
62   }
63
64   public void setListCount(int listCount) {
65     this.listCount = listCount;
66   }
67
68   /**
69    * Add boolean.
70    *
71    * @param item the list item
72    * @return the boolean
73    */
74   public boolean add(T item) {
75     if (this.getResults().add(item)) {
76       this.setListCount(this.getResults().size());
77       return true;
78     }
79     return false;
80   }
81 }