Generate @param for RPC invocation methods
[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 static java.util.Objects.requireNonNull;
11
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
16 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
17 import org.opendaylight.mdsal.binding.model.api.MethodSignature.ValueMechanics;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder;
20 import org.opendaylight.yangtools.util.LazyCollections;
21
22 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodSignatureBuilder>
23         implements MethodSignatureBuilder {
24     private List<MethodSignature.Parameter> parameters = Collections.emptyList();
25     private List<MethodSignature.Parameter> unmodifiableParams = Collections.emptyList();
26     private ValueMechanics mechanics = ValueMechanics.NORMAL;
27     private boolean isAbstract;
28     private boolean isDefault;
29
30     MethodSignatureBuilderImpl(final String name) {
31         super(name);
32     }
33
34     @Override
35     public MethodSignatureBuilder setAbstract(final boolean newIsAbstract) {
36         this.isAbstract = newIsAbstract;
37         return this;
38     }
39
40     @Override
41     public MethodSignatureBuilder setDefault(final boolean newIsDefault) {
42         this.isDefault = newIsDefault;
43         return this;
44     }
45
46     @Override
47     public MethodSignatureBuilder setMechanics(final ValueMechanics newMechanics) {
48         this.mechanics = requireNonNull(newMechanics);
49         return this;
50     }
51
52     @Override
53     public MethodSignatureBuilder addParameter(final Type type, final String name) {
54         this.parameters = LazyCollections.lazyAdd(this.parameters, new MethodParameterImpl(name, type));
55         this.unmodifiableParams = Collections.unmodifiableList(this.parameters);
56         return this;
57     }
58
59     @Override
60     protected MethodSignatureBuilder thisInstance() {
61         return this;
62     }
63
64     @Override
65     public MethodSignature toInstance(final Type definingType) {
66         final List<AnnotationType> annotations = toAnnotationTypes();
67         return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
68                 getReturnType(), this.unmodifiableParams, isFinal(), this.isAbstract, isStatic(), isDefault, mechanics);
69     }
70
71     @Override
72     public int hashCode() {
73         return Objects.hash(getName(), parameters, getReturnType());
74     }
75
76     @Override
77     public boolean equals(final Object obj) {
78         if (this == obj) {
79             return true;
80         }
81         if (obj == null || getClass() != obj.getClass()) {
82             return false;
83         }
84         final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
85         return Objects.equals(getName(), other.getName())
86                 && Objects.equals(this.parameters, other.parameters)
87                 && Objects.equals(getReturnType(), other.getReturnType());
88     }
89
90     @Override
91     public String toString() {
92         return new StringBuilder().append("MethodSignatureBuilderImpl [name=").append(getName())
93                 .append(", returnType=").append(getReturnType())
94                 .append(", parameters=").append(this.parameters)
95                 .append(", annotationBuilders=").append(getAnnotationBuilders())
96                 .append(", comment=").append(getComment())
97                 .append(']').toString();
98     }
99 }