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.controller.yang.model.util;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.SchemaPath;
16 import org.opendaylight.controller.yang.model.api.Status;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
19 import org.opendaylight.controller.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 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 SchemaPath path, final QName name,
53 final String description, final Number minRange,
54 final Number maxRange, final String units) {
56 this.description = description;
59 this.rangeStatements = new ArrayList<RangeConstraint>();
60 final String rangeDescription = "Integer values between " + minRange
61 + " and " + maxRange + ", inclusively.";
62 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
63 maxRange, rangeDescription,
64 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
70 * @param rangeStatements
73 public AbstractSignedInteger(final SchemaPath path, final QName name,
74 final String description,
75 final List<RangeConstraint> rangeStatements, final String units) {
77 this.description = description;
80 this.rangeStatements = rangeStatements;
84 public String getUnits() {
89 public QName getQName() {
94 public SchemaPath getPath() {
99 public String getDescription() {
104 public String getReference() {
109 public Status getStatus() {
110 return Status.CURRENT;
114 public List<RangeConstraint> getRangeStatements() {
115 return rangeStatements;
119 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
120 return Collections.emptyList();
124 public int hashCode() {
125 final int prime = 31;
127 result = prime * result
128 + ((description == null) ? 0 : description.hashCode());
129 result = prime * result + ((name == null) ? 0 : name.hashCode());
130 result = prime * result + ((path == null) ? 0 : path.hashCode());
131 result = prime * result
132 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
133 result = prime * result
134 + ((reference == null) ? 0 : reference.hashCode());
135 result = prime * result + ((units == null) ? 0 : units.hashCode());
140 public boolean equals(Object obj) {
147 if (getClass() != obj.getClass()) {
150 AbstractSignedInteger other = (AbstractSignedInteger) obj;
151 if (description == null) {
152 if (other.description != null) {
155 } else if (!description.equals(other.description)) {
159 if (other.name != null) {
162 } else if (!name.equals(other.name)) {
166 if (other.path != null) {
169 } else if (!path.equals(other.path)) {
172 if (rangeStatements == null) {
173 if (other.rangeStatements != null) {
176 } else if (!rangeStatements.equals(other.rangeStatements)) {
179 if (reference == null) {
180 if (other.reference != null) {
183 } else if (!reference.equals(other.reference)) {
187 if (other.units != null) {
190 } else if (!units.equals(other.units)) {
197 public String toString() {
198 StringBuilder builder = new StringBuilder();
199 builder.append("AbstractInteger [name=");
200 builder.append(name);
201 builder.append(", path=");
202 builder.append(path);
203 builder.append(", description=");
204 builder.append(description);
205 builder.append(", reference=");
206 builder.append(reference);
207 builder.append(", units=");
208 builder.append(units);
209 builder.append(", rangeStatements=");
210 builder.append(rangeStatements);
212 return builder.toString();