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;
56 public AbstractSignedInteger(final List<String> actualPath,
57 final URI namespace, final Date revision, final QName name,
58 final String description, final Number minRange,
59 final Number maxRange, final String units) {
61 this.description = description;
62 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
64 this.rangeStatements = new ArrayList<RangeConstraint>();
65 final String rangeDescription = "Integer values between " + minRange
66 + " and " + maxRange + ", inclusively.";
67 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
68 maxRange, rangeDescription,
69 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
75 * @param rangeStatements
78 public AbstractSignedInteger(final List<String> actualPath,
79 final URI namespace, final Date revision, final QName name,
80 final String description,
81 final List<RangeConstraint> rangeStatements, final String units) {
83 this.description = description;
84 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
86 this.rangeStatements = rangeStatements;
90 public String getUnits() {
95 public QName getQName() {
100 public SchemaPath getPath() {
105 public String getDescription() {
110 public String getReference() {
115 public Status getStatus() {
116 return Status.CURRENT;
120 public List<RangeConstraint> getRangeStatements() {
121 return rangeStatements;
125 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
126 return Collections.emptyList();
130 public int hashCode() {
131 final int prime = 31;
133 result = prime * result
134 + ((description == null) ? 0 : description.hashCode());
135 result = prime * result + ((name == null) ? 0 : name.hashCode());
136 result = prime * result + ((path == null) ? 0 : path.hashCode());
137 result = prime * result
138 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
139 result = prime * result
140 + ((reference == null) ? 0 : reference.hashCode());
141 result = prime * result + ((units == null) ? 0 : units.hashCode());
146 public boolean equals(Object obj) {
153 if (getClass() != obj.getClass()) {
156 AbstractSignedInteger other = (AbstractSignedInteger) obj;
157 if (description == null) {
158 if (other.description != null) {
161 } else if (!description.equals(other.description)) {
165 if (other.name != null) {
168 } else if (!name.equals(other.name)) {
172 if (other.path != null) {
175 } else if (!path.equals(other.path)) {
178 if (rangeStatements == null) {
179 if (other.rangeStatements != null) {
182 } else if (!rangeStatements.equals(other.rangeStatements)) {
185 if (reference == null) {
186 if (other.reference != null) {
189 } else if (!reference.equals(other.reference)) {
193 if (other.units != null) {
196 } else if (!units.equals(other.units)) {
203 public String toString() {
204 StringBuilder builder = new StringBuilder();
205 builder.append("AbstractInteger [name=");
206 builder.append(name);
207 builder.append(", path=");
208 builder.append(path);
209 builder.append(", description=");
210 builder.append(description);
211 builder.append(", reference=");
212 builder.append(reference);
213 builder.append(", units=");
214 builder.append(units);
215 builder.append(", rangeStatements=");
216 builder.append(rangeStatements);
218 return builder.toString();