Merge "Fixed bug in maven-yang-plugin."
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / ExtendedType.java
index 2057a42eb6490bf659d11149ff85bb138326634b..6070c1c6ac563cc230dd7c9ddac921cfb9344911 100644 (file)
@@ -1,13 +1,15 @@
 /*
 * 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
 */
+ * 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.controller.yang.model.util;
 
+import java.net.URI;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.opendaylight.controller.yang.common.QName;
@@ -33,10 +35,10 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     private List<PatternConstraint> patterns = Collections.emptyList();
     private Integer fractionDigits = null;
 
-
     private Status status;
     private String units;
     private Object defaultValue;
+    private boolean addedByUses;
 
     public static class Builder {
         private final QName typeName;
@@ -46,21 +48,35 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private final String description;
         private final String reference;
 
-        private List<UnknownSchemaNode> unknownSchemaNodes = Collections.emptyList();;
+        private List<UnknownSchemaNode> unknownSchemaNodes = Collections
+                .emptyList();
         private Status status = Status.CURRENT;
-        private String units = "";
+        private String units = null;
         private Object defaultValue = null;
+        private boolean addedByUses;
 
         private List<RangeConstraint> ranges = Collections.emptyList();
         private List<LengthConstraint> lengths = Collections.emptyList();
         private List<PatternConstraint> patterns = Collections.emptyList();
         private Integer fractionDigits = null;
 
+        public Builder(final List<String> actualPath, final URI namespace,
+                final Date revision, final QName typeName,
+                TypeDefinition<?> baseType, final String description,
+                final String reference) {
+            this.typeName = typeName;
+            this.baseType = baseType;
+            this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
+            this.description = description;
+            this.reference = reference;
+        }
+
         public Builder(final QName typeName, TypeDefinition<?> baseType,
-                final String description, final String reference) {
+                final String description, final String reference,
+                SchemaPath path) {
             this.typeName = typeName;
             this.baseType = baseType;
-            this.path = BaseTypes.schemaPath(typeName);
+            this.path = path;
             this.description = description;
             this.reference = reference;
         }
@@ -80,27 +96,33 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
             return this;
         }
 
-        public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
+        public Builder addedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+            return this;
+        }
+
+        public Builder unknownSchemaNodes(
+                final List<UnknownSchemaNode> unknownSchemaNodes) {
             this.unknownSchemaNodes = unknownSchemaNodes;
             return this;
         }
 
         public Builder ranges(final List<RangeConstraint> ranges) {
-            if(ranges != null) {
+            if (ranges != null) {
                 this.ranges = ranges;
             }
             return this;
         }
 
         public Builder lengths(final List<LengthConstraint> lengths) {
-            if(lengths != null) {
+            if (lengths != null) {
                 this.lengths = lengths;
             }
             return this;
         }
 
         public Builder patterns(final List<PatternConstraint> patterns) {
-            if(patterns != null) {
+            if (patterns != null) {
                 this.patterns = patterns;
             }
             return this;
@@ -126,6 +148,7 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         this.status = builder.status;
         this.units = builder.units;
         this.defaultValue = builder.defaultValue;
+        this.addedByUses = builder.addedByUses;
 
         this.ranges = builder.ranges;
         this.lengths = builder.lengths;
@@ -148,6 +171,10 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         return defaultValue;
     }
 
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
     @Override
     public QName getQName() {
         return typeName;
@@ -179,124 +206,54 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     }
 
     @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result
-                + ((baseType == null) ? 0 : baseType.hashCode());
-        result = prime * result
-                + ((defaultValue == null) ? 0 : defaultValue.hashCode());
-        result = prime * result
-                + ((description == null) ? 0 : description.hashCode());
-        result = prime * result
-                + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.hashCode());
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
-        result = prime * result
-                + ((reference == null) ? 0 : reference.hashCode());
-        result = prime * result + ((status == null) ? 0 : status.hashCode());
-        result = prime * result
-                + ((typeName == null) ? 0 : typeName.hashCode());
-        result = prime * result + ((units == null) ? 0 : units.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
+    public boolean equals(Object o) {
+        if (this == o) {
             return true;
         }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        ExtendedType other = (ExtendedType) obj;
-        if (baseType == null) {
-            if (other.baseType != null) {
-                return false;
-            }
-        } else if (!baseType.equals(other.baseType)) {
-            return false;
-        }
-        if (defaultValue == null) {
-            if (other.defaultValue != null) {
-                return false;
-            }
-        } else if (!defaultValue.equals(other.defaultValue)) {
+        if (!(o instanceof ExtendedType)) {
             return false;
         }
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
-            return false;
-        }
-        if (unknownSchemaNodes == null) {
-            if (other.unknownSchemaNodes != null) {
-                return false;
-            }
-        } else if (!unknownSchemaNodes.equals(other.unknownSchemaNodes)) {
-            return false;
-        }
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
-            return false;
-        }
-        if (status != other.status) {
-            return false;
-        }
-        if (typeName == null) {
-            if (other.typeName != null) {
-                return false;
-            }
-        } else if (!typeName.equals(other.typeName)) {
+
+        ExtendedType that = (ExtendedType) o;
+        if (path != null ? !path.equals(that.path) : that.path != null) {
             return false;
         }
-        if (units == null) {
-            if (other.units != null) {
-                return false;
-            }
-        } else if (!units.equals(other.units)) {
+        if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null)
             return false;
-        }
+
         return true;
     }
 
+    @Override
+    public int hashCode() {
+        int result = typeName != null ? typeName.hashCode() : 0;
+        result = 31 * result + (path != null ? path.hashCode() : 0);
+        return result;
+    }
+
     @Override
     public String toString() {
-        StringBuilder builder2 = new StringBuilder();
-        builder2.append("ExtendedType [typeName=");
-        builder2.append(typeName);
-        builder2.append(", baseType=");
-        builder2.append(baseType);
-        builder2.append(", path=");
-        builder2.append(path);
-        builder2.append(", description=");
-        builder2.append(description);
-        builder2.append(", reference=");
-        builder2.append(reference);
-        builder2.append(", unknownSchemaNodes=");
-        builder2.append(unknownSchemaNodes);
-        builder2.append(", status=");
-        builder2.append(status);
-        builder2.append(", units=");
-        builder2.append(units);
-        builder2.append(", defaultValue=");
-        builder2.append(defaultValue);
-        builder2.append("]");
-        return builder2.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();
     }
 
     public List<RangeConstraint> getRanges() {