Fix mergeable if-the-else statements
[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 || getClass() != obj.getClass()) {
78             return false;
79         }
80         final MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
81         return Objects.equals(getName(), other.getName())
82                 && Objects.equals(this.parameters, other.parameters)
83                 && Objects.equals(getReturnType(), other.getReturnType());
84     }
85
86     @Override
87     public String toString() {
88         return new StringBuilder().append("MethodSignatureBuilderImpl [name=").append(getName())
89                 .append(", returnType=").append(getReturnType())
90                 .append(", parameters=").append(this.parameters)
91                 .append(", annotationBuilders=").append(getAnnotationBuilders())
92                 .append(", comment=").append(getComment())
93                 .append(']').toString();
94     }
95 }