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