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