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,
36 * @deprecated Used only by deprecated {@link Uint8} and friends.
39 abstract class AbstractUnsignedInteger implements UnsignedIntegerTypeDefinition {
40 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
41 private static final Optional<String> OPT_REF = Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4");
42 private static final long MIN_VALUE = 0;
43 private final QName name;
44 private final SchemaPath path;
45 private final String description;
46 private final String units;
47 private final List<RangeConstraint> rangeStatements;
50 * Construct Unsigned Integer
52 * @param name Name of type
53 * @param description Description of type
54 * @param maxRange Maximum value
57 public AbstractUnsignedInteger(final QName name, final String description, final Number maxRange, final String units) {
59 this.path = SchemaPath.create(true, name);
60 this.description = description;
62 final String rangeDescription = "Integer values between " + MIN_VALUE + " and " + maxRange + ", inclusively.";
63 this.rangeStatements = Collections.singletonList(BaseConstraints.newRangeConstraint(MIN_VALUE, maxRange,
64 Optional.of(rangeDescription), OPT_REF));
68 public UnsignedIntegerTypeDefinition getBaseType() {
73 public String getUnits() {
78 public QName getQName() {
83 public SchemaPath getPath() {
88 public String getDescription() {
93 public String getReference() {
98 public Status getStatus() {
99 return Status.CURRENT;
103 public List<RangeConstraint> getRangeConstraints() {
104 return rangeStatements;
108 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
109 return Collections.emptyList();
113 public int hashCode() {
114 final int prime = 31;
116 result = prime * result + Objects.hashCode(description);
117 result = prime * result + Objects.hashCode(name);
118 result = prime * result + Objects.hashCode(path);
119 result = prime * result + Objects.hashCode(rangeStatements);
120 result = prime * result + Objects.hashCode(units);
125 public boolean equals(final Object obj) {
132 if (getClass() != obj.getClass()) {
135 AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
136 if (!Objects.equals(description, other.description)) {
139 if (!Objects.equals(name, other.name)) {
142 if (!Objects.equals(path, other.path)) {
145 if (!Objects.equals(rangeStatements, other.rangeStatements)) {
148 if (!Objects.equals(units, other.units)) {
155 public String toString() {
156 StringBuilder builder = new StringBuilder();
157 builder.append("AbstractInteger [name=");
158 builder.append(name);
159 builder.append(", path=");
160 builder.append(path);
161 builder.append(", description=");
162 builder.append(description);
163 builder.append(", reference=");
164 builder.append(REFERENCE);
165 builder.append(", units=");
166 builder.append(units);
167 builder.append(", rangeStatements=");
168 builder.append(rangeStatements);
170 return builder.toString();