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