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