ebb68647bfe8d9206e27500494f08e95e26fec06
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-util / src / main / java / org / opendaylight / controller / binding / generator / util / generated / type / builder / MethodSignatureBuilderImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
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;
18
19 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder {
20
21     private final List<MethodSignature.Parameter> parameters;
22     private boolean isAbstract;
23
24     public MethodSignatureBuilderImpl(final String name) {
25         super(name);
26         this.parameters = new ArrayList<>();
27     }
28
29     @Override
30     public void setAbstract(boolean isAbstract) {
31         this.isAbstract = isAbstract;
32     }
33
34     @Override
35     public void addParameter(Type type, String name) {
36         parameters.add(new MethodParameterImpl(name, type));
37     }
38
39     @Override
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);
44     }
45     
46     @Override
47     public int hashCode() {
48         final int prime = 31;
49         int result = 1;
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());
55         return result;
56     }
57
58     @Override
59     public boolean equals(Object obj) {
60         if (this == obj) {
61             return true;
62         }
63         if (obj == null) {
64             return false;
65         }
66         if (getClass() != obj.getClass()) {
67             return false;
68         }
69         MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
70         if (getName() == null) {
71             if (other.getName() != null) {
72                 return false;
73             }
74         } else if (!getName().equals(other.getName())) {
75             return false;
76         }
77         if (parameters == null) {
78             if (other.parameters != null) {
79                 return false;
80             }
81         } else if (!parameters.equals(other.parameters)) {
82             return false;
83         }
84         if (getReturnType() == null) {
85             if (other.getReturnType() != null) {
86                 return false;
87             }
88         } else if (!getReturnType().equals(other.getReturnType())) {
89             return false;
90         }
91         return true;
92     }
93
94     @Override
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());
107         builder.append("]");
108         return builder.toString();
109     }
110 }