013d80d79911c127ef4f3823a2fc996bf70c044f
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / AbstractUnsignedInteger.java
1 /**
2  *
3  */
4 package org.opendaylight.controller.yang.model.util;
5
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.List;
9
10 import org.opendaylight.controller.yang.common.QName;
11 import org.opendaylight.controller.yang.model.api.SchemaPath;
12 import org.opendaylight.controller.yang.model.api.Status;
13 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.controller.yang.model.api.type.RangeConstraint;
15 import org.opendaylight.controller.yang.model.api.type.UnsignedIntegerTypeDefinition;
16
17 /**
18  * The Abstract Integer class defines implementation of IntegerTypeDefinition
19  * interface which represents UNSIGNED Integer values defined in Yang language. <br>
20  * The integer built-in types in Yang are uint8, uint16, uint32, and uint64.
21  * They represent unsigned integers of different sizes:
22  *
23  * <ul>
24  * <li>uint8 - represents integer values between 0 and 255, inclusively.</li>
25  * <li>uint16 - represents integer values between 0 and 65535, inclusively.</li>
26  * <li>uint32 - represents integer values between 0 and 4294967295, inclusively.
27  * </li>
28  * <li>uint64 - represents integer values between 0 and 18446744073709551615,
29  * inclusively.</li>
30  * </ul>
31  *
32  */
33 public abstract class AbstractUnsignedInteger implements
34         UnsignedIntegerTypeDefinition {
35     private final QName name;
36     private final SchemaPath path;
37     private final String description;
38     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.2";
39
40     private final String units;
41     private final List<RangeConstraint> rangeStatements;
42
43     protected AbstractUnsignedInteger(final QName name,
44             final String description, final Number minRange,
45             final Number maxRange, final String units) {
46         this.name = name;
47         this.description = description;
48         this.path = BaseTypes.schemaPath(name);
49         this.units = units;
50         this.rangeStatements = new ArrayList<RangeConstraint>();
51         final String rangeDescription = "Integer values between " + minRange
52                 + " and " + maxRange + ", inclusively.";
53         this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
54                 maxRange, rangeDescription,
55                 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
56     }
57
58     /**
59      *
60      * @param actualPath
61      * @param namespace
62      * @param revision
63      * @param name
64      * @param description
65      * @param minRange
66      * @param maxRange
67      * @param units
68      */
69     public AbstractUnsignedInteger(final SchemaPath path, final QName name,
70             final String description, final Number minRange,
71             final Number maxRange, final String units) {
72         this.name = name;
73         this.description = description;
74         this.path = path;
75         this.units = units;
76         this.rangeStatements = new ArrayList<RangeConstraint>();
77         final String rangeDescription = "Integer values between " + minRange
78                 + " and " + maxRange + ", inclusively.";
79         this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
80                 maxRange, rangeDescription,
81                 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
82     }
83
84     /**
85      * @param name
86      * @param description
87      * @param rangeStatements
88      * @param units
89      */
90     public AbstractUnsignedInteger(final SchemaPath path, final QName name,
91             final String description,
92             final List<RangeConstraint> rangeStatements, final String units) {
93         this.name = name;
94         this.description = description;
95         this.path = path;
96         this.units = units;
97         this.rangeStatements = rangeStatements;
98     }
99
100     @Override
101     public String getUnits() {
102         return units;
103     }
104
105     @Override
106     public QName getQName() {
107         return name;
108     }
109
110     @Override
111     public SchemaPath getPath() {
112         return path;
113     }
114
115     @Override
116     public String getDescription() {
117         return description;
118     }
119
120     @Override
121     public String getReference() {
122         return reference;
123     }
124
125     @Override
126     public Status getStatus() {
127         return Status.CURRENT;
128     }
129
130     @Override
131     public List<RangeConstraint> getRangeStatements() {
132         return rangeStatements;
133     }
134
135     @Override
136     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
137         return Collections.emptyList();
138     }
139
140     @Override
141     public int hashCode() {
142         final int prime = 31;
143         int result = 1;
144         result = prime * result
145                 + ((description == null) ? 0 : description.hashCode());
146         result = prime * result + ((name == null) ? 0 : name.hashCode());
147         result = prime * result + ((path == null) ? 0 : path.hashCode());
148         result = prime * result
149                 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
150         result = prime * result
151                 + ((reference == null) ? 0 : reference.hashCode());
152         result = prime * result + ((units == null) ? 0 : units.hashCode());
153         return result;
154     }
155
156     @Override
157     public boolean equals(Object obj) {
158         if (this == obj) {
159             return true;
160         }
161         if (obj == null) {
162             return false;
163         }
164         if (getClass() != obj.getClass()) {
165             return false;
166         }
167         AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
168         if (description == null) {
169             if (other.description != null) {
170                 return false;
171             }
172         } else if (!description.equals(other.description)) {
173             return false;
174         }
175         if (name == null) {
176             if (other.name != null) {
177                 return false;
178             }
179         } else if (!name.equals(other.name)) {
180             return false;
181         }
182         if (path == null) {
183             if (other.path != null) {
184                 return false;
185             }
186         } else if (!path.equals(other.path)) {
187             return false;
188         }
189         if (rangeStatements == null) {
190             if (other.rangeStatements != null) {
191                 return false;
192             }
193         } else if (!rangeStatements.equals(other.rangeStatements)) {
194             return false;
195         }
196         if (reference == null) {
197             if (other.reference != null) {
198                 return false;
199             }
200         } else if (!reference.equals(other.reference)) {
201             return false;
202         }
203         if (units == null) {
204             if (other.units != null) {
205                 return false;
206             }
207         } else if (!units.equals(other.units)) {
208             return false;
209         }
210         return true;
211     }
212
213     @Override
214     public String toString() {
215         StringBuilder builder = new StringBuilder();
216         builder.append("AbstractInteger [name=");
217         builder.append(name);
218         builder.append(", path=");
219         builder.append(path);
220         builder.append(", description=");
221         builder.append(description);
222         builder.append(", reference=");
223         builder.append(reference);
224         builder.append(", units=");
225         builder.append(units);
226         builder.append(", rangeStatements=");
227         builder.append(rangeStatements);
228         builder.append("]");
229         return builder.toString();
230     }
231 }