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.controller.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.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.controller.yang.model.api.type.DecimalTypeDefinition;
20 import org.opendaylight.controller.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 final String units = "";
32 private final BigDecimal defaultValue = 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 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;
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 18
52 * inclusively as defined interface {@link DecimalTypeDefinition} <br>
53 * If the fraction digits are not defined inner the definition boundaries
54 * the constructor will throw {@link IllegalArgumentException}
57 * @param fractionDigits
58 * integer between 1 and 18 inclusively
60 * @see DecimalTypeDefinition
61 * @exception IllegalArgumentException
63 public Decimal64(final SchemaPath path, final Integer fractionDigits) {
64 if (!((fractionDigits.intValue() > 1) && (fractionDigits.intValue() <= 18))) {
65 throw new IllegalArgumentException(
66 "The fraction digits outside of boundaries. Fraction digits MUST be integer between 1 and 18 inclusively");
68 this.fractionDigits = fractionDigits;
69 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> rangeStatements = 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
84 + " and " + max + ", inclusively.";
85 rangeStatements.add(BaseConstraints.rangeConstraint(min, max,
87 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
88 return Collections.unmodifiableList(rangeStatements);
92 public DecimalTypeDefinition getBaseType() {
97 public String getUnits() {
102 public Object getDefaultValue() {
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> getRangeStatements() {
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
187 + ", fractionDigits=" + fractionDigits + "]";