Merge "BUG-2962: add DataTreeTip interface and implement it"
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / Decimal64.java
index 64f1dc6e8ec49912b8eed68987200cc77897c615..8b643568bafa25ed12cf5d5a0e09525f3c5317d0 100644 (file)
@@ -19,19 +19,21 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 
+import com.google.common.base.Optional;
+
 /**
  * The <code>default</code> implementation of Decimal Type Definition interface.
- * 
- * 
+ *
+ *
  * @see DecimalTypeDefinition
  */
 public final class Decimal64 implements DecimalTypeDefinition {
-    private final QName name = BaseTypes.constructQName("decimal64");
+    private static final QName NAME = BaseTypes.DECIMAL64_QNAME;
     private final SchemaPath path;
     private static final String UNITS = "";
     private static final BigDecimal DEFAULT_VALUE = null;
 
-    private final String description = "The decimal64 type represents a subset of the real numbers, which can "
+    private static final String DESCRIPTION = "The decimal64 type represents a subset of the real numbers, which can "
             + "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
             + "be obtained by multiplying a 64-bit signed integer by a negative power of ten, i.e., expressible as "
             + "'i x 10^-n' where i is an integer64 and n is an integer between 1 and 18, inclusively.";
@@ -40,7 +42,6 @@ public final class Decimal64 implements DecimalTypeDefinition {
 
     private final List<RangeConstraint> rangeStatements;
     private final Integer fractionDigits;
-    private final DecimalTypeDefinition baseType;
     private static final int MAX_NUMBER_OF_FRACTION_DIGITS = 18;
 
     /**
@@ -54,14 +55,16 @@ public final class Decimal64 implements DecimalTypeDefinition {
      * {@link DecimalTypeDefinition} <br>
      * If the fraction digits are not defined inner the definition boundaries
      * the constructor will throw {@link IllegalArgumentException}
-     * 
+     *
      * @param path
      * @param fractionDigits
      *            integer between 1 and 18 inclusively
-     * 
+     *
      * @see DecimalTypeDefinition
      * @exception IllegalArgumentException
+     * @deprecated Use static factory {@link #create(SchemaPath, Integer)}.
      */
+    @Deprecated
     public Decimal64(final SchemaPath path, final Integer fractionDigits) {
         if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= MAX_NUMBER_OF_FRACTION_DIGITS))) {
             throw new IllegalArgumentException(
@@ -70,12 +73,15 @@ public final class Decimal64 implements DecimalTypeDefinition {
         this.fractionDigits = fractionDigits;
         rangeStatements = defaultRangeStatements();
         this.path = path;
-        this.baseType = this;
+    }
+
+    public static Decimal64 create(final SchemaPath path, final Integer fractionDigits) {
+        return new Decimal64(path, fractionDigits);
     }
 
     /**
      * Returns unmodifiable List with default definition of Range Statements.
-     * 
+     *
      * @return unmodifiable List with default definition of Range Statements.
      */
     private List<RangeConstraint> defaultRangeStatements() {
@@ -83,14 +89,14 @@ public final class Decimal64 implements DecimalTypeDefinition {
         final BigDecimal min = new BigDecimal("-922337203685477580.8");
         final BigDecimal max = new BigDecimal("922337203685477580.7");
         final String rangeDescription = "Integer values between " + min + " and " + max + ", inclusively.";
-        rangeStmts.add(BaseConstraints.rangeConstraint(min, max, rangeDescription,
-                "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
+        rangeStmts.add(BaseConstraints.newRangeConstraint(min, max, Optional.of(rangeDescription),
+                Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4")));
         return Collections.unmodifiableList(rangeStmts);
     }
 
     @Override
     public DecimalTypeDefinition getBaseType() {
-        return baseType;
+        return null;
     }
 
     @Override
@@ -105,7 +111,7 @@ public final class Decimal64 implements DecimalTypeDefinition {
 
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
     @Override
@@ -115,7 +121,7 @@ public final class Decimal64 implements DecimalTypeDefinition {
 
     @Override
     public String getDescription() {
-        return description;
+        return DESCRIPTION;
     }
 
     @Override
@@ -134,7 +140,7 @@ public final class Decimal64 implements DecimalTypeDefinition {
     }
 
     @Override
-    public List<RangeConstraint> getRangeStatements() {
+    public List<RangeConstraint> getRangeConstraints() {
         return rangeStatements;
     }
 
@@ -147,13 +153,13 @@ public final class Decimal64 implements DecimalTypeDefinition {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((NAME == null) ? 0 : NAME.hashCode());
         result = prime * result + ((path == null) ? 0 : path.hashCode());
         return result;
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -164,13 +170,6 @@ public final class Decimal64 implements DecimalTypeDefinition {
             return false;
         }
         Decimal64 other = (Decimal64) obj;
-        if (name == null) {
-            if (other.name != null) {
-                return false;
-            }
-        } else if (!name.equals(other.name)) {
-            return false;
-        }
         if (path == null) {
             if (other.path != null) {
                 return false;
@@ -183,6 +182,6 @@ public final class Decimal64 implements DecimalTypeDefinition {
 
     @Override
     public String toString() {
-        return Decimal64.class.getSimpleName() + "[qname=" + name + ", fractionDigits=" + fractionDigits + "]";
+        return Decimal64.class.getSimpleName() + "[qname=" + NAME + ", fractionDigits=" + fractionDigits + "]";
     }
 }