1 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
3 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
5 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
6 import com.google.common.base.Optional;
7 import java.util.Collections;
9 import org.opendaylight.yangtools.yang.common.QName;
10 import org.opendaylight.yangtools.yang.common.YangConstants;
11 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
12 import org.opendaylight.yangtools.yang.model.api.Status;
13 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
16 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
20 abstract class UnsignedIntegerEffectiveImplBase extends
21 EffectiveStatementBase<String, TypeStatement> implements UnsignedIntegerTypeDefinition {
23 private static final String REFERENCE_INT = "https://tools.ietf.org/html/rfc6020#section-9.2";
25 protected static final Number MIN_RANGE = 0;
26 protected QName qName;
27 private SchemaPath path;
28 private String units = "";
29 private final String description;
30 private List<RangeConstraint> rangeStatements;
32 protected UnsignedIntegerEffectiveImplBase(final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
33 final String localName, final Number maxRange, final String description) {
37 this.qName = QName.create(YangConstants.RFC6020_YANG_MODULE, localName);
38 path = Utils.getSchemaPath(ctx);
40 final String rangeDescription = "Integer values between " + MIN_RANGE + " and " + maxRange + ", inclusively.";
41 final RangeConstraint defaultRange = new RangeConstraintEffectiveImpl(MIN_RANGE, maxRange,
42 Optional.of(rangeDescription), Optional.of(RangeConstraintEffectiveImpl.DEFAULT_REFERENCE));
43 rangeStatements = Collections.singletonList(defaultRange);
45 this.description = description;
49 public List<RangeConstraint> getRangeConstraints() {
50 return rangeStatements;
54 public UnsignedIntegerTypeDefinition getBaseType() {
59 public String getUnits() {
64 public Object getDefaultValue() {
69 public QName getQName() {
74 public SchemaPath getPath() {
79 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
80 return Collections.emptyList();
84 public String getDescription() {
89 public String getReference() {
94 public Status getStatus() {
95 return Status.CURRENT;
99 public int hashCode() {
100 final int prime = 31;
102 result = prime * result + ((description == null) ? 0 : description.hashCode());
103 result = prime * result + ((qName == null) ? 0 : qName.hashCode());
104 result = prime * result + ((path == null) ? 0 : path.hashCode());
105 result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
106 result = prime * result + ((units == null) ? 0 : units.hashCode());
111 public boolean equals(final Object obj) {
118 if (getClass() != obj.getClass()) {
121 UnsignedIntegerEffectiveImplBase other = (UnsignedIntegerEffectiveImplBase) obj;
122 if (description == null) {
123 if (other.description != null) {
126 } else if (!description.equals(other.description)) {
130 if (other.qName != null) {
133 } else if (!qName.equals(other.qName)) {
137 if (other.path != null) {
140 } else if (!path.equals(other.path)) {
143 if (rangeStatements == null) {
144 if (other.rangeStatements != null) {
147 } else if (!rangeStatements.equals(other.rangeStatements)) {
151 if (other.units != null) {
154 } else if (!units.equals(other.units)) {
161 public String toString() {
162 StringBuilder builder = new StringBuilder();
163 builder.append(getClass().getSimpleName());
164 builder.append(" [name=");
165 builder.append(qName);
166 builder.append(", path=");
167 builder.append(path);
168 builder.append(", description=");
169 builder.append(description);
170 builder.append(", reference=");
171 builder.append(REFERENCE_INT);
172 builder.append(", units=");
173 builder.append(units);
174 builder.append(", rangeStatements=");
175 builder.append(rangeStatements);
177 return builder.toString();