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;
54 public AbstractSignedInteger(final QName name, final String description,
55 final Number minRange, final Number maxRange, final String units) {
57 this.description = description;
58 this.path = BaseTypes.schemaPath(name);
60 this.rangeStatements = new ArrayList<RangeConstraint>();
61 final String rangeDescription = "Integer values between " + minRange
62 + " and " + maxRange + ", inclusively.";
63 this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
64 maxRange, rangeDescription, "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
70 * @param rangeStatements
73 public AbstractSignedInteger(final QName name, final String description,
74 final List<RangeConstraint> rangeStatements, final String units) {
76 this.description = description;
77 this.path = BaseTypes.schemaPath(name);
79 this.rangeStatements = rangeStatements;
83 public String getUnits() {
88 public QName getQName() {
93 public SchemaPath getPath() {
98 public String getDescription() {
103 public String getReference() {
108 public Status getStatus() {
109 return Status.CURRENT;
113 public List<RangeConstraint> getRangeStatements() {
114 return rangeStatements;
118 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
119 return Collections.emptyList();
123 public int hashCode() {
124 final int prime = 31;
126 result = prime * result
127 + ((description == null) ? 0 : description.hashCode());
128 result = prime * result + ((name == null) ? 0 : name.hashCode());
129 result = prime * result + ((path == null) ? 0 : path.hashCode());
130 result = prime * result
131 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
132 result = prime * result
133 + ((reference == null) ? 0 : reference.hashCode());
134 result = prime * result + ((units == null) ? 0 : units.hashCode());
139 public boolean equals(Object obj) {
146 if (getClass() != obj.getClass()) {
149 AbstractSignedInteger other = (AbstractSignedInteger) obj;
150 if (description == null) {
151 if (other.description != null) {
154 } else if (!description.equals(other.description)) {
158 if (other.name != null) {
161 } else if (!name.equals(other.name)) {
165 if (other.path != null) {
168 } else if (!path.equals(other.path)) {
171 if (rangeStatements == null) {
172 if (other.rangeStatements != null) {
175 } else if (!rangeStatements.equals(other.rangeStatements)) {
178 if (reference == null) {
179 if (other.reference != null) {
182 } else if (!reference.equals(other.reference)) {
186 if (other.units != null) {
189 } else if (!units.equals(other.units)) {
196 public String toString() {
197 StringBuilder builder = new StringBuilder();
198 builder.append("AbstractInteger [name=");
199 builder.append(name);
200 builder.append(", path=");
201 builder.append(path);
202 builder.append(", description=");
203 builder.append(description);
204 builder.append(", reference=");
205 builder.append(reference);
206 builder.append(", units=");
207 builder.append(units);
208 builder.append(", rangeStatements=");
209 builder.append(rangeStatements);
211 return builder.toString();