4 package org.opendaylight.controller.model.util;
6 import java.util.ArrayList;
7 import java.util.Collections;
10 import org.opendaylight.controller.model.api.type.RangeConstraint;
11 import org.opendaylight.controller.model.api.type.UnsignedIntegerTypeDefinition;
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;
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. They
21 * 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,
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;
50 public AbstractUnsignedInteger(final QName name, final String description,
51 final Number minRange, final Number maxRange, final String units) {
53 this.description = description;
54 this.path = BaseTypes.schemaPath(name);
56 this.rangeStatements = new ArrayList<RangeConstraint>();
57 final String rangeDescription = "Integer values between " + minRange
58 + " and " + maxRange + ", inclusively.";
59 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
60 maxRange, rangeDescription, "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
66 * @param rangeStatements
69 public AbstractUnsignedInteger(final QName name, final String description,
70 final List<RangeConstraint> rangeStatements, final String units) {
72 this.description = description;
73 this.path = BaseTypes.schemaPath(name);
75 this.rangeStatements = rangeStatements;
79 public String getUnits() {
84 public QName getQName() {
89 public SchemaPath getPath() {
94 public String getDescription() {
99 public String getReference() {
104 public Status getStatus() {
105 return Status.CURRENT;
109 public List<RangeConstraint> getRangeStatements() {
110 return rangeStatements;
114 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
115 return Collections.emptyList();
119 public int hashCode() {
120 final int prime = 31;
122 result = prime * result
123 + ((description == null) ? 0 : description.hashCode());
124 result = prime * result + ((name == null) ? 0 : name.hashCode());
125 result = prime * result + ((path == null) ? 0 : path.hashCode());
126 result = prime * result
127 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
128 result = prime * result
129 + ((reference == null) ? 0 : reference.hashCode());
130 result = prime * result + ((units == null) ? 0 : units.hashCode());
135 public boolean equals(Object obj) {
142 if (getClass() != obj.getClass()) {
145 AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
146 if (description == null) {
147 if (other.description != null) {
150 } else if (!description.equals(other.description)) {
154 if (other.name != null) {
157 } else if (!name.equals(other.name)) {
161 if (other.path != null) {
164 } else if (!path.equals(other.path)) {
167 if (rangeStatements == null) {
168 if (other.rangeStatements != null) {
171 } else if (!rangeStatements.equals(other.rangeStatements)) {
174 if (reference == null) {
175 if (other.reference != null) {
178 } else if (!reference.equals(other.reference)) {
182 if (other.units != null) {
185 } else if (!units.equals(other.units)) {
192 public String toString() {
193 StringBuilder builder = new StringBuilder();
194 builder.append("AbstractInteger [name=");
195 builder.append(name);
196 builder.append(", path=");
197 builder.append(path);
198 builder.append(", description=");
199 builder.append(description);
200 builder.append(", reference=");
201 builder.append(reference);
202 builder.append(", units=");
203 builder.append(units);
204 builder.append(", rangeStatements=");
205 builder.append(rangeStatements);
207 return builder.toString();