2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
15 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
17 final class AnnotationTypeBuilderImpl implements AnnotationTypeBuilder {
19 private final String packageName;
20 private final String name;
21 private final List<AnnotationTypeBuilder> annotationBuilders;
22 private final List<AnnotationType.Parameter> parameters;
24 public AnnotationTypeBuilderImpl(final String packageName, final String name) {
26 this.packageName = packageName;
28 annotationBuilders = new ArrayList<>();
29 parameters = new ArrayList<>();
33 public String getPackageName() {
38 public String getName() {
43 public String getFullyQualifiedName() {
44 return packageName + "." + name;
48 public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
49 if (packageName != null && name != null) {
50 final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
51 if (annotationBuilders.add(builder)) {
59 public boolean addParameter(String paramName, String value) {
60 if ((paramName != null) && (value != null)) {
61 return parameters.add(new ParameterImpl(paramName, value));
67 public boolean addParameters(String paramName, List<String> values) {
68 if ((paramName != null) && (values != null)) {
69 return parameters.add(new ParameterImpl(paramName, values));
75 public AnnotationType toInstance() {
76 return new AnnotationTypeImpl(packageName, name, annotationBuilders, parameters);
80 public int hashCode() {
83 result = prime * result + ((name == null) ? 0 : name.hashCode());
84 result = prime * result
85 + ((packageName == null) ? 0 : packageName.hashCode());
90 public boolean equals(Object obj) {
97 if (getClass() != obj.getClass()) {
100 AnnotationTypeBuilderImpl other = (AnnotationTypeBuilderImpl) obj;
102 if (other.name != null) {
105 } else if (!name.equals(other.name)) {
108 if (packageName == null) {
109 if (other.packageName != null) {
112 } else if (!packageName.equals(other.packageName)) {
119 public String toString() {
120 StringBuilder builder = new StringBuilder();
121 builder.append("AnnotationTypeBuilder [packageName=");
122 builder.append(packageName);
123 builder.append(", name=");
124 builder.append(name);
125 builder.append(", annotationBuilders=");
126 builder.append(annotationBuilders);
127 builder.append(", parameters=");
128 builder.append(parameters);
130 return builder.toString();
133 private static final class AnnotationTypeImpl implements AnnotationType {
135 private final String packageName;
136 private final String name;
137 private List<AnnotationType> annotations;
138 private final List<AnnotationType.Parameter> parameters;
139 private List<String> paramNames;
141 public AnnotationTypeImpl(String packageName, String name,
142 List<AnnotationTypeBuilder> annotationBuilders,
143 List<AnnotationType.Parameter> parameters) {
145 this.packageName = packageName;
148 this.annotations = new ArrayList<>();
149 for (final AnnotationTypeBuilder builder : annotationBuilders) {
150 annotations.add(builder.toInstance());
153 this.annotations = Collections.unmodifiableList(annotations);
154 this.parameters = Collections.unmodifiableList(parameters);
156 paramNames = new ArrayList<>();
157 for (final AnnotationType.Parameter parameter : parameters) {
158 paramNames.add(parameter.getName());
160 this.paramNames = Collections.unmodifiableList(paramNames);
164 public String getPackageName() {
169 public String getName() {
174 public String getFullyQualifiedName() {
175 return packageName + "." + name;
179 public List<AnnotationType> getAnnotations() {
184 public Parameter getParameter(final String paramName) {
185 if (paramName != null) {
186 for (final AnnotationType.Parameter parameter : parameters) {
187 if (parameter.getName().equals(paramName)) {
196 public List<Parameter> getParameters() {
201 public List<String> getParameterNames() {
206 public boolean containsParameters() {
207 return !parameters.isEmpty();
211 public int hashCode() {
212 final int prime = 31;
214 result = prime * result + ((name == null) ? 0 : name.hashCode());
215 result = prime * result
216 + ((packageName == null) ? 0 : packageName.hashCode());
221 public boolean equals(Object obj) {
228 if (getClass() != obj.getClass()) {
231 AnnotationTypeImpl other = (AnnotationTypeImpl) obj;
233 if (other.name != null) {
236 } else if (!name.equals(other.name)) {
239 if (packageName == null) {
240 if (other.packageName != null) {
243 } else if (!packageName.equals(other.packageName)) {
250 public String toString() {
251 StringBuilder builder = new StringBuilder();
252 builder.append("AnnotationType [packageName=");
253 builder.append(packageName);
254 builder.append(", name=");
255 builder.append(name);
256 builder.append(", annotations=");
257 builder.append(annotations);
258 builder.append(", parameters=");
259 builder.append(parameters);
261 return builder.toString();
265 private static final class ParameterImpl implements AnnotationType.Parameter {
267 private final String name;
268 private final String value;
269 private final List<String> values;
271 public ParameterImpl(String name, String value) {
275 this.values = Collections.emptyList();
278 public ParameterImpl(String name, List<String> values) {
281 this.values = values;
286 public String getName() {
291 public String getValue() {
296 public List<String> getValues() {
301 public int hashCode() {
302 final int prime = 31;
304 result = prime * result + ((name == null) ? 0 : name.hashCode());
309 public boolean equals(Object obj) {
316 if (getClass() != obj.getClass()) {
319 ParameterImpl other = (ParameterImpl) obj;
321 if (other.name != null) {
324 } else if (!name.equals(other.name)) {
331 public String toString() {
332 StringBuilder builder = new StringBuilder();
333 builder.append("ParameterImpl [name=");
334 builder.append(name);
335 builder.append(", value=");
336 builder.append(value);
337 builder.append(", values=");
338 builder.append(values);
340 return builder.toString();