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 com.google.common.base.Optional;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
19 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
22 * The Abstract Integer class defines implementation of IntegerTypeDefinition
23 * interface which represents UNSIGNED Integer values defined in Yang language. <br>
24 * The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
25 * They represent unsigned integers of different sizes:
28 * <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
29 * <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
30 * <li>uint32 - represents integer values between 0 and 4294967295, inclusively.
32 * <li>uint64 - represents integer values between 0 and 18446744073709551615,
37 abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition {
38 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
39 private static final Optional<String> OPT_REF = Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4");
40 private static final long MIN_VALUE = 0;
41 private final QName name;
42 private final SchemaPath path;
43 private final String description;
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(true, name);
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,
62 Optional.of(rangeDescription), OPT_REF));
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 + Objects.hashCode(description);
115 result = prime * result + Objects.hashCode(name);
116 result = prime * result + Objects.hashCode(path);
117 result = prime * result + Objects.hashCode(rangeStatements);
118 result = prime * result + Objects.hashCode(units);
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();