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