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