8bd1b263320167602648eba3a085c515f4f1fd06
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.tosca.datatypes.model;
18
19 import org.apache.commons.collections4.MapUtils;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 public class InterfaceDefinitionType extends InterfaceDefinition {
25
26   private String type;
27   private Map<String, PropertyDefinition> inputs;
28   protected Map<String, OperationDefinitionType> operations;
29
30   public String getType() {
31     return type;
32   }
33
34   public void setType(String type) {
35     this.type = type;
36   }
37
38   public Map<String, PropertyDefinition> getInputs() {
39     return inputs;
40   }
41
42   public void setInputs(
43       Map<String, PropertyDefinition> inputs) {
44     this.inputs = inputs;
45   }
46
47   public Map<String, OperationDefinitionType> getOperations() {
48     return operations;
49   }
50
51   public void setOperations(
52       Map<String, OperationDefinitionType> operations) {
53     this.operations = operations;
54   }
55
56   public void addOperation(String operationName, OperationDefinitionType operation) {
57     if(MapUtils.isEmpty(this.operations)) {
58       this.operations = new HashMap<>();
59     }
60
61     this.operations.put(operationName, operation);
62   }
63
64   @Override
65   public boolean equals(Object o) {
66     if (this == o) {
67       return true;
68     }
69     if (!(o instanceof InterfaceDefinitionType)) {
70       return false;
71     }
72
73     InterfaceDefinitionType that = (InterfaceDefinitionType) o;
74
75     if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) {
76       return false;
77     }
78     if (getInputs() != null ? !getInputs().equals(that.getInputs()) : that.getInputs() != null) {
79       return false;
80     }
81     return getOperations() != null ? getOperations().equals(that.getOperations())
82         : that.getOperations() == null;
83   }
84
85   @Override
86   public int hashCode() {
87     int result = getType() != null ? getType().hashCode() : 0;
88     result = 31 * result + (getInputs() != null ? getInputs().hashCode() : 0);
89     result = 31 * result + (getOperations() != null ? getOperations().hashCode() : 0);
90     return result;
91   }
92
93   @Override
94   public void addOperation(String operationName, OperationDefinition operationDefinition) {
95     addOperation(operationName, (OperationDefinitionType)operationDefinition);
96   }
97 }