-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
-
-import org.opendaylight.yangtools.sal.binding.model.api.*;
-import org.opendaylight.yangtools.sal.binding.model.api.type.builder.*;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTOBuilder {
-
- private GeneratedTransferObject extendsType;
- private final List<GeneratedPropertyBuilder> properties = new ArrayList<>();
- private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<>();
- private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<>();
- private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<>();
- private boolean isUnionType = false;
-
- public GeneratedTOBuilderImpl(String packageName, String name) {
- super(packageName, name);
- setAbstract(false);
- }
-
- @Override
- public void setExtendsType(final GeneratedTransferObject genTransObj) {
- if (genTransObj == null) {
- throw new IllegalArgumentException("Generated Transfer Object cannot be null!");
- }
- extendsType = genTransObj;
- }
-
- @Override
- public GeneratedPropertyBuilder addProperty(String name) {
- final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name);
- builder.setAccessModifier(AccessModifier.PUBLIC);
- properties.add(builder);
- return builder;
- }
-
- @Override
- public boolean containsProperty(String name) {
- if (name == null) {
- throw new IllegalArgumentException("Parameter name can't be null");
- }
- for (GeneratedPropertyBuilder property : properties) {
- if (name.equals(property.getName())) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Add new Method Signature definition for Generated Type Builder and
- * returns Method Signature Builder for specifying all Method parameters. <br>
- * Name of Method cannot be <code>null</code>, if it is <code>null</code>
- * the method SHOULD throw {@link IllegalArgumentException} <br>
- * By <i>Default</i> the MethodSignatureBuilder SHOULD be pre-set as
- * {@link MethodSignatureBuilder#setAbstract(false)},
- * {@link MethodSignatureBuilder#setFinal(false)} and
- * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)}
- *
- * @param name
- * Name of Method
- * @return <code>new</code> instance of Method Signature Builder.
- */
- @Override
- public MethodSignatureBuilder addMethod(String name) {
- final MethodSignatureBuilder builder = super.addMethod(name);
- builder.setAbstract(false);
- return builder;
- }
-
- @Override
- public boolean addEqualsIdentity(GeneratedPropertyBuilder property) {
- return equalsProperties.add(property);
- }
-
- @Override
- public boolean addHashIdentity(GeneratedPropertyBuilder property) {
- return hashProperties.add(property);
- }
-
- @Override
- public boolean addToStringProperty(GeneratedPropertyBuilder property) {
- return toStringProperties.add(property);
- }
-
- @Override
- public GeneratedTransferObject toInstance() {
- return new GeneratedTransferObjectImpl(null, getPackageName(), getName(), getComment(), getAnnotations(),
- isAbstract(), extendsType, getImplementsTypes(), getEnclosedTypes(), getEnclosedTransferObjects(),
- getConstants(), getEnumerations(), getMethodDefinitions(), properties, equalsProperties,
- hashProperties, toStringProperties, isUnionType);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("GeneratedTransferObject [packageName=");
- builder.append(getPackageName());
- builder.append(", name=");
- builder.append(getName());
- builder.append(", comment=");
- builder.append(getComment());
- builder.append(", constants=");
- builder.append(getConstants());
- builder.append(", enumerations=");
- builder.append(getEnumerations());
- builder.append(", properties=");
- builder.append(properties);
- builder.append(", equalsProperties=");
- builder.append(equalsProperties);
- builder.append(", hashCodeProperties=");
- builder.append(hashProperties);
- builder.append(", stringProperties=");
- builder.append(toStringProperties);
- builder.append(", annotations=");
- builder.append(getAnnotations());
- builder.append(", methods=");
- builder.append(getMethodDefinitions());
- builder.append("]");
- return builder.toString();
- }
-
- @Override
- public void setIsUnion(boolean isUnion) {
- this.isUnionType = isUnion;
- }
-
- private static final class GeneratedTransferObjectImpl extends AbstractGeneratedType implements
- GeneratedTransferObject {
-
- private final List<GeneratedProperty> properties;
- private final List<GeneratedProperty> equalsProperties;
- private final List<GeneratedProperty> hashCodeProperties;
- private final List<GeneratedProperty> stringProperties;
- private final GeneratedTransferObject extendsType;
- private final boolean isUnionType;
-
- GeneratedTransferObjectImpl(final Type parent, final String packageName, final String name,
- final String comment, final List<AnnotationTypeBuilder> annotationBuilders, final boolean isAbstract,
- final GeneratedTransferObject extendsType, final List<Type> implementsTypes,
- final List<GeneratedTypeBuilder> enclosedGenTypeBuilders,
- final List<GeneratedTOBuilder> enclosedGenTOBuilders, final List<Constant> constants,
- final List<EnumBuilder> enumBuilders, final List<MethodSignatureBuilder> methodBuilders,
- final List<GeneratedPropertyBuilder> propBuilders, final List<GeneratedPropertyBuilder> equalsBuilders,
- final List<GeneratedPropertyBuilder> hashCodeBuilders,
- final List<GeneratedPropertyBuilder> stringBuilders, final boolean isUnionType) {
- super(parent, packageName, name, comment, annotationBuilders, isAbstract, implementsTypes,
- enclosedGenTypeBuilders, enclosedGenTOBuilders, enumBuilders, constants, methodBuilders);
- this.extendsType = extendsType;
- this.properties = toUnmodifiableProperties(propBuilders);
- this.equalsProperties = toUnmodifiableProperties(equalsBuilders);
- this.hashCodeProperties = toUnmodifiableProperties(hashCodeBuilders);
- this.stringProperties = toUnmodifiableProperties(stringBuilders);
- this.isUnionType = isUnionType;
- }
-
- @Override
- public boolean isUnionType() {
- return isUnionType;
- }
-
- private List<GeneratedProperty> toUnmodifiableProperties(final List<GeneratedPropertyBuilder> propBuilders) {
- final List<GeneratedProperty> properties = new ArrayList<>();
- for (final GeneratedPropertyBuilder builder : propBuilders) {
- properties.add(builder.toInstance(this));
- }
- return Collections.unmodifiableList(properties);
- }
-
- @Override
- public GeneratedTransferObject getExtends() {
- return extendsType;
- }
-
- @Override
- public List<GeneratedProperty> getProperties() {
- return properties;
- }
-
- @Override
- public List<GeneratedProperty> getEqualsIdentifiers() {
- return equalsProperties;
- }
-
- @Override
- public List<GeneratedProperty> getHashCodeIdentifiers() {
- return hashCodeProperties;
- }
-
- @Override
- public List<GeneratedProperty> getToStringIdentifiers() {
- return stringProperties;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("GeneratedTransferObject [packageName=");
- builder.append(getPackageName());
- builder.append(", name=");
- builder.append(getName());
- builder.append(", comment=");
- builder.append(", annotations=");
- builder.append(getAnnotations());
- builder.append(getComment());
- builder.append(", extends=");
- builder.append(getExtends());
- builder.append(", implements=");
- builder.append(getImplements());
- builder.append(", enclosedTypes=");
- builder.append(getEnclosedTypes());
- builder.append(", constants=");
- builder.append(getConstantDefinitions());
- builder.append(", enumerations=");
- builder.append(getEnumerations());
- builder.append(", properties=");
- builder.append(properties);
- builder.append(", equalsProperties=");
- builder.append(equalsProperties);
- builder.append(", hashCodeProperties=");
- builder.append(hashCodeProperties);
- builder.append(", stringProperties=");
- builder.append(stringProperties);
- builder.append(", methods=");
- builder.append(getMethodDefinitions());
- builder.append("]");
- return builder.toString();
- }
- }
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;\r
+\r
+import org.opendaylight.yangtools.sal.binding.model.api.*;\r
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.*;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTOBuilder {\r
+\r
+ private GeneratedTransferObject extendsType;\r
+ private final List<GeneratedPropertyBuilder> properties = new ArrayList<>();\r
+ private final List<GeneratedPropertyBuilder> equalsProperties = new ArrayList<>();\r
+ private final List<GeneratedPropertyBuilder> hashProperties = new ArrayList<>();\r
+ private final List<GeneratedPropertyBuilder> toStringProperties = new ArrayList<>();\r
+ private boolean isUnionType = false;\r
+\r
+ public GeneratedTOBuilderImpl(String packageName, String name) {\r
+ super(packageName, name);\r
+ setAbstract(false);\r
+ }\r
+\r
+ @Override\r
+ public void setExtendsType(final GeneratedTransferObject genTransObj) {\r
+ if (genTransObj == null) {\r
+ throw new IllegalArgumentException("Generated Transfer Object cannot be null!");\r
+ }\r
+ extendsType = genTransObj;\r
+ }\r
+\r
+\r
+\r
+ /**\r
+ * Add new Method Signature definition for Generated Type Builder and\r
+ * returns Method Signature Builder for specifying all Method parameters. <br>\r
+ * Name of Method cannot be <code>null</code>, if it is <code>null</code>\r
+ * the method SHOULD throw {@link IllegalArgumentException} <br>\r
+ * By <i>Default</i> the MethodSignatureBuilder SHOULD be pre-set as\r
+ * {@link MethodSignatureBuilder#setAbstract(false)},\r
+ * {@link MethodSignatureBuilder#setFinal(false)} and\r
+ * {@link MethodSignatureBuilder#setAccessModifier(PUBLIC)}\r
+ * \r
+ * @param name\r
+ * Name of Method\r
+ * @return <code>new</code> instance of Method Signature Builder.\r
+ */\r
+ @Override\r
+ public MethodSignatureBuilder addMethod(String name) {\r
+ final MethodSignatureBuilder builder = super.addMethod(name);\r
+ builder.setAbstract(false);\r
+ return builder;\r
+ }\r
+\r
+ @Override\r
+ public boolean addEqualsIdentity(GeneratedPropertyBuilder property) {\r
+ return equalsProperties.add(property);\r
+ }\r
+\r
+ @Override\r
+ public boolean addHashIdentity(GeneratedPropertyBuilder property) {\r
+ return hashProperties.add(property);\r
+ }\r
+\r
+ @Override\r
+ public boolean addToStringProperty(GeneratedPropertyBuilder property) {\r
+ return toStringProperties.add(property);\r
+ }\r
+\r
+ @Override\r
+ public GeneratedTransferObject toInstance() {\r
+ return new GeneratedTransferObjectImpl(this);\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append("GeneratedTransferObject [packageName=");\r
+ builder.append(getPackageName());\r
+ builder.append(", name=");\r
+ builder.append(getName());\r
+ builder.append(", comment=");\r
+ builder.append(getComment());\r
+ builder.append(", constants=");\r
+ builder.append(getConstants());\r
+ builder.append(", enumerations=");\r
+ builder.append(getEnumerations());\r
+ builder.append(", properties=");\r
+ builder.append(properties);\r
+ builder.append(", equalsProperties=");\r
+ builder.append(equalsProperties);\r
+ builder.append(", hashCodeProperties=");\r
+ builder.append(hashProperties);\r
+ builder.append(", stringProperties=");\r
+ builder.append(toStringProperties);\r
+ builder.append(", annotations=");\r
+ builder.append(getAnnotations());\r
+ builder.append(", methods=");\r
+ builder.append(getMethodDefinitions());\r
+ builder.append("]");\r
+ return builder.toString();\r
+ }\r
+\r
+ @Override\r
+ public void setIsUnion(boolean isUnion) {\r
+ this.isUnionType = isUnion;\r
+ }\r
+\r
+ private static final class GeneratedTransferObjectImpl extends AbstractGeneratedType implements\r
+ GeneratedTransferObject {\r
+\r
+ private final List<GeneratedProperty> equalsProperties;\r
+ private final List<GeneratedProperty> hashCodeProperties;\r
+ private final List<GeneratedProperty> stringProperties;\r
+ private final GeneratedTransferObject extendsType;\r
+ private final boolean isUnionType;\r
+\r
+ public GeneratedTransferObjectImpl(GeneratedTOBuilderImpl builder) {\r
+ super(builder);\r
+ this.extendsType = builder.extendsType;\r
+ this.equalsProperties = toUnmodifiableProperties(builder.equalsProperties);\r
+ this.hashCodeProperties = toUnmodifiableProperties(builder.hashProperties);\r
+ this.stringProperties = toUnmodifiableProperties(builder.toStringProperties);\r
+ this.isUnionType = builder.isUnionType;\r
+ }\r
+\r
+ @Override\r
+ public boolean isUnionType() {\r
+ return isUnionType;\r
+ }\r
+ @Override\r
+ public GeneratedTransferObject getSuperType() {\r
+ return extendsType;\r
+ }\r
+\r
+ @Override\r
+ public List<GeneratedProperty> getEqualsIdentifiers() {\r
+ return equalsProperties;\r
+ }\r
+\r
+ @Override\r
+ public List<GeneratedProperty> getHashCodeIdentifiers() {\r
+ return hashCodeProperties;\r
+ }\r
+\r
+ @Override\r
+ public List<GeneratedProperty> getToStringIdentifiers() {\r
+ return stringProperties;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ StringBuilder builder = new StringBuilder();\r
+ builder.append("GeneratedTransferObject [packageName=");\r
+ builder.append(getPackageName());\r
+ builder.append(", name=");\r
+ builder.append(getName());\r
+ builder.append(", comment=");\r
+ builder.append(", annotations=");\r
+ builder.append(getAnnotations());\r
+ builder.append(getComment());\r
+ builder.append(", extends=");\r
+ builder.append(getSuperType());\r
+ builder.append(", implements=");\r
+ builder.append(getImplements());\r
+ builder.append(", enclosedTypes=");\r
+ builder.append(getEnclosedTypes());\r
+ builder.append(", constants=");\r
+ builder.append(getConstantDefinitions());\r
+ builder.append(", enumerations=");\r
+ builder.append(getEnumerations());\r
+ builder.append(", properties=");\r
+ builder.append(getProperties());\r
+ builder.append(", equalsProperties=");\r
+ builder.append(equalsProperties);\r
+ builder.append(", hashCodeProperties=");\r
+ builder.append(hashCodeProperties);\r
+ builder.append(", stringProperties=");\r
+ builder.append(stringProperties);\r
+ builder.append(", methods=");\r
+ builder.append(getMethodDefinitions());\r
+ builder.append("]");\r
+ return builder.toString();\r
+ }\r
+ }\r
+}\r