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