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