2 * Copyright (c) 2013 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;
12 import java.util.Collections;
13 import java.util.List;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
23 * The Abstract Integer class defines implementation of IntegerTypeDefinition
24 * interface which represents SIGNED Integer values defined in Yang language. <br>
25 * The integer built-in types in Yang are int8, int16, int32, int64. They
26 * represent signed integers of different sizes:
29 * <li>int8 - represents integer values between -128 and 127, inclusively.</li>
30 * <li>int16 - represents integer values between -32768 and 32767, inclusively.</li>
31 * <li>int32 - represents integer values between -2147483648 and 2147483647,
33 * <li>int64 - represents integer values between -9223372036854775808 and
34 * 9223372036854775807, inclusively.</li>
38 abstract class AbstractSignedInteger implements IntegerTypeDefinition {
39 private final QName name;
40 private final SchemaPath path;
41 private final String description;
42 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
43 private final String units;
44 private final List<RangeConstraint> rangeStatements;
47 * Construct SignedInteger
49 * @param name Name of type
50 * @param description Description of type
51 * @param minRange Minimal range
52 * @param maxRange Maximum range
55 protected AbstractSignedInteger(final QName name, final String description, final Number minRange,
56 final Number maxRange, final String units) {
58 this.path = SchemaPath.create(true, name);
59 this.description = description;
61 final String rangeDescription = "Integer values between " + minRange + " and " + maxRange + ", inclusively.";
62 this.rangeStatements = Collections.singletonList(BaseConstraints.newRangeConstraint(minRange, maxRange, Optional.of(rangeDescription),
63 Optional.of("https://tools.ietf.org/html/rfc6020#section-9.2.4")));
67 public IntegerTypeDefinition getBaseType() {
72 public String getUnits() {
77 public QName getQName() {
82 public SchemaPath getPath() {
87 public String getDescription() {
92 public String getReference() {
97 public Status getStatus() {
98 return Status.CURRENT;
102 public List<RangeConstraint> getRangeConstraints() {
103 return rangeStatements;
107 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
108 return Collections.emptyList();
112 public int hashCode() {
113 final int prime = 31;
115 result = prime * result + ((description == null) ? 0 : description.hashCode());
116 result = prime * result + ((name == null) ? 0 : name.hashCode());
117 result = prime * result + ((path == null) ? 0 : path.hashCode());
118 result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
119 result = prime * result + ((units == null) ? 0 : units.hashCode());
124 public boolean equals(final Object obj) {
131 if (getClass() != obj.getClass()) {
134 AbstractSignedInteger other = (AbstractSignedInteger) obj;
135 if (description == null) {
136 if (other.description != null) {
139 } else if (!description.equals(other.description)) {
143 if (other.name != null) {
146 } else if (!name.equals(other.name)) {
150 if (other.path != null) {
153 } else if (!path.equals(other.path)) {
156 if (rangeStatements == null) {
157 if (other.rangeStatements != null) {
160 } else if (!rangeStatements.equals(other.rangeStatements)) {
164 if (other.units != null) {
167 } else if (!units.equals(other.units)) {
174 public String toString() {
175 StringBuilder builder = new StringBuilder();
176 builder.append("AbstractInteger [name=");
177 builder.append(name);
178 builder.append(", path=");
179 builder.append(path);
180 builder.append(", description=");
181 builder.append(description);
182 builder.append(", reference=");
183 builder.append(REFERENCE);
184 builder.append(", units=");
185 builder.append(units);
186 builder.append(", rangeStatements=");
187 builder.append(rangeStatements);
189 return builder.toString();