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