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.MethodSignatureBuilder;
18 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder {
20 private final List<MethodSignature.Parameter> parameters;
21 private boolean isAbstract;
23 public MethodSignatureBuilderImpl(final String name) {
25 this.parameters = new ArrayList<>();
29 public void setAbstract(boolean isAbstract) {
30 this.isAbstract = isAbstract;
34 public void addParameter(Type type, String name) {
35 parameters.add(new MethodParameterImpl(name, type));
39 public MethodSignature toInstance(Type definingType) {
40 final List<AnnotationType> annotations = toAnnotationTypes();
41 return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
42 getReturnType(), parameters, isFinal(), isAbstract);
46 public int hashCode() {
49 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
50 result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
51 result = prime * result + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
56 public boolean equals(Object obj) {
63 if (getClass() != obj.getClass()) {
66 MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
67 if (getName() == null) {
68 if (other.getName() != null) {
71 } else if (!getName().equals(other.getName())) {
74 if (parameters == null) {
75 if (other.parameters != null) {
78 } else if (!parameters.equals(other.parameters)) {
81 if (getReturnType() == null) {
82 if (other.getReturnType() != null) {
85 } else if (!getReturnType().equals(other.getReturnType())) {
92 public String toString() {
93 StringBuilder builder = new StringBuilder();
94 builder.append("MethodSignatureBuilderImpl [name=");
95 builder.append(getName());
96 builder.append(", returnType=");
97 builder.append(getReturnType());
98 builder.append(", parameters=");
99 builder.append(parameters);
100 builder.append(", annotationBuilders=");
101 builder.append(getAnnotationBuilders());
102 builder.append(", comment=");
103 builder.append(getComment());
105 return builder.toString();