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