5f0ea6ae928ded2118388011e680408b2389de61
[sdc.git] / common / onap-tosca-datatype / src / main / java / org / onap / sdc / tosca / datatypes / model / InterfaceDefinitionType.java
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
18 package org.onap.sdc.tosca.datatypes.model;
19
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.Optional;
23 import org.apache.commons.collections4.MapUtils;
24 import org.onap.sdc.tosca.services.DataModelCloneUtil;
25
26 public class InterfaceDefinitionType extends InterfaceDefinition {
27
28     private String type;
29     private Map<String, PropertyDefinition> inputs;
30     private Map<String, OperationDefinitionType> operations;
31
32     public InterfaceDefinitionType() {
33     }
34
35     public InterfaceDefinitionType(Object toscaInterfaceDefinitionType) {
36         InterfaceDefinitionType interfaceDefinitionType =
37                 (InterfaceDefinitionType) convertObjToInterfaceDefinition(toscaInterfaceDefinitionType);
38         this.setType(interfaceDefinitionType.getType());
39         this.setInputs(DataModelCloneUtil.cloneStringPropertyDefinitionMap(interfaceDefinitionType.getInputs()));
40         this.setOperations(
41                 DataModelCloneUtil.cloneStringOperationDefinitionMap(interfaceDefinitionType.getOperations()));
42     }
43
44     public String getType() {
45         return type;
46     }
47
48     public void setType(String type) {
49         this.type = type;
50     }
51
52     public Map<String, PropertyDefinition> getInputs() {
53         return inputs;
54     }
55
56     public void setInputs(Map<String, PropertyDefinition> inputs) {
57         this.inputs = inputs;
58     }
59
60     public Map<String, OperationDefinitionType> getOperations() {
61         return operations;
62     }
63
64     public void setOperations(Map<String, OperationDefinitionType> operations) {
65         this.operations = operations;
66     }
67
68     @Override
69     public boolean equals(Object o) {
70         if (this == o) {
71             return true;
72         }
73         if (!(o instanceof InterfaceDefinitionType)) {
74             return false;
75         }
76
77         InterfaceDefinitionType that = (InterfaceDefinitionType) o;
78
79         if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) {
80             return false;
81         }
82         if (getInputs() != null ? !getInputs().equals(that.getInputs()) : that.getInputs() != null) {
83             return false;
84         }
85         return getOperations() != null ? getOperations().equals(that.getOperations()) : that.getOperations() == null;
86     }
87
88     @Override
89     public int hashCode() {
90         int result = getType() != null ? getType().hashCode() : 0;
91         result = 31 * result + (getInputs() != null ? getInputs().hashCode() : 0);
92         result = 31 * result + (getOperations() != null ? getOperations().hashCode() : 0);
93         return result;
94     }
95
96     @Override
97     public void addOperation(String operationName, OperationDefinition operationDefinition) {
98         addOperation(operationName, (OperationDefinitionType) operationDefinition);
99     }
100
101     private void addOperation(String operationName, OperationDefinitionType operation) {
102         if (MapUtils.isEmpty(this.operations)) {
103             this.operations = new HashMap<>();
104         }
105         this.operations.put(operationName, operation);
106     }
107
108     public Optional<Object> convertInterfaceDefinitionTypeToToscaObj() {
109         return convertInterfaceToToscaInterfaceObj(this);
110     }
111
112 }