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