4 package org.opendaylight.yangtools.yang.model.util;
6 import java.util.ArrayList;
7 import java.util.Collections;
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
12 import org.opendaylight.yangtools.yang.model.api.Status;
13 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
15 import org.opendaylight.yangtools.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 static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
39 private final String units;
40 private final List<RangeConstraint> rangeStatements;
49 public AbstractUnsignedInteger(final QName name, final String description, final Number maxRange, final String units) {
51 this.path = new SchemaPath(Collections.singletonList(name), true);
52 this.description = description;
54 this.rangeStatements = new ArrayList<RangeConstraint>();
55 final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + maxRange + ", inclusively.";
56 this.rangeStatements.add(BaseConstraints.rangeConstraint(MIN_VALUE, maxRange, rangeDescription,
57 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
61 public String getUnits() {
66 public QName getQName() {
71 public SchemaPath getPath() {
76 public String getDescription() {
81 public String getReference() {
86 public Status getStatus() {
87 return Status.CURRENT;
91 public List<RangeConstraint> getRangeStatements() {
92 return rangeStatements;
96 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
97 return Collections.emptyList();
101 public int hashCode() {
102 final int prime = 31;
104 result = prime * result + ((description == null) ? 0 : description.hashCode());
105 result = prime * result + ((name == null) ? 0 : name.hashCode());
106 result = prime * result + ((path == null) ? 0 : path.hashCode());
107 result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
108 result = prime * result + ((units == null) ? 0 : units.hashCode());
113 public boolean equals(Object obj) {
120 if (getClass() != obj.getClass()) {
123 AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
124 if (description == null) {
125 if (other.description != null) {
128 } else if (!description.equals(other.description)) {
132 if (other.name != null) {
135 } else if (!name.equals(other.name)) {
139 if (other.path != null) {
142 } else if (!path.equals(other.path)) {
145 if (rangeStatements == null) {
146 if (other.rangeStatements != null) {
149 } else if (!rangeStatements.equals(other.rangeStatements)) {
153 if (other.units != null) {
156 } else if (!units.equals(other.units)) {
163 public String toString() {
164 StringBuilder builder = new StringBuilder();
165 builder.append("AbstractInteger [name=");
166 builder.append(name);
167 builder.append(", path=");
168 builder.append(path);
169 builder.append(", description=");
170 builder.append(description);
171 builder.append(", reference=");
172 builder.append(REFERENCE);
173 builder.append(", units=");
174 builder.append(units);
175 builder.append(", rangeStatements=");
176 builder.append(rangeStatements);
178 return builder.toString();