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 {
39 private final QName name;
40 private final SchemaPath path;
41 private final String description;
42 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
44 private final String units;
45 private final List<RangeConstraint> rangeStatements;
47 protected AbstractSignedInteger(final QName name, final String description,
48 final Number minRange, final Number maxRange, final String units) {
50 this.description = description;
51 this.path = BaseTypes.schemaPath(name);
53 this.rangeStatements = new ArrayList<RangeConstraint>();
54 final String rangeDescription = "Integer values between " + minRange
55 + " and " + maxRange + ", inclusively.";
56 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
57 maxRange, rangeDescription,
58 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
68 public AbstractSignedInteger(final SchemaPath path, final QName name,
69 final String description, final Number minRange,
70 final Number maxRange, final String units) {
72 this.description = description;
75 this.rangeStatements = new ArrayList<RangeConstraint>();
76 final String rangeDescription = "Integer values between " + minRange
77 + " and " + maxRange + ", inclusively.";
78 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
79 maxRange, rangeDescription,
80 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
86 * @param rangeStatements
89 public AbstractSignedInteger(final SchemaPath path, final QName name,
90 final String description,
91 final List<RangeConstraint> rangeStatements, final String units) {
93 this.description = description;
96 this.rangeStatements = rangeStatements;
100 public String getUnits() {
105 public QName getQName() {
110 public SchemaPath getPath() {
115 public String getDescription() {
120 public String getReference() {
125 public Status getStatus() {
126 return Status.CURRENT;
130 public List<RangeConstraint> getRangeStatements() {
131 return rangeStatements;
135 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
136 return Collections.emptyList();
140 public int hashCode() {
141 final int prime = 31;
143 result = prime * result
144 + ((description == null) ? 0 : description.hashCode());
145 result = prime * result + ((name == null) ? 0 : name.hashCode());
146 result = prime * result + ((path == null) ? 0 : path.hashCode());
147 result = prime * result
148 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
149 result = prime * result
150 + ((reference == null) ? 0 : reference.hashCode());
151 result = prime * result + ((units == null) ? 0 : units.hashCode());
156 public boolean equals(Object obj) {
163 if (getClass() != obj.getClass()) {
166 AbstractSignedInteger other = (AbstractSignedInteger) obj;
167 if (description == null) {
168 if (other.description != null) {
171 } else if (!description.equals(other.description)) {
175 if (other.name != null) {
178 } else if (!name.equals(other.name)) {
182 if (other.path != null) {
185 } else if (!path.equals(other.path)) {
188 if (rangeStatements == null) {
189 if (other.rangeStatements != null) {
192 } else if (!rangeStatements.equals(other.rangeStatements)) {
195 if (reference == null) {
196 if (other.reference != null) {
199 } else if (!reference.equals(other.reference)) {
203 if (other.units != null) {
206 } else if (!units.equals(other.units)) {
213 public String toString() {
214 StringBuilder builder = new StringBuilder();
215 builder.append("AbstractInteger [name=");
216 builder.append(name);
217 builder.append(", path=");
218 builder.append(path);
219 builder.append(", description=");
220 builder.append(description);
221 builder.append(", reference=");
222 builder.append(reference);
223 builder.append(", units=");
224 builder.append(units);
225 builder.append(", rangeStatements=");
226 builder.append(rangeStatements);
228 return builder.toString();