2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
10 import java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
14 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
15 import org.opendaylight.controller.sal.binding.model.api.Type;
16 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
17 import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
19 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder {
21 private final List<MethodSignature.Parameter> parameters;
22 private boolean isAbstract;
24 public MethodSignatureBuilderImpl(final String name) {
26 this.parameters = new ArrayList<>();
30 public void setAbstract(boolean isAbstract) {
31 this.isAbstract = isAbstract;
35 public void addParameter(Type type, String name) {
36 parameters.add(new MethodParameterImpl(name, type));
40 public MethodSignature toInstance(Type definingType) {
41 final List<AnnotationType> annotations = toAnnotationTypes();
42 return new MethodSignatureImpl(definingType, getName(), annotations,
43 getComment(), getAccessModifier(), getReturnType(), parameters, isFinal(), isAbstract);
47 public int hashCode() {
50 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
51 result = prime * result
52 + ((parameters == null) ? 0 : parameters.hashCode());
53 result = prime * result
54 + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
59 public boolean equals(Object obj) {
66 if (getClass() != obj.getClass()) {
69 MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
70 if (getName() == null) {
71 if (other.getName() != null) {
74 } else if (!getName().equals(other.getName())) {
77 if (parameters == null) {
78 if (other.parameters != null) {
81 } else if (!parameters.equals(other.parameters)) {
84 if (getReturnType() == null) {
85 if (other.getReturnType() != null) {
88 } else if (!getReturnType().equals(other.getReturnType())) {
95 public String toString() {
96 StringBuilder builder = new StringBuilder();
97 builder.append("MethodSignatureBuilderImpl [name=");
98 builder.append(getName());
99 builder.append(", returnType=");
100 builder.append(getReturnType());
101 builder.append(", parameters=");
102 builder.append(parameters);
103 builder.append(", annotationBuilders=");
104 builder.append(getAnnotationBuilders());
105 builder.append(", comment=");
106 builder.append(getComment());
108 return builder.toString();