4 package org.opendaylight.controller.yang.model.util;
6 import java.util.ArrayList;
7 import java.util.Collections;
10 import org.opendaylight.controller.yang.common.QName;
11 import org.opendaylight.controller.yang.model.api.SchemaPath;
12 import org.opendaylight.controller.yang.model.api.Status;
13 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
15 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
18 * The Abstract Integer class defines implementation of IntegerTypeDefinition
19 * interface which represents UNSIGNED Integer values defined in Yang language. <br>
20 * The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
21 * They represent unsigned integers of different sizes:
24 * <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
25 * <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
26 * <li>uint32 - represents integer values between 0 and 4294967295, inclusively.
28 * <li>uint64 - represents integer values between 0 and 18446744073709551615,
33 public abstract class AbstractUnsignedInteger implements
34 UnsignedIntegerTypeDefinition {
35 private final QName name;
36 private final SchemaPath path;
37 private final String description;
38 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
40 private final String units;
41 private final List<RangeConstraint> rangeStatements;
43 protected AbstractUnsignedInteger(final QName name,
44 final String description, final Number minRange,
45 final Number maxRange, final String units) {
47 this.description = description;
48 this.path = BaseTypes.schemaPath(name);
50 this.rangeStatements = new ArrayList<RangeConstraint>();
51 final String rangeDescription = "Integer values between " + minRange
52 + " and " + maxRange + ", inclusively.";
53 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
54 maxRange, rangeDescription,
55 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
69 public AbstractUnsignedInteger(final SchemaPath path, final QName name,
70 final String description, final Number minRange,
71 final Number maxRange, final String units) {
73 this.description = description;
76 this.rangeStatements = new ArrayList<RangeConstraint>();
77 final String rangeDescription = "Integer values between " + minRange
78 + " and " + maxRange + ", inclusively.";
79 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
80 maxRange, rangeDescription,
81 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
87 * @param rangeStatements
90 public AbstractUnsignedInteger(final SchemaPath path, final QName name,
91 final String description,
92 final List<RangeConstraint> rangeStatements, final String units) {
94 this.description = description;
97 this.rangeStatements = rangeStatements;
101 public String getUnits() {
106 public QName getQName() {
111 public SchemaPath getPath() {
116 public String getDescription() {
121 public String getReference() {
126 public Status getStatus() {
127 return Status.CURRENT;
131 public List<RangeConstraint> getRangeStatements() {
132 return rangeStatements;
136 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
137 return Collections.emptyList();
141 public int hashCode() {
142 final int prime = 31;
144 result = prime * result
145 + ((description == null) ? 0 : description.hashCode());
146 result = prime * result + ((name == null) ? 0 : name.hashCode());
147 result = prime * result + ((path == null) ? 0 : path.hashCode());
148 result = prime * result
149 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
150 result = prime * result
151 + ((reference == null) ? 0 : reference.hashCode());
152 result = prime * result + ((units == null) ? 0 : units.hashCode());
157 public boolean equals(Object obj) {
164 if (getClass() != obj.getClass()) {
167 AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
168 if (description == null) {
169 if (other.description != null) {
172 } else if (!description.equals(other.description)) {
176 if (other.name != null) {
179 } else if (!name.equals(other.name)) {
183 if (other.path != null) {
186 } else if (!path.equals(other.path)) {
189 if (rangeStatements == null) {
190 if (other.rangeStatements != null) {
193 } else if (!rangeStatements.equals(other.rangeStatements)) {
196 if (reference == null) {
197 if (other.reference != null) {
200 } else if (!reference.equals(other.reference)) {
204 if (other.units != null) {
207 } else if (!units.equals(other.units)) {
214 public String toString() {
215 StringBuilder builder = new StringBuilder();
216 builder.append("AbstractInteger [name=");
217 builder.append(name);
218 builder.append(", path=");
219 builder.append(path);
220 builder.append(", description=");
221 builder.append(description);
222 builder.append(", reference=");
223 builder.append(reference);
224 builder.append(", units=");
225 builder.append(units);
226 builder.append(", rangeStatements=");
227 builder.append(rangeStatements);
229 return builder.toString();