e548f4eeeb9e35318d394d47c570790be98ff909
[yangtools.git] / model / 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
13 /**
14  * Contains methods for getting data from the YANG <code>type</code> substatement for <code>decimal64</code> built-in
15  * type.
16  */
17 public interface DecimalTypeDefinition extends RangeRestrictedTypeDefinition<DecimalTypeDefinition, BigDecimal> {
18     /**
19      * Returns integer between 1 and 18 inclusively.
20      *
21      * <p>
22      * The "fraction-digits" statement controls the size of the minimum difference between values of a decimal64 type,
23      * by restricting the value space to numbers that are expressible as "i x 10^-n" where n is the fraction-digits
24      * argument.
25      *
26      * @return number of fraction digits
27      */
28     int getFractionDigits();
29
30     static int hashCode(final DecimalTypeDefinition type) {
31         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
32             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getFractionDigits(),
33             type.getRangeConstraint().orElse(null));
34     }
35
36     static boolean equals(final DecimalTypeDefinition type, final Object obj) {
37         if (type == obj) {
38             return true;
39         }
40
41         final DecimalTypeDefinition other = TypeDefinitions.castIfEquals(DecimalTypeDefinition.class, type, obj);
42         return other != null && type.getFractionDigits() == other.getFractionDigits()
43                 && type.getRangeConstraint().equals(other.getRangeConstraint());
44     }
45
46     static String toString(final DecimalTypeDefinition type) {
47         return TypeDefinitions.toStringHelper(type).add("fractionDigits", type.getFractionDigits()).toString();
48     }
49 }