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 (!Objects.equals(description, other.description)) {
137 if (!Objects.equals(name, other.name)) {
140 if (!Objects.equals(path, other.path)) {
143 if (!Objects.equals(rangeStatements, other.rangeStatements)) {
146 if (!Objects.equals(units, other.units)) {
153 public String toString() {
154 StringBuilder builder = new StringBuilder();
155 builder.append("AbstractInteger [name=");
156 builder.append(name);
157 builder.append(", path=");
158 builder.append(path);
159 builder.append(", description=");
160 builder.append(description);
161 builder.append(", reference=");
162 builder.append(REFERENCE);
163 builder.append(", units=");
164 builder.append(units);
165 builder.append(", rangeStatements=");
166 builder.append(rangeStatements);
168 return builder.toString();