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