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