Bug 1411-3: MDSAL Binding2 Generator Util
[mdsal.git] / binding2 / mdsal-binding2-generator-util / src / main / java / org / opendaylight / mdsal / binding2 / 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.mdsal.binding2.generator.util.generated.type.builder;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.mdsal.binding2.model.api.AnnotationType;
16 import org.opendaylight.mdsal.binding2.model.api.MethodSignature;
17 import org.opendaylight.mdsal.binding2.model.api.Type;
18 import org.opendaylight.mdsal.binding2.model.api.type.builder.MethodSignatureBuilder;
19 import org.opendaylight.yangtools.util.LazyCollections;
20
21 @Beta
22 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodSignatureBuilder> implements MethodSignatureBuilder {
23
24     private List<MethodSignature.Parameter> parameters = ImmutableList.of();
25     private List<MethodSignature.Parameter> unmodifiableParams  = ImmutableList.of();
26     private boolean isAbstract;
27
28     public MethodSignatureBuilderImpl(final String name) {
29         super(name);
30     }
31
32     @Override
33     public MethodSignatureBuilder setAbstract(final boolean isAbstract) {
34         this.isAbstract = isAbstract;
35         return this;
36     }
37
38     @Override
39     public MethodSignatureBuilder addParameter(final Type type, final String name) {
40         parameters = LazyCollections.lazyAdd(parameters, new MethodParameterImpl(name, type));
41         unmodifiableParams = Collections.unmodifiableList(parameters);
42         return this;
43     }
44
45     @Override
46     protected MethodSignatureBuilder thisInstance() {
47         return this;
48     }
49
50     @Override
51     public MethodSignature toInstance(final Type definingType) {
52         final List<AnnotationType> annotations = toAnnotationTypes();
53         return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
54                 getReturnType(), unmodifiableParams, isFinal(), isAbstract, isStatic());
55     }
56
57     @Override
58     public int hashCode() {
59         return Objects.hash(getName(), parameters, getReturnType());
60     }
61
62     @Override
63     public boolean equals(final 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 (!Objects.equals(getName(), other.getName())) {
75             return false;
76         }
77         if (!Objects.equals(parameters, other.parameters)) {
78             return false;
79         }
80         if (!Objects.equals(getReturnType(), other.getReturnType())) {
81             return false;
82         }
83         return true;
84     }
85
86     @Override
87     public String toString() {
88         StringBuilder builder = new StringBuilder();
89         builder.append("MethodSignatureBuilderImpl [name=");
90         builder.append(getName());
91         builder.append(", returnType=");
92         builder.append(getReturnType());
93         builder.append(", parameters=");
94         builder.append(parameters);
95         builder.append(", annotationBuilders=");
96         builder.append(getAnnotationBuilders());
97         builder.append(", comment=");
98         builder.append(getComment());
99         builder.append("]");
100         return builder.toString();
101     }
102 }