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 java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
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.IntegerTypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
22 * The Abstract Integer class defines implementation of IntegerTypeDefinition
23 * interface which represents SIGNED Integer values defined in Yang language. <br>
24 * The integer built-in types in Yang are int8, int16, int32, int64. They
25 * represent signed integers of different sizes:
28 * <li>int8 - represents integer values between -128 and 127, inclusively.</li>
29 * <li>int16 - represents integer values between -32768 and 32767, inclusively.</li>
30 * <li>int32 - represents integer values between -2147483648 and 2147483647,
32 * <li>int64 - represents integer values between -9223372036854775808 and
33 * 9223372036854775807, inclusively.</li>
37 public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
38 private final QName name;
39 private final SchemaPath path;
40 private final String description;
41 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2";
42 private final String units;
43 private final List<RangeConstraint> rangeStatements;
52 public AbstractSignedInteger(final QName name, final String description, final Number minRange,
53 final Number maxRange, final String units) {
55 this.path = new SchemaPath(Collections.singletonList(name), true);
56 this.description = description;
58 this.rangeStatements = new ArrayList<RangeConstraint>();
59 final String rangeDescription = "Integer values between " + minRange + " and " + maxRange + ", inclusively.";
60 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange, maxRange, rangeDescription,
61 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
65 public String getUnits() {
70 public QName getQName() {
75 public SchemaPath getPath() {
80 public String getDescription() {
85 public String getReference() {
90 public Status getStatus() {
91 return Status.CURRENT;
95 public List<RangeConstraint> getRangeConstraints() {
96 return rangeStatements;
100 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
101 return Collections.emptyList();
105 public int hashCode() {
106 final int prime = 31;
108 result = prime * result + ((description == null) ? 0 : description.hashCode());
109 result = prime * result + ((name == null) ? 0 : name.hashCode());
110 result = prime * result + ((path == null) ? 0 : path.hashCode());
111 result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
112 result = prime * result + ((units == null) ? 0 : units.hashCode());
117 public boolean equals(Object obj) {
124 if (getClass() != obj.getClass()) {
127 AbstractSignedInteger other = (AbstractSignedInteger) obj;
128 if (description == null) {
129 if (other.description != null) {
132 } else if (!description.equals(other.description)) {
136 if (other.name != null) {
139 } else if (!name.equals(other.name)) {
143 if (other.path != null) {
146 } else if (!path.equals(other.path)) {
149 if (rangeStatements == null) {
150 if (other.rangeStatements != null) {
153 } else if (!rangeStatements.equals(other.rangeStatements)) {
157 if (other.units != null) {
160 } else if (!units.equals(other.units)) {
167 public String toString() {
168 StringBuilder builder = new StringBuilder();
169 builder.append("AbstractInteger [name=");
170 builder.append(name);
171 builder.append(", path=");
172 builder.append(path);
173 builder.append(", description=");
174 builder.append(description);
175 builder.append(", reference=");
176 builder.append(REFERENCE);
177 builder.append(", units=");
178 builder.append(units);
179 builder.append(", rangeStatements=");
180 builder.append(rangeStatements);
182 return builder.toString();