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.Optional;
23 import org.apache.commons.collections4.MapUtils;
24 import org.onap.sdc.tosca.services.DataModelCloneUtil;
26 public class InterfaceDefinitionType extends InterfaceDefinition {
29 private Map<String, PropertyDefinition> inputs;
30 private Map<String, OperationDefinitionType> operations;
32 public InterfaceDefinitionType() {
35 public InterfaceDefinitionType(Object toscaInterfaceDefinitionType) {
36 InterfaceDefinitionType interfaceDefinitionType =
37 (InterfaceDefinitionType) convertObjToInterfaceDefinition(toscaInterfaceDefinitionType);
38 this.setType(interfaceDefinitionType.getType());
39 this.setInputs(DataModelCloneUtil.cloneStringPropertyDefinitionMap(interfaceDefinitionType.getInputs()));
41 DataModelCloneUtil.cloneStringOperationDefinitionMap(interfaceDefinitionType.getOperations()));
44 public String getType() {
48 public void setType(String type) {
52 public Map<String, PropertyDefinition> getInputs() {
56 public void setInputs(Map<String, PropertyDefinition> inputs) {
60 public Map<String, OperationDefinitionType> getOperations() {
64 public void setOperations(Map<String, OperationDefinitionType> operations) {
65 this.operations = operations;
69 public boolean equals(Object o) {
73 if (!(o instanceof InterfaceDefinitionType)) {
77 InterfaceDefinitionType that = (InterfaceDefinitionType) o;
79 if (getType() != null ? !getType().equals(that.getType()) : that.getType() != null) {
82 if (getInputs() != null ? !getInputs().equals(that.getInputs()) : that.getInputs() != null) {
85 return getOperations() != null ? getOperations().equals(that.getOperations()) : that.getOperations() == null;
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);
97 public void addOperation(String operationName, OperationDefinition operationDefinition) {
98 addOperation(operationName, (OperationDefinitionType) operationDefinition);
101 private void addOperation(String operationName, OperationDefinitionType operation) {
102 if (MapUtils.isEmpty(this.operations)) {
103 this.operations = new HashMap<>();
105 this.operations.put(operationName, operation);
108 public Optional<Object> convertInterfaceDefinitionTypeToToscaObj() {
109 return convertInterfaceToToscaInterfaceObj(this);