Bug 7759 - TEST - Getter of BA object fails to construct class instance
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / model / 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.mdsal.binding.model.util.generated.type.builder;
9
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
14 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
15 import org.opendaylight.mdsal.binding.model.api.Type;
16 import org.opendaylight.mdsal.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         this.parameters = LazyCollections.lazyAdd(this.parameters, new MethodParameterImpl(name, type));
38         this.unmodifiableParams = Collections.unmodifiableList(this.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(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic());
52     }
53
54     @Override
55     public int hashCode() {
56         final int prime = 31;
57         int result = 1;
58         result = (prime * result) + Objects.hashCode(getName());
59         result = (prime * result) + Objects.hashCode(this.parameters);
60         result = (prime * result) + Objects.hashCode(getReturnType());
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         final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
76         if (!Objects.equals(getName(), other.getName())) {
77             return false;
78         }
79         if (!Objects.equals(this.parameters, other.parameters)) {
80             return false;
81         }
82         if (!Objects.equals(getReturnType(), other.getReturnType())) {
83             return false;
84         }
85         return true;
86     }
87
88     @Override
89     public String toString() {
90         final StringBuilder builder = new StringBuilder();
91         builder.append("MethodSignatureBuilderImpl [name=");
92         builder.append(getName());
93         builder.append(", returnType=");
94         builder.append(getReturnType());
95         builder.append(", parameters=");
96         builder.append(this.parameters);
97         builder.append(", annotationBuilders=");
98         builder.append(getAnnotationBuilders());
99         builder.append(", comment=");
100         builder.append(getComment());
101         builder.append("]");
102         return builder.toString();
103     }
104 }