2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.util;
10 import java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
18 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
20 import com.google.common.base.Optional;
23 * The Abstract Integer class defines implementation of IntegerTypeDefinition
24 * interface which represents UNSIGNED Integer values defined in Yang language. <br>
25 * The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
26 * They represent unsigned integers of different sizes:
29 * <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
30 * <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
31 * <li>uint32 - represents integer values between 0 and 4294967295, inclusively.
33 * <li>uint64 - represents integer values between 0 and 18446744073709551615,
38 abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition {
39 private static final long MIN_VALUE = 0;
40 private final QName name;
41 private final SchemaPath path;
42 private final String description;
43 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
44 private final String units;
45 private final List<RangeConstraint> rangeStatements;
48 * Construct Unsigned Integer
50 * @param name Name of type
51 * @param description Description of type
52 * @param maxRange Maximum value
55 public AbstractUnsignedInteger(final QName name, final String description, final Number maxRange, final String units) {
57 this.path = SchemaPath.create(Collections.singletonList(name), true);
58 this.description = description;
60 final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + maxRange + ", inclusively.";
61 this.rangeStatements = Collections.singletonList(BaseConstraints.newRangeConstraint(MIN_VALUE, maxRange, Optional.of(rangeDescription),
62 Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4")));
66 public UnsignedIntegerTypeDefinition getBaseType() {
71 public String getUnits() {
76 public QName getQName() {
81 public SchemaPath getPath() {
86 public String getDescription() {
91 public String getReference() {
96 public Status getStatus() {
97 return Status.CURRENT;
101 public List<RangeConstraint> getRangeConstraints() {
102 return rangeStatements;
106 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
107 return Collections.emptyList();
111 public int hashCode() {
112 final int prime = 31;
114 result = prime * result + ((description == null) ? 0 : description.hashCode());
115 result = prime * result + ((name == null) ? 0 : name.hashCode());
116 result = prime * result + ((path == null) ? 0 : path.hashCode());
117 result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
118 result = prime * result + ((units == null) ? 0 : units.hashCode());
123 public boolean equals(final Object obj) {
130 if (getClass() != obj.getClass()) {
133 AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
134 if (description == null) {
135 if (other.description != null) {
138 } else if (!description.equals(other.description)) {
142 if (other.name != null) {
145 } else if (!name.equals(other.name)) {
149 if (other.path != null) {
152 } else if (!path.equals(other.path)) {
155 if (rangeStatements == null) {
156 if (other.rangeStatements != null) {
159 } else if (!rangeStatements.equals(other.rangeStatements)) {
163 if (other.units != null) {
166 } else if (!units.equals(other.units)) {
173 public String toString() {
174 StringBuilder builder = new StringBuilder();
175 builder.append("AbstractInteger [name=");
176 builder.append(name);
177 builder.append(", path=");
178 builder.append(path);
179 builder.append(", description=");
180 builder.append(description);
181 builder.append(", reference=");
182 builder.append(REFERENCE);
183 builder.append(", units=");
184 builder.append(units);
185 builder.append(", rangeStatements=");
186 builder.append(rangeStatements);
188 return builder.toString();