HostTracker Bundle Separation
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / ExtendedType.java
index c82df2e079cfaa98a1bb70119ebc2860c80c4851..86bde24d62d8131314f0f1d37b7e8ed61552f72e 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;
@@ -15,8 +17,11 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
+import org.opendaylight.controller.yang.model.api.type.PatternConstraint;
+import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
 
-public class ExtendedType implements TypeDefinition {
+public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
 
     private final QName typeName;
     private final TypeDefinition<?> baseType;
@@ -25,6 +30,11 @@ public class ExtendedType implements 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 Status status;
     private String units;
     private Object defaultValue;
@@ -37,16 +47,34 @@ public class ExtendedType implements 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 Object defaultValue = null;
 
+        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;
         }
@@ -66,11 +94,38 @@ public class ExtendedType implements TypeDefinition {
             return this;
         }
 
-        public Builder unknownSchemaNodes(final List<UnknownSchemaNode> unknownSchemaNodes) {
+        public Builder unknownSchemaNodes(
+                final List<UnknownSchemaNode> unknownSchemaNodes) {
             this.unknownSchemaNodes = unknownSchemaNodes;
             return this;
         }
 
+        public Builder ranges(final List<RangeConstraint> ranges) {
+            if (ranges != null) {
+                this.ranges = ranges;
+            }
+            return this;
+        }
+
+        public Builder lengths(final List<LengthConstraint> lengths) {
+            if (lengths != null) {
+                this.lengths = lengths;
+            }
+            return this;
+        }
+
+        public Builder patterns(final List<PatternConstraint> patterns) {
+            if (patterns != null) {
+                this.patterns = patterns;
+            }
+            return this;
+        }
+
+        public Builder fractionDigits(final Integer fractionDigits) {
+            this.fractionDigits = fractionDigits;
+            return this;
+        }
+
         public ExtendedType build() {
             return new ExtendedType(this);
         }
@@ -86,6 +141,11 @@ public class ExtendedType implements TypeDefinition {
         this.status = builder.status;
         this.units = builder.units;
         this.defaultValue = builder.defaultValue;
+
+        this.ranges = builder.ranges;
+        this.lengths = builder.lengths;
+        this.patterns = builder.patterns;
+        this.fractionDigits = builder.fractionDigits;
     }
 
     @Override
@@ -143,8 +203,10 @@ public class ExtendedType implements TypeDefinition {
                 + ((defaultValue == null) ? 0 : defaultValue.hashCode());
         result = prime * result
                 + ((description == null) ? 0 : description.hashCode());
-        result = prime * result
-                + ((unknownSchemaNodes == null) ? 0 : unknownSchemaNodes.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());
@@ -253,4 +315,20 @@ public class ExtendedType implements TypeDefinition {
         builder2.append("]");
         return builder2.toString();
     }
+
+    public List<RangeConstraint> getRanges() {
+        return ranges;
+    }
+
+    public List<LengthConstraint> getLengths() {
+        return lengths;
+    }
+
+    public List<PatternConstraint> getPatterns() {
+        return patterns;
+    }
+
+    public Integer getFractionDigits() {
+        return fractionDigits;
+    }
 }