2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.sdc.tosca.datatypes.model;
18 import java.util.HashMap;
20 import java.util.Objects;
21 import java.util.Optional;
22 import org.apache.commons.collections4.MapUtils;
23 import org.onap.sdc.tosca.services.DataModelCloneUtil;
25 public class InterfaceDefinitionType extends InterfaceDefinition {
28 private Map<String, PropertyDefinition> inputs;
29 private Map<String, OperationDefinitionType> operations;
31 public InterfaceDefinitionType() {
34 public InterfaceDefinitionType(Object toscaInterfaceDefinitionType) {
35 InterfaceDefinitionType interfaceDefinitionType = (InterfaceDefinitionType) convertObjToInterfaceDefinition(toscaInterfaceDefinitionType);
36 this.setType(interfaceDefinitionType.getType());
37 this.setInputs(DataModelCloneUtil.cloneStringPropertyDefinitionMap(interfaceDefinitionType.getInputs()));
38 this.setOperations(DataModelCloneUtil.cloneStringOperationDefinitionMap(interfaceDefinitionType.getOperations()));
41 public String getType() {
45 public void setType(String type) {
49 public Map<String, PropertyDefinition> getInputs() {
53 public void setInputs(Map<String, PropertyDefinition> inputs) {
57 public Map<String, OperationDefinitionType> getOperations() {
61 public void setOperations(Map<String, OperationDefinitionType> operations) {
62 this.operations = operations;
66 public boolean equals(Object o) {
70 if (o == null || getClass() != o.getClass()) {
73 InterfaceDefinitionType that = (InterfaceDefinitionType) o;
74 return Objects.equals(type, that.type) && Objects.equals(inputs, that.inputs) && Objects.equals(operations, that.operations);
78 public int hashCode() {
79 return Objects.hash(type, inputs, operations);
83 public void addOperation(String operationName, OperationDefinition operationDefinition) {
84 addOperation(operationName, (OperationDefinitionType) operationDefinition);
87 private void addOperation(String operationName, OperationDefinitionType operation) {
88 if (MapUtils.isEmpty(this.operations)) {
89 this.operations = new HashMap<>();
91 this.operations.put(operationName, operation);
94 public Optional<Object> convertInterfaceDefinitionTypeToToscaObj() {
95 return convertInterfaceToToscaInterfaceObj(this);