Use String concatenation instead of StringBuffer/Builder
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / ExtendedType.java
index c5add934bee984990ec6d7e8eb2b213922c278b1..7982e157db6bc62ba9c50d1afd2e3fdc470bb7ea 100644 (file)
@@ -7,11 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.model.util;
 
-import java.net.URI;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import java.util.Collections;
-import java.util.Date;
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
@@ -21,8 +20,6 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 /**
  * Extended Type represents YANG type derived from other type.
  *
@@ -31,7 +28,9 @@ import com.google.common.base.Preconditions;
  * may define additional constraints, modify description or reference
  * of parent type or provide new type capture for specific use-cases.
  *
+ * @deprecated Use of this class is deprecated, use {@link DerivedType} instead.
  */
+@Deprecated
 public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
 
     private final QName typeName;
@@ -41,27 +40,28 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     private final String reference;
     private final List<UnknownSchemaNode> unknownSchemaNodes;
 
-    private List<RangeConstraint> ranges = Collections.emptyList();
-    private List<LengthConstraint> lengths = Collections.emptyList();
-    private List<PatternConstraint> patterns = Collections.emptyList();
-    private Integer fractionDigits = null;
-
     private final Status status;
     private final String units;
     private final Object defaultValue;
     private final boolean addedByUses;
 
+    private List<RangeConstraint> ranges = Collections.emptyList();
+    private List<LengthConstraint> lengths = Collections.emptyList();
+    private List<PatternConstraint> patterns = Collections.emptyList();
+    private Integer fractionDigits = null;
+
     /**
-    *
-    * Creates Builder for extended / derived type.
-    *
-    * @param typeName QName of derived type
-    * @param baseType Base type of derived type
-    * @param description Description of type
-    * @param reference Reference of Type
-    * @param path Schema path to type definition.
-    */
-    public static final Builder builder(final QName typeName,final TypeDefinition<?> baseType,final Optional<String> description,final Optional<String> reference,final SchemaPath path) {
+     *
+     * Creates Builder for extended / derived type.
+     *
+     * @param typeName QName of derived type
+     * @param baseType Base type of derived type
+     * @param description Description of type
+     * @param reference Reference of Type
+     * @param path Schema path to type definition.
+     */
+    public static Builder builder(final QName typeName, final TypeDefinition<?> baseType,
+            final Optional<String> description, final Optional<String> reference, final SchemaPath path) {
         return new Builder(typeName, baseType, description.or(""), reference.or(""), path);
     }
 
@@ -86,27 +86,6 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private Integer fractionDigits = null;
 
         /**
-         *
-         * @param actualPath
-         * @param namespace
-         * @param revision
-         * @param typeName
-         * @param baseType
-         * @param description
-         * @param reference
-         *
-         * @deprecated Use {@link ExtendedType#builder(QName, TypeDefinition, Optional, Optional, SchemaPath) instead.
-         */
-        @Deprecated
-        public Builder(final List<String> actualPath, final URI namespace,
-                final Date revision, final QName typeName,
-                final TypeDefinition<?> baseType, final String description,
-                final String reference) {
-            this(typeName,baseType,description,reference,BaseTypes.schemaPath(actualPath, namespace, revision));
-        }
-
-        /**
-         *
          * Creates Builder for extended / derived type.
          *
          * @param typeName QName of derived type
@@ -114,11 +93,8 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
          * @param description Description of type
          * @param reference Reference of Type
          * @param path Schema path to type definition.
-         *
-         * @deprecated Use {@link ExtendedType#builder(QName, TypeDefinition, Optional, Optional, SchemaPath) instead.
          */
-        @Deprecated
-        public Builder(final QName typeName, final TypeDefinition<?> baseType,
+        protected Builder(final QName typeName, final TypeDefinition<?> baseType,
                 final String description, final String reference,
                 final SchemaPath path) {
             this.typeName = Preconditions.checkNotNull(typeName, "type name must not be null.");
@@ -150,7 +126,11 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
 
         public Builder unknownSchemaNodes(
                 final List<UnknownSchemaNode> unknownSchemaNodes) {
-            this.unknownSchemaNodes = unknownSchemaNodes;
+            if (unknownSchemaNodes.isEmpty()) {
+                this.unknownSchemaNodes = Collections.emptyList();
+            } else {
+                this.unknownSchemaNodes = unknownSchemaNodes;
+            }
             return this;
         }
 
@@ -265,8 +245,9 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         if (path != null ? !path.equals(that.path) : that.path != null) {
             return false;
         }
-        if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null)
+        if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null) {
             return false;
+        }
 
         return true;
     }
@@ -280,27 +261,25 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
 
     @Override
     public String toString() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("ExtendedType [typeName=");
-        builder.append(typeName);
-        builder.append(", baseType=");
-        builder.append(baseType);
-        builder.append(", path=");
-        builder.append(path);
-        builder.append(", description=");
-        builder.append(description);
-        builder.append(", reference=");
-        builder.append(reference);
-        builder.append(", unknownSchemaNodes=");
-        builder.append(unknownSchemaNodes);
-        builder.append(", status=");
-        builder.append(status);
-        builder.append(", units=");
-        builder.append(units);
-        builder.append(", defaultValue=");
-        builder.append(defaultValue);
-        builder.append("]");
-        return builder.toString();
+        return "ExtendedType [typeName=" +
+                typeName +
+                ", baseType=" +
+                baseType +
+                ", path=" +
+                path +
+                ", description=" +
+                description +
+                ", reference=" +
+                reference +
+                ", unknownSchemaNodes=" +
+                unknownSchemaNodes +
+                ", status=" +
+                status +
+                ", units=" +
+                units +
+                ", defaultValue=" +
+                defaultValue +
+                "]";
     }
 
     public List<RangeConstraint> getRangeConstraints() {