Added NotificationListener interfaces
[yangtools.git] / code-generator / binding-generator-util / src / main / java / org / opendaylight / yangtools / 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.yangtools.binding.generator.util.generated.type.builder;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
14 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
15 import org.opendaylight.yangtools.sal.binding.model.api.Type;
16 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
17
18 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodSignatureBuilder> implements MethodSignatureBuilder {
19
20     private final List<MethodSignature.Parameter> parameters;
21     private boolean isAbstract;
22
23     public MethodSignatureBuilderImpl(final String name) {
24         super(name);
25         this.parameters = new ArrayList<>();
26     }
27
28     @Override
29     public MethodSignatureBuilder setAbstract(boolean isAbstract) {
30         this.isAbstract = isAbstract;
31         return this;
32     }
33
34     @Override
35     public MethodSignatureBuilder addParameter(Type type, String name) {
36         parameters.add(new MethodParameterImpl(name, type));
37         return this;
38     }
39
40 @Override
41     protected MethodSignatureBuilder thisInstance() {
42         return this;
43     }
44     
45     @Override
46     public MethodSignature toInstance(Type definingType) {
47         final List<AnnotationType> annotations = toAnnotationTypes();
48         return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
49                 getReturnType(), parameters, isFinal(), isAbstract);
50     }
51
52     @Override
53     public int hashCode() {
54         final int prime = 31;
55         int result = 1;
56         result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
57         result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
58         result = prime * result + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
59         return result;
60     }
61
62     @Override
63     public boolean equals(Object obj) {
64         if (this == obj) {
65             return true;
66         }
67         if (obj == null) {
68             return false;
69         }
70         if (getClass() != obj.getClass()) {
71             return false;
72         }
73         MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
74         if (getName() == null) {
75             if (other.getName() != null) {
76                 return false;
77             }
78         } else if (!getName().equals(other.getName())) {
79             return false;
80         }
81         if (parameters == null) {
82             if (other.parameters != null) {
83                 return false;
84             }
85         } else if (!parameters.equals(other.parameters)) {
86             return false;
87         }
88         if (getReturnType() == null) {
89             if (other.getReturnType() != null) {
90                 return false;
91             }
92         } else if (!getReturnType().equals(other.getReturnType())) {
93             return false;
94         }
95         return true;
96     }
97
98     @Override
99     public String toString() {
100         StringBuilder builder = new StringBuilder();
101         builder.append("MethodSignatureBuilderImpl [name=");
102         builder.append(getName());
103         builder.append(", returnType=");
104         builder.append(getReturnType());
105         builder.append(", parameters=");
106         builder.append(parameters);
107         builder.append(", annotationBuilders=");
108         builder.append(getAnnotationBuilders());
109         builder.append(", comment=");
110         builder.append(getComment());
111         builder.append("]");
112         return builder.toString();
113     }
114 }