Remove yang.model.util.BaseTypes
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / DecimalTypeDefinition.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.model.api.type;
9
10 import java.math.BigDecimal;
11 import java.util.Objects;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.common.YangConstants;
14
15 /**
16  * Contains methods for getting data from the YANG <code>type</code> substatement for <code>decimal64</code> built-in
17  * type.
18  */
19 public interface DecimalTypeDefinition extends RangeRestrictedTypeDefinition<DecimalTypeDefinition, BigDecimal> {
20     /**
21      * Well-known QName of the {@code decimal64} built-in type.
22      */
23     QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, "decimal64").intern();
24
25     /**
26      * Returns integer between 1 and 18 inclusively.
27      *
28      * <p>
29      * The "fraction-digits" statement controls the size of the minimum difference between values of a decimal64 type,
30      * by restricting the value space to numbers that are expressible as "i x 10^-n" where n is the fraction-digits
31      * argument.
32      *
33      * @return number of fraction digits
34      */
35     int getFractionDigits();
36
37     static int hashCode(final DecimalTypeDefinition type) {
38         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
39             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getFractionDigits(),
40             type.getRangeConstraint().orElse(null));
41     }
42
43     static boolean equals(final DecimalTypeDefinition type, final Object obj) {
44         if (type == obj) {
45             return true;
46         }
47
48         final DecimalTypeDefinition other = TypeDefinitions.castIfEquals(DecimalTypeDefinition.class, type, obj);
49         return other != null && type.getFractionDigits() == other.getFractionDigits()
50                 && type.getRangeConstraint().equals(other.getRangeConstraint());
51     }
52
53     static String toString(final DecimalTypeDefinition type) {
54         return TypeDefinitions.toStringHelper(type).add("fractionDigits", type.getFractionDigits()).toString();
55     }
56 }