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