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 UnsignedIntegerTypeDefinition {
34 private static final long MIN_VALUE = 0;
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";
39 private final String units;
40 private final List<RangeConstraint> rangeStatements;
44 * @param path uint type schema path
50 public AbstractUnsignedInteger(final SchemaPath path, final QName name, final String description,
51 final Number maxRange, final String units) {
53 this.description = description;
56 this.rangeStatements = new ArrayList<RangeConstraint>();
57 final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + maxRange + ", inclusively.";
58 this.rangeStatements.add(BaseConstraints.rangeConstraint(MIN_VALUE, maxRange, rangeDescription,
59 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
64 * @param path uint type schema path
67 * @param rangeStatements
70 public AbstractUnsignedInteger(final SchemaPath path, final QName name, final String description,
71 final List<RangeConstraint> rangeStatements, final String units) {
73 this.description = description;
76 this.rangeStatements = rangeStatements;
80 public String getUnits() {
85 public QName getQName() {
90 public SchemaPath getPath() {
95 public String getDescription() {
100 public String getReference() {
105 public Status getStatus() {
106 return Status.CURRENT;
110 public List<RangeConstraint> getRangeStatements() {
111 return rangeStatements;
115 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
116 return Collections.emptyList();
120 public int hashCode() {
121 final int prime = 31;
123 result = prime * result + ((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 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
127 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
128 result = prime * result + ((units == null) ? 0 : units.hashCode());
133 public boolean equals(Object obj) {
140 if (getClass() != obj.getClass()) {
143 AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
144 if (description == null) {
145 if (other.description != null) {
148 } else if (!description.equals(other.description)) {
152 if (other.name != null) {
155 } else if (!name.equals(other.name)) {
159 if (other.path != null) {
162 } else if (!path.equals(other.path)) {
165 if (rangeStatements == null) {
166 if (other.rangeStatements != null) {
169 } else if (!rangeStatements.equals(other.rangeStatements)) {
172 if (reference == null) {
173 if (other.reference != null) {
176 } else if (!reference.equals(other.reference)) {
180 if (other.units != null) {
183 } else if (!units.equals(other.units)) {
190 public String toString() {
191 StringBuilder builder = new StringBuilder();
192 builder.append("AbstractInteger [name=");
193 builder.append(name);
194 builder.append(", path=");
195 builder.append(path);
196 builder.append(", description=");
197 builder.append(description);
198 builder.append(", reference=");
199 builder.append(reference);
200 builder.append(", units=");
201 builder.append(units);
202 builder.append(", rangeStatements=");
203 builder.append(rangeStatements);
205 return builder.toString();