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.sal.binding.generator.impl;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
15 import org.opendaylight.controller.sal.binding.model.api.Constant;
16 import org.opendaylight.controller.sal.binding.model.api.Enumeration;
17 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
18 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
20 import org.opendaylight.controller.sal.binding.model.api.Type;
21 import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
22 import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
23 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
24 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
26 final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
27 private String packageName;
28 private final String name;
30 private final List<EnumBuilder> enumerations = new ArrayList<EnumBuilder>();
31 private final List<GeneratedPropertyBuilder> properties = new ArrayList<GeneratedPropertyBuilder>();
32 private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<GeneratedPropertyBuilder>();
33 private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<GeneratedPropertyBuilder>();
34 private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<GeneratedPropertyBuilder>();
36 public GeneratedTOBuilderImpl(String packageName, String name) {
38 this.packageName = packageName;
43 public String getPackageName() {
48 public String getName() {
53 public EnumBuilder addEnumeration(String name) {
54 final EnumBuilder builder = new EnumerationBuilderImpl(packageName,
56 enumerations.add(builder);
61 public GeneratedPropertyBuilder addProperty(String name) {
62 final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(
64 properties.add(builder);
69 public boolean addEqualsIdentity(GeneratedPropertyBuilder property) {
70 return equalsProperties.add(property);
74 public boolean addHashIdentity(GeneratedPropertyBuilder property) {
75 return hashProperties.add(property);
79 public boolean addToStringProperty(GeneratedPropertyBuilder property) {
80 return toStringProperties.add(property);
84 public GeneratedTransferObject toInstance() {
85 return new GeneratedTransferObjectImpl(packageName, name, enumerations,
86 properties, equalsProperties, hashProperties,
90 private static final class GeneratedPropertyBuilderImpl implements
91 GeneratedPropertyBuilder {
93 private final String name;
94 private Type returnType;
95 private final List<MethodSignature.Parameter> parameters;
96 private String comment = "";
97 private AccessModifier accessModifier;
98 private boolean isFinal;
99 private boolean isReadOnly;
101 public GeneratedPropertyBuilderImpl(final String name) {
104 parameters = new ArrayList<MethodSignature.Parameter>();
106 this.isReadOnly = true;
107 accessModifier = AccessModifier.PUBLIC;
110 public String getName() {
115 public boolean addReturnType(Type returnType) {
116 if (returnType != null) {
117 this.returnType = returnType;
118 this.parameters.add(new MethodParameterImpl(name, returnType));
125 public void accessorModifier(final AccessModifier modifier) {
126 accessModifier = modifier;
130 public void addComment(String comment) {
131 if (comment != null) {
132 this.comment = comment;
137 public void setFinal(boolean isFinal) {
138 this.isFinal = isFinal;
142 public void setReadOnly(boolean isReadOnly) {
143 this.isReadOnly = isReadOnly;
147 public GeneratedProperty toInstance(final Type definingType) {
148 return new GeneratedPropertyImpl(name, comment, definingType,
149 returnType, isFinal, isReadOnly, parameters, accessModifier);
153 private static final class GeneratedPropertyImpl implements
156 private final String name;
157 private final String comment;
158 private final Type parent;
159 private final Type returnType;
160 private final boolean isFinal;
161 private final boolean isReadOnly;
162 private final List<MethodSignature.Parameter> parameters;
163 private final AccessModifier modifier;
165 public GeneratedPropertyImpl(final String name, final String comment,
166 final Type parent, final Type returnType,
167 final boolean isFinal, final boolean isReadOnly,
168 final List<Parameter> parameters, final AccessModifier modifier) {
171 this.comment = comment;
172 this.parent = parent;
173 this.returnType = returnType;
174 this.isFinal = isFinal;
175 this.isReadOnly = isReadOnly;
176 this.parameters = Collections.unmodifiableList(parameters);
177 this.modifier = modifier;
181 public String getName() {
186 public String getComment() {
191 public Type getDefiningType() {
196 public Type getReturnType() {
201 public List<Parameter> getParameters() {
206 public AccessModifier getAccessModifier() {
211 public boolean isReadOnly() {
216 public boolean isFinal() {
221 public int hashCode() {
222 final int prime = 31;
224 result = prime * result
225 + ((comment == null) ? 0 : comment.hashCode());
226 result = prime * result + (isFinal ? 1231 : 1237);
227 result = prime * result + (isReadOnly ? 1231 : 1237);
228 result = prime * result
229 + ((modifier == null) ? 0 : modifier.hashCode());
230 result = prime * result + ((name == null) ? 0 : name.hashCode());
231 result = prime * result
232 + ((parameters == null) ? 0 : parameters.hashCode());
234 if (parent != null) {
237 + ((parent.getPackageName() == null) ? 0 : parent
238 .getPackageName().hashCode());
241 + ((parent.getName() == null) ? 0 : parent.getName()
245 result = prime * result
246 + ((returnType == null) ? 0 : returnType.hashCode());
251 public boolean equals(Object obj) {
258 if (getClass() != obj.getClass()) {
261 GeneratedPropertyImpl other = (GeneratedPropertyImpl) obj;
262 if (comment == null) {
263 if (other.comment != null) {
266 } else if (!comment.equals(other.comment)) {
269 if (isFinal != other.isFinal) {
272 if (isReadOnly != other.isReadOnly) {
275 if (modifier != other.modifier) {
279 if (other.name != null) {
282 } else if (!name.equals(other.name)) {
285 if (parameters == null) {
286 if (other.parameters != null) {
289 } else if (!parameters.equals(other.parameters)) {
292 if (parent == null) {
293 if (other.parent != null) {
296 } else if ((parent != null) && (other.parent != null)) {
297 if (!parent.getPackageName().equals(
298 other.parent.getPackageName())
299 && !parent.getName().equals(other.parent.getName())) {
303 if (returnType == null) {
304 if (other.returnType != null) {
307 } else if (!returnType.equals(other.returnType)) {
314 public String toString() {
315 StringBuilder builder = new StringBuilder();
316 builder.append("GeneratedPropertyImpl [name=");
317 builder.append(name);
318 builder.append(", comment=");
319 builder.append(comment);
320 if (parent != null) {
321 builder.append(", parent=");
322 builder.append(parent.getPackageName());
324 builder.append(parent.getName());
326 builder.append(", parent= null");
328 builder.append(", returnType=");
329 builder.append(returnType);
330 builder.append(", isFinal=");
331 builder.append(isFinal);
332 builder.append(", isReadOnly=");
333 builder.append(isReadOnly);
334 builder.append(", parameters=");
335 builder.append(parameters);
336 builder.append(", modifier=");
337 builder.append(modifier);
339 return builder.toString();
343 private static final class GeneratedTransferObjectImpl implements
344 GeneratedTransferObject {
346 private final String packageName;
347 private final String name;
348 // private final List<Constant> constants;
349 private final List<Enumeration> enumerations;
350 private final List<GeneratedProperty> properties;
351 private final List<GeneratedProperty> equalsProperties;
352 private final List<GeneratedProperty> hashCodeProperties;
353 private final List<GeneratedProperty> stringProperties;
355 private List<Enumeration> toUnmodifiableEnumerations(
356 final List<EnumBuilder> enumBuilders) {
357 final List<Enumeration> enumerations = new ArrayList<Enumeration>();
358 for (final EnumBuilder builder : enumBuilders) {
359 enumerations.add(builder.toInstance(this));
361 return Collections.unmodifiableList(enumerations);
364 private List<Constant> toUnmodifiableConstant(
365 final List<ConstantBuilder> constBuilders) {
366 final List<Constant> constants = new ArrayList<Constant>();
367 for (final ConstantBuilder builder : constBuilders) {
368 constants.add(builder.toInstance(this));
370 return Collections.unmodifiableList(constants);
373 private List<GeneratedProperty> toUnmodifiableProperties(
374 final List<GeneratedPropertyBuilder> propBuilders) {
375 final List<GeneratedProperty> constants = new ArrayList<GeneratedProperty>();
376 for (final GeneratedPropertyBuilder builder : propBuilders) {
377 constants.add(builder.toInstance(this));
379 return Collections.unmodifiableList(constants);
382 public GeneratedTransferObjectImpl(String packageName, String name,
383 List<EnumBuilder> enumBuilders,
384 List<GeneratedPropertyBuilder> propBuilers,
385 List<GeneratedPropertyBuilder> equalsBuilers,
386 List<GeneratedPropertyBuilder> hashCodeBuilers,
387 List<GeneratedPropertyBuilder> stringBuilers) {
389 this.packageName = packageName;
391 this.enumerations = toUnmodifiableEnumerations(enumBuilders);
392 this.properties = toUnmodifiableProperties(propBuilers);
393 this.equalsProperties = toUnmodifiableProperties(equalsBuilers);
394 this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilers);
395 this.stringProperties = toUnmodifiableProperties(stringBuilers);
399 public String getPackageName() {
404 public String getName() {
409 public List<Enumeration> getEnumDefintions() {
414 public List<GeneratedProperty> getProperties() {
419 public List<GeneratedProperty> getEqualsIdentifiers() {
420 return equalsProperties;
424 public List<GeneratedProperty> getHashCodeIdentifiers() {
425 return hashCodeProperties;
429 public List<GeneratedProperty> getToStringIdentifiers() {
430 return stringProperties;
436 * @see java.lang.Object#hashCode()
439 public int hashCode() {
440 final int prime = 31;
442 result = prime * result
443 + ((enumerations == null) ? 0 : enumerations.hashCode());
446 + ((equalsProperties == null) ? 0 : equalsProperties
450 + ((hashCodeProperties == null) ? 0 : hashCodeProperties
452 result = prime * result + ((name == null) ? 0 : name.hashCode());
453 result = prime * result
454 + ((packageName == null) ? 0 : packageName.hashCode());
455 result = prime * result
456 + ((properties == null) ? 0 : properties.hashCode());
459 + ((stringProperties == null) ? 0 : stringProperties
467 * @see java.lang.Object#equals(java.lang.Object)
470 public boolean equals(Object obj) {
477 if (getClass() != obj.getClass()) {
480 GeneratedTransferObjectImpl other = (GeneratedTransferObjectImpl) obj;
481 if (enumerations == null) {
482 if (other.enumerations != null) {
485 } else if (!enumerations.equals(other.enumerations)) {
488 if (equalsProperties == null) {
489 if (other.equalsProperties != null) {
492 } else if (!equalsProperties.equals(other.equalsProperties)) {
495 if (hashCodeProperties == null) {
496 if (other.hashCodeProperties != null) {
499 } else if (!hashCodeProperties.equals(other.hashCodeProperties)) {
503 if (other.name != null) {
506 } else if (!name.equals(other.name)) {
509 if (packageName == null) {
510 if (other.packageName != null) {
513 } else if (!packageName.equals(other.packageName)) {
516 if (properties == null) {
517 if (other.properties != null) {
520 } else if (!properties.equals(other.properties)) {
523 if (stringProperties == null) {
524 if (other.stringProperties != null) {
527 } else if (!stringProperties.equals(other.stringProperties)) {
536 * @see java.lang.Object#toString()
539 public String toString() {
540 StringBuilder builder = new StringBuilder();
541 builder.append("GeneratedTransferObjectImpl [packageName=");
542 builder.append(packageName);
543 builder.append(", name=");
544 builder.append(name);
545 builder.append(", enumerations=");
546 builder.append(enumerations);
547 builder.append(", properties=");
548 builder.append(properties);
549 builder.append(", equalsProperties=");
550 builder.append(equalsProperties);
551 builder.append(", hashCodeProperties=");
552 builder.append(hashCodeProperties);
553 builder.append(", stringProperties=");
554 builder.append(stringProperties);
556 return builder.toString();