Updated YANG Type definitions and documentation in YANG Model Utils.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / model / util / Decimal64.java
index 233e4607ce703eeb1cadd7f6499154e1c293a41a..31c8c0d32da5764b4ad0b07878cccf6410825ac3 100644 (file)
@@ -1,10 +1,10 @@
 /*\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
+ * 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.controller.model.util;\r
 \r
 import java.math.BigDecimal;\r
@@ -19,6 +19,12 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.Status;\r
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
 \r
+/**\r
+ * The <code>default</code> implementation of Decimal Type Definition interface.\r
+ * \r
+ * \r
+ * @see DecimalTypeDefinition\r
+ */\r
 public class Decimal64 implements DecimalTypeDefinition {\r
 \r
     private final QName name = BaseTypes.constructQName("decimal64");\r
@@ -27,7 +33,7 @@ public class Decimal64 implements DecimalTypeDefinition {
     private BigDecimal defaultValue = null;\r
 \r
     private final String description = "The decimal64 type represents a subset of the real numbers, which can "\r
-            + "be represented by decimal numerals.  The value space of decimal64 is the set of numbers that can "\r
+            + "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "\r
             + "be obtained by multiplying a 64-bit signed integer by a negative power of ten, i.e., expressible as "\r
             + "'i x 10^-n' where i is an integer64 and n is an integer between 1 and 18, inclusively.";\r
 \r
@@ -36,32 +42,132 @@ public class Decimal64 implements DecimalTypeDefinition {
     private final List<RangeConstraint> rangeStatements;\r
     private final Integer fractionDigits;\r
 \r
+    /**\r
+     * Default Decimal64 Type Constructor. <br>\r
+     * <br>\r
+     * The initial range statements are set to Decimal64\r
+     * <code>min=-922337203685477580.8</code> and\r
+     * <code>max=922337203685477580.7</code> <br>\r
+     * The fractions digits MUST be defined as integer between 1 and 18\r
+     * inclusively as defined interface {@link DecimalTypeDefinition} <br>\r
+     * If the fraction digits are not defined inner the definition boundaries\r
+     * the constructor will throw {@link IllegalArgumentException}\r
+     * \r
+     * @param fractionDigits\r
+     *            integer between 1 and 18 inclusively\r
+     * \r
+     * @see DecimalTypeDefinition\r
+     * @exception IllegalArgumentException\r
+     */\r
     public Decimal64(final Integer fractionDigits) {\r
         super();\r
+        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {\r
+            throw new IllegalArgumentException(\r
+                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");\r
+        }\r
         this.fractionDigits = fractionDigits;\r
-        rangeStatements = new ArrayList<RangeConstraint>();\r
+        rangeStatements = defaultRangeStatements();\r
         this.path = BaseTypes.schemaPath(name);\r
     }\r
 \r
+    /**\r
+     * Decimal64 Type Constructor. <br>\r
+     * \r
+     * If parameter <code>Range Statements</code> is <code>null</code> or\r
+     * defined as <code>empty List</code> the constructor automatically assigns\r
+     * the boundaries as min and max value defined for Decimal64 in <a\r
+     * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The\r
+     * decimal64 Built-In Type</a> <br>\r
+     * <br>\r
+     * The fractions digits MUST be defined as integer between 1 and 18\r
+     * inclusively as defined interface {@link DecimalTypeDefinition} <br>\r
+     * If the fraction digits are not defined inner the definition boundaries\r
+     * the constructor will throw {@link IllegalArgumentException}\r
+     * \r
+     * @param rangeStatements\r
+     *            Range Constraint Statements\r
+     * @param fractionDigits\r
+     *            integer between 1 and 18 inclusively\r
+     * @exception IllegalArgumentException\r
+     */\r
     public Decimal64(final List<RangeConstraint> rangeStatements,\r
             Integer fractionDigits) {\r
         super();\r
-        this.rangeStatements = rangeStatements;\r
+        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {\r
+            throw new IllegalArgumentException(\r
+                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");\r
+        }\r
+        if (rangeStatements == null || rangeStatements.isEmpty()) {\r
+            this.rangeStatements = defaultRangeStatements();\r
+        } else {\r
+            this.rangeStatements = Collections.unmodifiableList(rangeStatements);\r
+        }\r
         this.fractionDigits = fractionDigits;\r
         this.path = BaseTypes.schemaPath(name);\r
     }\r
 \r
+    /**\r
+     * Decimal64 Type Constructor. <br>\r
+     * If parameter <code>Range Statements</code> is <code>null</code> or\r
+     * defined as <code>empty List</code> the constructor automatically assigns\r
+     * the boundaries as min and max value defined for Decimal64 in <a\r
+     * href="https://tools.ietf.org/html/rfc6020#section-9.3">[RFC-6020] The\r
+     * decimal64 Built-In Type</a> <br>\r
+     * <br>\r
+     * The fractions digits MUST be defined as integer between 1 and 18\r
+     * inclusively as defined interface {@link DecimalTypeDefinition} <br>\r
+     * If the fraction digits are not defined inner the definition boundaries\r
+     * the constructor will throw {@link IllegalArgumentException}\r
+     * \r
+     * @param units\r
+     *            units associated with the type\r
+     * @param defaultValue\r
+     *            Default Value for type\r
+     * @param rangeStatements\r
+     *            Range Constraint Statements\r
+     * @param fractionDigits\r
+     *            integer between 1 and 18 inclusively\r
+     * \r
+     * @exception IllegalArgumentException\r
+     */\r
     public Decimal64(final String units, final BigDecimal defaultValue,\r
             final List<RangeConstraint> rangeStatements,\r
             final Integer fractionDigits) {\r
         super();\r
+        if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {\r
+            throw new IllegalArgumentException(\r
+                    "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");\r
+        }\r
+\r
+        if (rangeStatements == null || rangeStatements.isEmpty()) {\r
+            this.rangeStatements = defaultRangeStatements();\r
+            \r
+        } else {\r
+            this.rangeStatements = Collections.unmodifiableList(rangeStatements);\r
+        }\r
         this.units = units;\r
         this.defaultValue = defaultValue;\r
-        this.rangeStatements = rangeStatements;\r
         this.fractionDigits = fractionDigits;\r
         this.path = BaseTypes.schemaPath(name);\r
     }\r
 \r
+    /**\r
+     * Returns unmodifiable List with default definition of Range Statements.\r
+     * \r
+     * @return unmodifiable List with default definition of Range Statements.\r
+     */\r
+    private List<RangeConstraint> defaultRangeStatements() {\r
+        final List<RangeConstraint> rangeStatements = new ArrayList<RangeConstraint>();\r
+        final BigDecimal min = new BigDecimal("-922337203685477580.8");\r
+        final BigDecimal max = new BigDecimal("922337203685477580.7");\r
+        final String rangeDescription = "Integer values between " + min\r
+                + " and " + max + ", inclusively.";\r
+        rangeStatements.add(BaseConstraints.rangeConstraint(min, max,\r
+                rangeDescription,\r
+                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));\r
+        return Collections.unmodifiableList(rangeStatements);\r
+    }\r
+\r
     @Override\r
     public DecimalTypeDefinition getBaseType() {\r
         return this;\r
@@ -117,6 +223,44 @@ public class Decimal64 implements DecimalTypeDefinition {
         return fractionDigits;\r
     }\r
 \r
+    @Override\r
+    public int hashCode() {\r
+        final int prime = 31;\r
+        int result = 1;\r
+        result = prime * result + ((name == null) ? 0 : name.hashCode());\r
+        result = prime * result + ((path == null) ? 0 : path.hashCode());\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj) {\r
+            return true;\r
+        }\r
+        if (obj == null) {\r
+            return false;\r
+        }\r
+        if (getClass() != obj.getClass()) {\r
+            return false;\r
+        }\r
+        Decimal64 other = (Decimal64) obj;\r
+        if (name == null) {\r
+            if (other.name != null) {\r
+                return false;\r
+            }\r
+        } else if (!name.equals(other.name)) {\r
+            return false;\r
+        }\r
+        if (path == null) {\r
+            if (other.path != null) {\r
+                return false;\r
+            }\r
+        } else if (!path.equals(other.path)) {\r
+            return false;\r
+        }\r
+        return true;\r
+    }\r
+\r
     @Override\r
     public String toString() {\r
         return Decimal64.class.getSimpleName() + "[qname=" + name\r