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.
18 package org.onap.sdc.tosca.datatypes.model;
20 import java.util.HashMap;
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;
27 public class InterfaceDefinitionType extends InterfaceDefinition {
30 private Map<String, PropertyDefinition> inputs;
31 private Map<String, OperationDefinitionType> operations;
33 public InterfaceDefinitionType() {
36 public InterfaceDefinitionType(Object toscaInterfaceDefinitionType) {
37 InterfaceDefinitionType interfaceDefinitionType =
38 (InterfaceDefinitionType) convertObjToInterfaceDefinition(toscaInterfaceDefinitionType);
39 this.setType(interfaceDefinitionType.getType());
40 this.setInputs(DataModelCloneUtil.cloneStringPropertyDefinitionMap(interfaceDefinitionType.getInputs()));
42 DataModelCloneUtil.cloneStringOperationDefinitionMap(interfaceDefinitionType.getOperations()));
45 public String getType() {
49 public void setType(String type) {
53 public Map<String, PropertyDefinition> getInputs() {
57 public void setInputs(Map<String, PropertyDefinition> inputs) {
61 public Map<String, OperationDefinitionType> getOperations() {
65 public void setOperations(Map<String, OperationDefinitionType> operations) {
66 this.operations = operations;
70 public boolean equals(Object o) {
74 if (o == null || getClass() != o.getClass()) {
77 InterfaceDefinitionType that = (InterfaceDefinitionType) o;
78 return Objects.equals(type, that.type)
79 && Objects.equals(inputs, that.inputs)
80 && Objects.equals(operations, that.operations);
84 public int hashCode() {
85 return Objects.hash(type, inputs, operations);
89 public void addOperation(String operationName, OperationDefinition operationDefinition) {
90 addOperation(operationName, (OperationDefinitionType) operationDefinition);
93 private void addOperation(String operationName, OperationDefinitionType operation) {
94 if (MapUtils.isEmpty(this.operations)) {
95 this.operations = new HashMap<>();
97 this.operations.put(operationName, operation);
100 public Optional<Object> convertInterfaceDefinitionTypeToToscaObj() {
101 return convertInterfaceToToscaInterfaceObj(this);