4 package org.opendaylight.controller.yang.model.util;
7 import java.util.ArrayList;
8 import java.util.Collections;
10 import java.util.List;
12 import org.opendaylight.controller.yang.common.QName;
13 import org.opendaylight.controller.yang.model.api.SchemaPath;
14 import org.opendaylight.controller.yang.model.api.Status;
15 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
16 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
17 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
20 * The Abstract Integer class defines implementation of IntegerTypeDefinition
21 * interface which represents UNSIGNED Integer values defined in Yang language. <br>
22 * The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
23 * They represent unsigned integers of different sizes:
26 * <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
27 * <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
28 * <li>uint32 - represents integer values between 0 and 4294967295, inclusively.
30 * <li>uint64 - represents integer values between 0 and 18446744073709551615,
35 public abstract class AbstractUnsignedInteger implements
36 UnsignedIntegerTypeDefinition {
37 private final QName name;
38 private final SchemaPath path;
39 private final String description;
40 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
42 private final String units;
43 private final List<RangeConstraint> rangeStatements;
45 protected AbstractUnsignedInteger(final QName name,
46 final String description, final Number minRange,
47 final Number maxRange, final String units) {
49 this.description = description;
50 this.path = BaseTypes.schemaPath(name);
52 this.rangeStatements = new ArrayList<RangeConstraint>();
53 final String rangeDescription = "Integer values between " + minRange
54 + " and " + maxRange + ", inclusively.";
55 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
56 maxRange, rangeDescription,
57 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
71 public AbstractUnsignedInteger(final List<String> actualPath,
72 final URI namespace, final Date revision, final QName name,
73 final String description, final Number minRange,
74 final Number maxRange, final String units) {
76 this.description = description;
77 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
79 this.rangeStatements = new ArrayList<RangeConstraint>();
80 final String rangeDescription = "Integer values between " + minRange
81 + " and " + maxRange + ", inclusively.";
82 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
83 maxRange, rangeDescription,
84 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
90 * @param rangeStatements
93 public AbstractUnsignedInteger(final List<String> actualPath,
94 final URI namespace, final Date revision, final QName name,
95 final String description,
96 final List<RangeConstraint> rangeStatements, final String units) {
98 this.description = description;
99 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
101 this.rangeStatements = rangeStatements;
105 public String getUnits() {
110 public QName getQName() {
115 public SchemaPath getPath() {
120 public String getDescription() {
125 public String getReference() {
130 public Status getStatus() {
131 return Status.CURRENT;
135 public List<RangeConstraint> getRangeStatements() {
136 return rangeStatements;
140 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
141 return Collections.emptyList();
145 public int hashCode() {
146 final int prime = 31;
148 result = prime * result
149 + ((description == null) ? 0 : description.hashCode());
150 result = prime * result + ((name == null) ? 0 : name.hashCode());
151 result = prime * result + ((path == null) ? 0 : path.hashCode());
152 result = prime * result
153 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
154 result = prime * result
155 + ((reference == null) ? 0 : reference.hashCode());
156 result = prime * result + ((units == null) ? 0 : units.hashCode());
161 public boolean equals(Object obj) {
168 if (getClass() != obj.getClass()) {
171 AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
172 if (description == null) {
173 if (other.description != null) {
176 } else if (!description.equals(other.description)) {
180 if (other.name != null) {
183 } else if (!name.equals(other.name)) {
187 if (other.path != null) {
190 } else if (!path.equals(other.path)) {
193 if (rangeStatements == null) {
194 if (other.rangeStatements != null) {
197 } else if (!rangeStatements.equals(other.rangeStatements)) {
200 if (reference == null) {
201 if (other.reference != null) {
204 } else if (!reference.equals(other.reference)) {
208 if (other.units != null) {
211 } else if (!units.equals(other.units)) {
218 public String toString() {
219 StringBuilder builder = new StringBuilder();
220 builder.append("AbstractInteger [name=");
221 builder.append(name);
222 builder.append(", path=");
223 builder.append(path);
224 builder.append(", description=");
225 builder.append(description);
226 builder.append(", reference=");
227 builder.append(reference);
228 builder.append(", units=");
229 builder.append(units);
230 builder.append(", rangeStatements=");
231 builder.append(rangeStatements);
233 return builder.toString();