Bug 6859: Cleanup package names for mdsal-binding-generator-util module
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / yangtools / binding / 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.yangtools.binding.generator.util.generated.type.builder;
9
10 import java.util.Collections;
11 import java.util.List;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
14 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
15 import org.opendaylight.yangtools.sal.binding.model.api.Type;
16 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
17 import org.opendaylight.yangtools.util.LazyCollections;
18
19 /**
20  * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.MethodSignatureBuilderImpl} instead.
21  */
22 @Deprecated
23 final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder<MethodSignatureBuilder> implements MethodSignatureBuilder {
24
25     private List<MethodSignature.Parameter> parameters = Collections.emptyList();
26     private List<MethodSignature.Parameter> unmodifiableParams  = Collections.emptyList();
27     private boolean isAbstract;
28
29     public MethodSignatureBuilderImpl(final String name) {
30         super(name);
31     }
32
33     @Override
34     public MethodSignatureBuilder setAbstract(final boolean isAbstract) {
35         this.isAbstract = isAbstract;
36         return this;
37     }
38
39     @Override
40     public MethodSignatureBuilder addParameter(final Type type, final String name) {
41         parameters = LazyCollections.lazyAdd(parameters, new MethodParameterImpl(name, type));
42         unmodifiableParams = Collections.unmodifiableList(parameters);
43         return this;
44     }
45
46     @Override
47     protected MethodSignatureBuilder thisInstance() {
48         return this;
49     }
50
51     @Override
52     public MethodSignature toInstance(final Type definingType) {
53         final List<AnnotationType> annotations = toAnnotationTypes();
54         return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(),
55                 getReturnType(), unmodifiableParams, isFinal(), isAbstract, isStatic());
56     }
57
58     @Override
59     public int hashCode() {
60         final int prime = 31;
61         int result = 1;
62         result = prime * result + Objects.hashCode(getName());
63         result = prime * result + Objects.hashCode(parameters);
64         result = prime * result + Objects.hashCode(getReturnType());
65         return result;
66     }
67
68     @Override
69     public boolean equals(final Object obj) {
70         if (this == obj) {
71             return true;
72         }
73         if (obj == null) {
74             return false;
75         }
76         if (getClass() != obj.getClass()) {
77             return false;
78         }
79         MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
80         if (!Objects.equals(getName(), other.getName())) {
81             return false;
82         }
83         if (!Objects.equals(parameters, other.parameters)) {
84             return false;
85         }
86         if (!Objects.equals(getReturnType(), other.getReturnType())) {
87             return false;
88         }
89         return true;
90     }
91
92     @Override
93     public String toString() {
94         StringBuilder builder = new StringBuilder();
95         builder.append("MethodSignatureBuilderImpl [name=");
96         builder.append(getName());
97         builder.append(", returnType=");
98         builder.append(getReturnType());
99         builder.append(", parameters=");
100         builder.append(parameters);
101         builder.append(", annotationBuilders=");
102         builder.append(getAnnotationBuilders());
103         builder.append(", comment=");
104         builder.append(getComment());
105         builder.append("]");
106         return builder.toString();
107     }
108 }