Fix minor bug in FRM proactive flow code path
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / Decimal64.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.controller.yang.model.util;
9
10 import java.math.BigDecimal;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
14
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;
21
22 /**
23  * The <code>default</code> implementation of Decimal Type Definition interface.
24  *
25  *
26  * @see DecimalTypeDefinition
27  */
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;
33
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.";
38
39     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.3";
40
41     private final List<RangeConstraint> rangeStatements;
42     private final Integer fractionDigits;
43     private final DecimalTypeDefinition baseType;
44
45     /**
46      * Default Decimal64 Type Constructor. <br>
47      * <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}
55      *
56      * @param path
57      * @param fractionDigits
58      *            integer between 1 and 18 inclusively
59      *
60      * @see DecimalTypeDefinition
61      * @exception IllegalArgumentException
62      */
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");
67         }
68         this.fractionDigits = fractionDigits;
69         rangeStatements = defaultRangeStatements();
70         this.path = path;
71         this.baseType = this;
72     }
73
74     /**
75      * Returns unmodifiable List with default definition of Range Statements.
76      *
77      * @return unmodifiable List with default definition of Range Statements.
78      */
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,
86                 rangeDescription,
87                 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
88         return Collections.unmodifiableList(rangeStatements);
89     }
90
91     @Override
92     public DecimalTypeDefinition getBaseType() {
93         return baseType;
94     }
95
96     @Override
97     public String getUnits() {
98         return units;
99     }
100
101     @Override
102     public Object getDefaultValue() {
103         return defaultValue;
104     }
105
106     @Override
107     public QName getQName() {
108         return name;
109     }
110
111     @Override
112     public SchemaPath getPath() {
113         return path;
114     }
115
116     @Override
117     public String getDescription() {
118         return description;
119     }
120
121     @Override
122     public String getReference() {
123         return reference;
124     }
125
126     @Override
127     public Status getStatus() {
128         return Status.CURRENT;
129     }
130
131     @Override
132     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
133         return Collections.emptyList();
134     }
135
136     @Override
137     public List<RangeConstraint> getRangeStatements() {
138         return rangeStatements;
139     }
140
141     @Override
142     public Integer getFractionDigits() {
143         return fractionDigits;
144     }
145
146     @Override
147     public int hashCode() {
148         final int prime = 31;
149         int result = 1;
150         result = prime * result + ((name == null) ? 0 : name.hashCode());
151         result = prime * result + ((path == null) ? 0 : path.hashCode());
152         return result;
153     }
154
155     @Override
156     public boolean equals(Object obj) {
157         if (this == obj) {
158             return true;
159         }
160         if (obj == null) {
161             return false;
162         }
163         if (getClass() != obj.getClass()) {
164             return false;
165         }
166         Decimal64 other = (Decimal64) obj;
167         if (name == null) {
168             if (other.name != null) {
169                 return false;
170             }
171         } else if (!name.equals(other.name)) {
172             return false;
173         }
174         if (path == null) {
175             if (other.path != null) {
176                 return false;
177             }
178         } else if (!path.equals(other.path)) {
179             return false;
180         }
181         return true;
182     }
183
184     @Override
185     public String toString() {
186         return Decimal64.class.getSimpleName() + "[qname=" + name
187                 + ", fractionDigits=" + fractionDigits + "]";
188     }
189 }