86c543e641d72e6f9d017594493f4423c1d4f7d3
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / model / util / AbstractUnsignedInteger.java
1 /**
2  * 
3  */
4 package org.opendaylight.controller.model.util;
5
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.List;
9
10 import org.opendaylight.controller.model.api.type.RangeConstraint;
11 import org.opendaylight.controller.model.api.type.UnsignedIntegerTypeDefinition;
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
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. They
21  * 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,
27       inclusively.</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     /**
44      * @param name
45      * @param description
46      * @param minRange
47      * @param maxRange
48      * @param units
49      */
50     public AbstractUnsignedInteger(final QName name, final String description,
51             final Number minRange, final Number maxRange, final String units) {
52         this.name = name;
53         this.description = description;
54         this.path = BaseTypes.schemaPath(name);
55         this.units = units;
56         this.rangeStatements = new ArrayList<RangeConstraint>();
57         final String rangeDescription = "Integer values between " + minRange
58                 + " and " + maxRange + ", inclusively.";
59         this.rangeStatements.add(BaseConstraints.rangeConstraint(minRange,
60                 maxRange, rangeDescription, "https://tools.ietf.org/html/rfc6020#section-9.2.4"));
61     }
62
63     /**
64      * @param name
65      * @param description
66      * @param rangeStatements
67      * @param units
68      */
69     public AbstractUnsignedInteger(final QName name, final String description,
70             final List<RangeConstraint> rangeStatements, final String units) {
71         this.name = name;
72         this.description = description;
73         this.path = BaseTypes.schemaPath(name);
74         this.units = units;
75         this.rangeStatements = rangeStatements;
76     }
77     
78     @Override
79     public String getUnits() {
80         return units;
81     }
82
83     @Override
84     public QName getQName() {
85         return name;
86     }
87
88     @Override
89     public SchemaPath getPath() {
90         return path;
91     }
92
93     @Override
94     public String getDescription() {
95         return description;
96     }
97
98     @Override
99     public String getReference() {
100         return reference;
101     }
102
103     @Override
104     public Status getStatus() {
105         return Status.CURRENT;
106     }
107
108     @Override
109     public List<RangeConstraint> getRangeStatements() {
110         return rangeStatements;
111     }
112
113     @Override
114     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
115         return Collections.emptyList();
116     }
117
118     @Override
119     public int hashCode() {
120         final int prime = 31;
121         int result = 1;
122         result = prime * result
123                 + ((description == null) ? 0 : description.hashCode());
124         result = prime * result + ((name == null) ? 0 : name.hashCode());
125         result = prime * result + ((path == null) ? 0 : path.hashCode());
126         result = prime * result
127                 + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
128         result = prime * result
129                 + ((reference == null) ? 0 : reference.hashCode());
130         result = prime * result + ((units == null) ? 0 : units.hashCode());
131         return result;
132     }
133
134     @Override
135     public boolean equals(Object obj) {
136         if (this == obj) {
137             return true;
138         }
139         if (obj == null) {
140             return false;
141         }
142         if (getClass() != obj.getClass()) {
143             return false;
144         }
145         AbstractUnsignedInteger other = (AbstractUnsignedInteger) obj;
146         if (description == null) {
147             if (other.description != null) {
148                 return false;
149             }
150         } else if (!description.equals(other.description)) {
151             return false;
152         }
153         if (name == null) {
154             if (other.name != null) {
155                 return false;
156             }
157         } else if (!name.equals(other.name)) {
158             return false;
159         }
160         if (path == null) {
161             if (other.path != null) {
162                 return false;
163             }
164         } else if (!path.equals(other.path)) {
165             return false;
166         }
167         if (rangeStatements == null) {
168             if (other.rangeStatements != null) {
169                 return false;
170             }
171         } else if (!rangeStatements.equals(other.rangeStatements)) {
172             return false;
173         }
174         if (reference == null) {
175             if (other.reference != null) {
176                 return false;
177             }
178         } else if (!reference.equals(other.reference)) {
179             return false;
180         }
181         if (units == null) {
182             if (other.units != null) {
183                 return false;
184             }
185         } else if (!units.equals(other.units)) {
186             return false;
187         }
188         return true;
189     }
190
191     @Override
192     public String toString() {
193         StringBuilder builder = new StringBuilder();
194         builder.append("AbstractInteger [name=");
195         builder.append(name);
196         builder.append(", path=");
197         builder.append(path);
198         builder.append(", description=");
199         builder.append(description);
200         builder.append(", reference=");
201         builder.append(reference);
202         builder.append(", units=");
203         builder.append(units);
204         builder.append(", rangeStatements=");
205         builder.append(rangeStatements);
206         builder.append("]");
207         return builder.toString();
208     }
209 }