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