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 static final int MAX_NUMBER_OF_FRACTION_DIGITS = 18;
46 * Default Decimal64 Type Constructor. <br>
48 * The initial range statements are set to Decimal64
49 * <code>min=-922337203685477580.8</code> and
50 * <code>max=922337203685477580.7</code> <br>
51 * The fractions digits MUST be defined as integer between 1 and
52 * {@link #MAX_NUMBER_OF_FRACTION_DIGITS} inclusively as defined interface
53 * {@link DecimalTypeDefinition} <br>
54 * If the fraction digits are not defined inner the definition boundaries
55 * the constructor will throw {@link IllegalArgumentException}
58 * @param fractionDigits
59 * integer between 1 and 18 inclusively
61 * @see DecimalTypeDefinition
62 * @exception IllegalArgumentException
64 public Decimal64(final SchemaPath path, final Integer fractionDigits) {
65 if (!((fractionDigits.intValue() >= 1) && (fractionDigits.intValue() <= MAX_NUMBER_OF_FRACTION_DIGITS))) {
66 throw new IllegalArgumentException(
67 "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
69 this.fractionDigits = fractionDigits;
70 rangeStatements = defaultRangeStatements();
75 * Returns unmodifiable List with default definition of Range Statements.
77 * @return unmodifiable List with default definition of Range Statements.
79 private List<RangeConstraint> defaultRangeStatements() {
80 final List<RangeConstraint> rangeStmts = new ArrayList<RangeConstraint>();
81 final BigDecimal min = new BigDecimal("-922337203685477580.8");
82 final BigDecimal max = new BigDecimal("922337203685477580.7");
83 final String rangeDescription = "Integer values between " + min + " and " + max + ", inclusively.";
84 rangeStmts.add(BaseConstraints.rangeConstraint(min, max, rangeDescription,
85 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
86 return Collections.unmodifiableList(rangeStmts);
90 public DecimalTypeDefinition getBaseType() {
95 public String getUnits() {
100 public Object getDefaultValue() {
101 return DEFAULT_VALUE;
105 public QName getQName() {
110 public SchemaPath getPath() {
115 public String getDescription() {
120 public String getReference() {
125 public Status getStatus() {
126 return Status.CURRENT;
130 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
131 return Collections.emptyList();
135 public List<RangeConstraint> getRangeConstraints() {
136 return rangeStatements;
140 public Integer getFractionDigits() {
141 return fractionDigits;
145 public int hashCode() {
146 final int prime = 31;
148 result = prime * result + ((name == null) ? 0 : name.hashCode());
149 result = prime * result + ((path == null) ? 0 : path.hashCode());
154 public boolean equals(Object obj) {
161 if (getClass() != obj.getClass()) {
164 Decimal64 other = (Decimal64) obj;
166 if (other.name != null) {
169 } else if (!name.equals(other.name)) {
173 if (other.path != null) {
176 } else if (!path.equals(other.path)) {
183 public String toString() {
184 return Decimal64.class.getSimpleName() + "[qname=" + name + ", fractionDigits=" + fractionDigits + "]";