Refactored SchemaPath for yang java types. Fixed SchemaPath for augmented nodes types.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / AbstractSignedInteger.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.yang.model.util;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
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;
20
21 /**
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:
26  *
27  * <ul>
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,
31  * inclusively.</li>
32  * <li>int64 - represents integer values between -9223372036854775808 and
33  * 9223372036854775807, inclusively.</li>
34  * </ul>
35  *
36  */
37 public abstract class AbstractSignedInteger implements IntegerTypeDefinition {
38
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";
43
44     private final String units;
45     private final List<RangeConstraint> rangeStatements;
46
47     protected AbstractSignedInteger(final QName name, final String description,
48             final Number minRange, final Number maxRange, final String units) {
49         this.name = name;
50         this.description = description;
51         this.path = BaseTypes.schemaPath(name);
52         this.units = units;
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"));
59     }
60
61     /**
62      * @param name
63      * @param description
64      * @param minRange
65      * @param maxRange
66      * @param units
67      */
68     public AbstractSignedInteger(final SchemaPath path, final QName name,
69             final String description, final Number minRange,
70             final Number maxRange, final String units) {
71         this.name = name;
72         this.description = description;
73         this.path = path;
74         this.units = units;
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"));
81     }
82
83     /**
84      * @param name
85      * @param description
86      * @param rangeStatements
87      * @param units
88      */
89     public AbstractSignedInteger(final SchemaPath path, final QName name,
90             final String description,
91             final List<RangeConstraint> rangeStatements, final String units) {
92         this.name = name;
93         this.description = description;
94         this.path = path;
95         this.units = units;
96         this.rangeStatements = rangeStatements;
97     }
98
99     @Override
100     public String getUnits() {
101         return units;
102     }
103
104     @Override
105     public QName getQName() {
106         return name;
107     }
108
109     @Override
110     public SchemaPath getPath() {
111         return path;
112     }
113
114     @Override
115     public String getDescription() {
116         return description;
117     }
118
119     @Override
120     public String getReference() {
121         return reference;
122     }
123
124     @Override
125     public Status getStatus() {
126         return Status.CURRENT;
127     }
128
129     @Override
130     public List<RangeConstraint> getRangeStatements() {
131         return rangeStatements;
132     }
133
134     @Override
135     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
136         return Collections.emptyList();
137     }
138
139     @Override
140     public int hashCode() {
141         final int prime = 31;
142         int result = 1;
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());
152         return result;
153     }
154
155     @Override
156     public boolean equals(Object obj) {
157         if (this == obj) {
158             return true;
159         }
160         if (obj == null) {
161             return false;
162         }
163         if (getClass() != obj.getClass()) {
164             return false;
165         }
166         AbstractSignedInteger other = (AbstractSignedInteger) obj;
167         if (description == null) {
168             if (other.description != null) {
169                 return false;
170             }
171         } else if (!description.equals(other.description)) {
172             return false;
173         }
174         if (name == null) {
175             if (other.name != null) {
176                 return false;
177             }
178         } else if (!name.equals(other.name)) {
179             return false;
180         }
181         if (path == null) {
182             if (other.path != null) {
183                 return false;
184             }
185         } else if (!path.equals(other.path)) {
186             return false;
187         }
188         if (rangeStatements == null) {
189             if (other.rangeStatements != null) {
190                 return false;
191             }
192         } else if (!rangeStatements.equals(other.rangeStatements)) {
193             return false;
194         }
195         if (reference == null) {
196             if (other.reference != null) {
197                 return false;
198             }
199         } else if (!reference.equals(other.reference)) {
200             return false;
201         }
202         if (units == null) {
203             if (other.units != null) {
204                 return false;
205             }
206         } else if (!units.equals(other.units)) {
207             return false;
208         }
209         return true;
210     }
211
212     @Override
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);
227         builder.append("]");
228         return builder.toString();
229     }
230 }