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