2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.util;
10 import java.math.BigDecimal;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
23 * The <code>default</code> implementation of Decimal Type Definition interface.
26 * @see DecimalTypeDefinition
28 public final class Decimal64 implements DecimalTypeDefinition {
29 private final QName name = BaseTypes.constructQName("decimal64");
30 private final SchemaPath path;
31 private static final String UNITS = "";
32 private static final BigDecimal DEFAULT_VALUE = null;
34 private final String description = "The decimal64 type represents a subset of the real numbers, which can "
35 + "be represented by decimal numerals. The value space of decimal64 is the set of numbers that can "
36 + "be obtained by multiplying a 64-bit signed integer by a negative power of ten, i.e., expressible as "
37 + "'i x 10^-n' where i is an integer64 and n is an integer between 1 and 18, inclusively.";
39 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.3";
41 private final List<RangeConstraint> rangeStatements;
42 private final Integer fractionDigits;
43 private final DecimalTypeDefinition baseType;
44 private static final int MAX_NUMBER_OF_FRACTION_DIGITS = 18;
47 * Default Decimal64 Type Constructor. <br>
49 * The initial range statements are set to Decimal64
50 * <code>min=-922337203685477580.8</code> and
51 * <code>max=922337203685477580.7</code> <br>
52 * The fractions digits MUST be defined as integer between 1 and
53 * {@link #MAX_NUMBER_OF_FRACTION_DIGITS} inclusively as defined interface
54 * {@link DecimalTypeDefinition} <br>
55 * If the fraction digits are not defined inner the definition boundaries
56 * the constructor will throw {@link IllegalArgumentException}
59 * @param fractionDigits
60 * integer between 1 and 18 inclusively
62 * @see DecimalTypeDefinition
63 * @exception IllegalArgumentException
65 public Decimal64(final SchemaPath path, final Integer fractionDigits) {
66 if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= MAX_NUMBER_OF_FRACTION_DIGITS))) {
67 throw new IllegalArgumentException(
68 "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
70 this.fractionDigits = fractionDigits;
71 rangeStatements = defaultRangeStatements();
77 * Returns unmodifiable List with default definition of Range Statements.
79 * @return unmodifiable List with default definition of Range Statements.
81 private List<RangeConstraint> defaultRangeStatements() {
82 final List<RangeConstraint> rangeStmts = new ArrayList<RangeConstraint>();
83 final BigDecimal min = new BigDecimal("-922337203685477580.8");
84 final BigDecimal max = new BigDecimal("922337203685477580.7");
85 final String rangeDescription = "Integer values between " + min + " and " + max + ", inclusively.";
86 rangeStmts.add(BaseConstraints.rangeConstraint(min, max, rangeDescription,
87 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
88 return Collections.unmodifiableList(rangeStmts);
92 public DecimalTypeDefinition getBaseType() {
97 public String getUnits() {
102 public Object getDefaultValue() {
103 return DEFAULT_VALUE;
107 public QName getQName() {
112 public SchemaPath getPath() {
117 public String getDescription() {
122 public String getReference() {
127 public Status getStatus() {
128 return Status.CURRENT;
132 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
133 return Collections.emptyList();
137 public List<RangeConstraint> getRangeConstraints() {
138 return rangeStatements;
142 public Integer getFractionDigits() {
143 return fractionDigits;
147 public int hashCode() {
148 final int prime = 31;
150 result = prime * result + ((name == null) ? 0 : name.hashCode());
151 result = prime * result + ((path == null) ? 0 : path.hashCode());
156 public boolean equals(Object obj) {
163 if (getClass() != obj.getClass()) {
166 Decimal64 other = (Decimal64) obj;
168 if (other.name != null) {
171 } else if (!name.equals(other.name)) {
175 if (other.path != null) {
178 } else if (!path.equals(other.path)) {
185 public String toString() {
186 return Decimal64.class.getSimpleName() + "[qname=" + name + ", fractionDigits=" + fractionDigits + "]";