Remove yang.model.util.BaseTypes
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / DecimalTypeDefinition.java
index e3ace5d6e10506df73c8bf5c67039dbc433c09a3..3a2e73ca9fef3d1980d44a6dee834991a9b4cebc 100644 (file)
@@ -7,36 +7,50 @@
  */
 package org.opendaylight.yangtools.yang.model.api.type;
 
-import java.util.List;
-
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import java.math.BigDecimal;
+import java.util.Objects;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.YangConstants;
 
 /**
- * Contains methods for getting data from the YANG <code>type</code>
- * substatement for <code>decimal64</code> built-in type.
- * 
+ * Contains methods for getting data from the YANG <code>type</code> substatement for <code>decimal64</code> built-in
+ * type.
  */
-public interface DecimalTypeDefinition extends TypeDefinition<DecimalTypeDefinition> {
-
+public interface DecimalTypeDefinition extends RangeRestrictedTypeDefinition<DecimalTypeDefinition, BigDecimal> {
     /**
-     * Returns range constraints for instance of this type.
-     * 
-     * @return list of range constraints which are specified as the argument of
-     *         the <code>range</code> which is substatement of the
-     *         <code>type</code> statement
+     * Well-known QName of the {@code decimal64} built-in type.
      */
-    List<RangeConstraint> getRangeStatements();
+    QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, "decimal64").intern();
 
     /**
-     * Returns integer between 1 and 18 inclusively. <br>
-     * <br>
-     * 
-     * The "fraction-digits" statement controls the size of the minimum
-     * difference between values of a decimal64 type, by restricting the value
-     * space to numbers that are expressible as "i x 10^-n" where n is the
-     * fraction-digits argument.
-     * 
+     * Returns integer between 1 and 18 inclusively.
+     *
+     * <p>
+     * The "fraction-digits" statement controls the size of the minimum difference between values of a decimal64 type,
+     * by restricting the value space to numbers that are expressible as "i x 10^-n" where n is the fraction-digits
+     * argument.
+     *
      * @return number of fraction digits
      */
-    Integer getFractionDigits();
+    int getFractionDigits();
+
+    static int hashCode(final DecimalTypeDefinition type) {
+        return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
+            type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getFractionDigits(),
+            type.getRangeConstraint().orElse(null));
+    }
+
+    static boolean equals(final DecimalTypeDefinition type, final Object obj) {
+        if (type == obj) {
+            return true;
+        }
+
+        final DecimalTypeDefinition other = TypeDefinitions.castIfEquals(DecimalTypeDefinition.class, type, obj);
+        return other != null && type.getFractionDigits() == other.getFractionDigits()
+                && type.getRangeConstraint().equals(other.getRangeConstraint());
+    }
+
+    static String toString(final DecimalTypeDefinition type) {
+        return TypeDefinitions.toStringHelper(type).add("fractionDigits", type.getFractionDigits()).toString();
+    }
 }