Merge of new rebased code
[appc.git] / appc-dg / appc-dg-shared / appc-dg-domain-model-lib / src / main / java / org / openecomp / appc / domainmodel / Vnfc.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.domainmodel;
23
24 import java.util.LinkedList;
25 import java.util.List;
26
27
28 public class Vnfc {
29
30     private String vnfcType;
31
32     public void setResilienceType(String resilienceType) {
33         this.resilienceType = resilienceType;
34     }
35
36     private String resilienceType;
37     private boolean mandatory;
38     private String vnfcName;
39     private List<Vserver> vserverList;
40
41     public Vnfc(String vnfcType,String resilienceType){
42         this(vnfcType,resilienceType,null, false);
43     }
44
45     public Vnfc(String vnfcType,String resilienceType,String vnfcName){
46         this(vnfcType,resilienceType,vnfcName, false);
47     }
48
49     public Vnfc(String vnfcType,String resilienceType,String vnfcName, boolean mandatory){
50         this.vnfcName = vnfcName;
51         this.vnfcType = vnfcType;
52         this.resilienceType = resilienceType;
53         this.mandatory = mandatory;
54         this.vserverList = new LinkedList<>();
55     }
56
57     @Override
58     public String toString() {
59         StringBuilder stringBuilder = new StringBuilder("Vnfc : vnfcType = " + vnfcType + ", vnfcName = " +vnfcName + ", resilienceType = " + resilienceType+", mandatory = " + mandatory);
60         for(Vserver vserver:vserverList){
61             stringBuilder.append(vserver.toString()).append(", \n");
62         }
63         return stringBuilder.toString();
64     }
65
66     @Override
67     public int hashCode(){
68         final int prime = 31;
69         int result = 1;
70         result = result * prime + (this.vnfcType == null ? 0 :this.vnfcType.hashCode());
71         result = result * prime + (this.resilienceType == null ? 0 :this.resilienceType.hashCode());
72         result = result * prime + (this.vnfcName == null ? 0 :this.vnfcName.hashCode());
73         result = result * prime + (Boolean.valueOf(this.mandatory).hashCode());
74         return result;
75     }
76     @Override
77     public boolean equals(Object object){
78         if(object == null){
79             return false;
80         }
81         if(!(object instanceof Vnfc)){
82             return false;
83         }
84         Vnfc vnfc = (Vnfc)object;
85
86         if(this.vnfcType == null){
87             if(vnfc.vnfcType !=null)
88                 return false;
89         }
90         else if(!this.vnfcType.equals(vnfc.vnfcType))
91             return false;
92
93         if(this.resilienceType == null){
94             if(vnfc.resilienceType !=null)
95                 return false;
96         }
97         else if(!this.resilienceType.equals(vnfc.resilienceType))
98             return false;
99
100         if(this.vnfcName == null){
101             if(vnfc.vnfcName !=null)
102                 return false;
103         }
104         else if(!this.vnfcName.equals(vnfc.vnfcName))
105             return false;
106         if (this.mandatory != vnfc.mandatory)
107             return false;
108         return true;
109     }
110
111     public void addVm(Vserver vserver){
112         this.vserverList.add(vserver);
113     }
114     public void addVms(List<Vserver> vserverList){
115         this.vserverList.addAll(vserverList);
116     }
117
118     public void setVnfcName(String vnfcName) {
119         this.vnfcName = vnfcName;
120     }
121
122     public String getVnfcType() {
123         return vnfcType;
124     }
125
126     public String getResilienceType() {
127         return resilienceType;
128     }
129
130     public String getVnfcName() {
131         return vnfcName;
132     }
133
134     public List<Vserver> getVserverList() {
135         return vserverList;
136     }
137
138     public boolean isMandatory() {
139         return mandatory;
140     }
141
142     public void setMandatory(boolean mandatory) {
143         this.mandatory = mandatory;
144     }
145 }