Merge "OF plugin classes must have a strict dependency on Connection Service"
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-util / src / main / java / org / opendaylight / controller / binding / generator / util / generated / type / builder / AbstractTypeMemberBuilder.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 org.opendaylight.controller.sal.binding.model.api.AccessModifier;
11 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
12 import org.opendaylight.controller.sal.binding.model.api.Type;
13 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
14 import org.opendaylight.controller.sal.binding.model.api.type.builder.TypeMemberBuilder;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 abstract class AbstractTypeMemberBuilder implements TypeMemberBuilder {
20     private final String name;
21     private Type returnType;
22     private final List<AnnotationTypeBuilder> annotationBuilders;
23     private String comment = "";
24     private boolean isFinal;
25     private AccessModifier accessModifier;
26
27     public AbstractTypeMemberBuilder(final String name) {
28         this.name = name;
29         this.annotationBuilders = new ArrayList<>();
30     }
31
32     @Override
33     public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
34         if (packageName == null) {
35             throw new IllegalArgumentException("Annotation Type cannot have package name null!");
36         }
37         if (name == null) {
38             throw new IllegalArgumentException("Annotation Type cannot have name as null!");
39         }
40         final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
41                     packageName, name);
42         annotationBuilders.add(builder);
43         return builder;
44     }
45
46     protected Type getReturnType() {
47         return returnType;
48     }
49
50     protected List<AnnotationTypeBuilder> getAnnotationBuilders() {
51         return annotationBuilders;
52     }
53
54     protected String getComment() {
55         return comment;
56     }
57
58     protected boolean isFinal() {
59         return isFinal;
60     }
61
62     protected AccessModifier getAccessModifier() {
63         return accessModifier;
64     }
65
66     @Override
67     public String getName() {
68         return name;
69     }
70
71     @Override
72     public void setReturnType(Type returnType) {
73         if (returnType == null) {
74             throw new IllegalArgumentException("Return Type of member cannot be null!");
75         }
76         this.returnType = returnType;
77     }
78
79     @Override
80     public void setAccessModifier(AccessModifier modifier) {
81         if (modifier == null) {
82             throw new IllegalArgumentException("Access Modifier for member type cannot be null!");
83         }
84         this.accessModifier = modifier;
85     }
86
87     @Override
88     public void setComment(String comment) {
89         if (comment == null) {
90             this.comment = "";
91         }
92         this.comment = comment;
93     }
94
95     @Override
96     public void setFinal(boolean isFinal) {
97         this.isFinal = isFinal;
98     }
99
100     protected List<AnnotationType> toAnnotationTypes() {
101         final List<AnnotationType> annotations = new ArrayList<>();
102         for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) {
103             if (annotBuilder != null) {
104                 annotations.add(annotBuilder.toInstance());
105             }
106         }
107         return annotations;
108     }
109
110     @Override
111     public int hashCode() {
112         final int prime = 31;
113         int result = 1;
114         result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
115         result = prime * result
116                 + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
117         return result;
118     }
119
120     @Override
121     public boolean equals(Object obj) {
122         if (this == obj) {
123             return true;
124         }
125         if (obj == null) {
126             return false;
127         }
128         if (getClass() != obj.getClass()) {
129             return false;
130         }
131         MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
132         if (getName() == null) {
133             if (other.getName() != null) {
134                 return false;
135             }
136         } else if (!getName().equals(other.getName())) {
137             return false;
138         }
139         if (getReturnType() == null) {
140             if (other.getReturnType() != null) {
141                 return false;
142             }
143         } else if (!getReturnType().equals(other.getReturnType())) {
144             return false;
145         }
146         return true;
147     }
148
149     @Override
150     public String toString() {
151         StringBuilder builder = new StringBuilder();
152         builder.append("GeneratedPropertyImpl [name=");
153         builder.append(getName());
154         builder.append(", annotations=");
155         builder.append(getAnnotationBuilders());
156         builder.append(", comment=");
157         builder.append(getComment());
158         builder.append(", returnType=");
159         builder.append(getReturnType());
160         builder.append(", isFinal=");
161         builder.append(isFinal());
162         builder.append(", modifier=");
163         builder.append(getAccessModifier());
164         builder.append("]");
165         return builder.toString();
166     }
167 }