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;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
16 import org.opendaylight.controller.yang.common.QName;
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
18 import org.opendaylight.controller.yang.model.api.Status;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.model.api.type.IntegerTypeDefinition;
21 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
24 * The Abstract Integer class defines implementation of IntegerTypeDefinition
25 * interface which represents SIGNED Integer values defined in Yang language. <br>
26 * The integer built-in types in Yang are int8, int16, int32, int64. They
27 * represent signed integers of different sizes:
30 * <li>int8 - represents integer values between -128 and 127, inclusively.</li>
31 * <li>int16 - represents integer values between -32768 and 32767, inclusively.</li>
32 * <li>int32 - represents integer values between -2147483648 and 2147483647,
34 * <li>int64 - represents integer values between -9223372036854775808 and
35 * 9223372036854775807, inclusively.</li>
39 public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
41 private final QName name;
42 private final SchemaPath path;
43 private final String description;
44 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
46 private final String units;
47 private final List<RangeConstraint> rangeStatements;
49 protected AbstractSignedInteger(final QName name, final String description,
50 final Number minRange, final Number maxRange, final String units) {
52 this.description = description;
53 this.path = BaseTypes.schemaPath(name);
55 this.rangeStatements = new ArrayList<RangeConstraint>();
56 final String rangeDescription = "Integer values between " + minRange
57 + " and " + maxRange + ", inclusively.";
58 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
59 maxRange, rangeDescription,
60 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
70 public AbstractSignedInteger(final List<String> actualPath,
71 final URI namespace, final Date revision, final QName name,
72 final String description, final Number minRange,
73 final Number maxRange, final String units) {
75 this.description = description;
76 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
78 this.rangeStatements = new ArrayList<RangeConstraint>();
79 final String rangeDescription = "Integer values between " + minRange
80 + " and " + maxRange + ", inclusively.";
81 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
82 maxRange, rangeDescription,
83 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
89 * @param rangeStatements
92 public AbstractSignedInteger(final List<String> actualPath,
93 final URI namespace, final Date revision, final QName name,
94 final String description,
95 final List<RangeConstraint> rangeStatements, final String units) {
97 this.description = description;
98 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
100 this.rangeStatements = rangeStatements;
104 public String getUnits() {
109 public QName getQName() {
114 public SchemaPath getPath() {
119 public String getDescription() {
124 public String getReference() {
129 public Status getStatus() {
130 return Status.CURRENT;
134 public List<RangeConstraint> getRangeStatements() {
135 return rangeStatements;
139 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
140 return Collections.emptyList();
144 public int hashCode() {
145 final int prime = 31;
147 result = prime * result
148 + ((description == null) ? 0 : description.hashCode());
149 result = prime * result + ((name == null) ? 0 : name.hashCode());
150 result = prime * result + ((path == null) ? 0 : path.hashCode());
151 result = prime * result
152 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
153 result = prime * result
154 + ((reference == null) ? 0 : reference.hashCode());
155 result = prime * result + ((units == null) ? 0 : units.hashCode());
160 public boolean equals(Object obj) {
167 if (getClass() != obj.getClass()) {
170 AbstractSignedInteger other = (AbstractSignedInteger) obj;
171 if (description == null) {
172 if (other.description != null) {
175 } else if (!description.equals(other.description)) {
179 if (other.name != null) {
182 } else if (!name.equals(other.name)) {
186 if (other.path != null) {
189 } else if (!path.equals(other.path)) {
192 if (rangeStatements == null) {
193 if (other.rangeStatements != null) {
196 } else if (!rangeStatements.equals(other.rangeStatements)) {
199 if (reference == null) {
200 if (other.reference != null) {
203 } else if (!reference.equals(other.reference)) {
207 if (other.units != null) {
210 } else if (!units.equals(other.units)) {
217 public String toString() {
218 StringBuilder builder = new StringBuilder();
219 builder.append("AbstractInteger [name=");
220 builder.append(name);
221 builder.append(", path=");
222 builder.append(path);
223 builder.append(", description=");
224 builder.append(description);
225 builder.append(", reference=");
226 builder.append(reference);
227 builder.append(", units=");
228 builder.append(units);
229 builder.append(", rangeStatements=");
230 builder.append(rangeStatements);
232 return builder.toString();