Merge "Added support for annotations in generated APIs."
[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     /**
46      * @param name
47      * @param description
48      * @param minRange
49      * @param maxRange
50      * @param units
51      */
52     public AbstractUnsignedInteger(final List<String> actualPath,
53             final URI namespace, final Date revision, final QName name,
54             final String description, final Number minRange,
55             final Number maxRange, final String units) {
56         this.name = name;
57         this.description = description;
58         this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
59         this.units = units;
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,
65                 "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
66     }
67
68     /**
69      * @param name
70      * @param description
71      * @param rangeStatements
72      * @param units
73      */
74     public AbstractUnsignedInteger(final List<String> actualPath,
75             final URI namespace, final Date revision, final QName name,
76             final String description,
77             final List<RangeConstraint> rangeStatements, final String units) {
78         this.name = name;
79         this.description = description;
80         this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
81         this.units = units;
82         this.rangeStatements = rangeStatements;
83     }
84
85     @Override
86     public String getUnits() {
87         return units;
88     }
89
90     @Override
91     public QName getQName() {
92         return name;
93     }
94
95     @Override
96     public SchemaPath getPath() {
97         return path;
98     }
99
100     @Override
101     public String getDescription() {
102         return description;
103     }
104
105     @Override
106     public String getReference() {
107         return reference;
108     }
109
110     @Override
111     public Status getStatus() {
112         return Status.CURRENT;
113     }
114
115     @Override
116     public List<RangeConstraint> getRangeStatements() {
117         return rangeStatements;
118     }
119
120     @Override
121     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
122         return Collections.emptyList();
123     }
124
125     @Override
126     public int hashCode() {
127         final int prime = 31;
128         int result = 1;
129         result = prime * result
130                 + ((description == null) ? 0 : description.hashCode());
131         result = prime * result + ((name == null) ? 0 : name.hashCode());
132         result = prime * result + ((path == null) ? 0 : path.hashCode());
133         result = prime * result
134                 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
135         result = prime * result
136                 + ((reference == null) ? 0 : reference.hashCode());
137         result = prime * result + ((units == null) ? 0 : units.hashCode());
138         return result;
139     }
140
141     @Override
142     public boolean equals(Object obj) {
143         if (this == obj) {
144             return true;
145         }
146         if (obj == null) {
147             return false;
148         }
149         if (getClass() != obj.getClass()) {
150             return false;
151         }
152         AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
153         if (description == null) {
154             if (other.description != null) {
155                 return false;
156             }
157         } else if (!description.equals(other.description)) {
158             return false;
159         }
160         if (name == null) {
161             if (other.name != null) {
162                 return false;
163             }
164         } else if (!name.equals(other.name)) {
165             return false;
166         }
167         if (path == null) {
168             if (other.path != null) {
169                 return false;
170             }
171         } else if (!path.equals(other.path)) {
172             return false;
173         }
174         if (rangeStatements == null) {
175             if (other.rangeStatements != null) {
176                 return false;
177             }
178         } else if (!rangeStatements.equals(other.rangeStatements)) {
179             return false;
180         }
181         if (reference == null) {
182             if (other.reference != null) {
183                 return false;
184             }
185         } else if (!reference.equals(other.reference)) {
186             return false;
187         }
188         if (units == null) {
189             if (other.units != null) {
190                 return false;
191             }
192         } else if (!units.equals(other.units)) {
193             return false;
194         }
195         return true;
196     }
197
198     @Override
199     public String toString() {
200         StringBuilder builder = new StringBuilder();
201         builder.append("AbstractInteger [name=");
202         builder.append(name);
203         builder.append(", path=");
204         builder.append(path);
205         builder.append(", description=");
206         builder.append(description);
207         builder.append(", reference=");
208         builder.append(reference);
209         builder.append(", units=");
210         builder.append(units);
211         builder.append(", rangeStatements=");
212         builder.append(rangeStatements);
213         builder.append("]");
214         return builder.toString();
215     }
216 }