Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / UnsignedIntegerEffectiveImplBase.java
1 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
2
3 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
4
5 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
6 import com.google.common.base.Optional;
7 import java.util.Collections;
8 import java.util.List;
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;
19
20 abstract class UnsignedIntegerEffectiveImplBase extends
21         EffectiveStatementBase<String, TypeStatement> implements UnsignedIntegerTypeDefinition {
22
23     private static final String REFERENCE_INT = "https://tools.ietf.org/html/rfc6020#section-9.2";
24
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;
31
32     protected UnsignedIntegerEffectiveImplBase(final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
33             final String localName, final Number maxRange, final String description) {
34
35         super(ctx);
36
37         this.qName = QName.create(YangConstants.RFC6020_YANG_MODULE, localName);
38         path = Utils.getSchemaPath(ctx);
39
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);
44
45         this.description = description;
46     }
47
48     @Override
49     public List<RangeConstraint> getRangeConstraints() {
50         return rangeStatements;
51     }
52
53     @Override
54     public UnsignedIntegerTypeDefinition getBaseType() {
55         return null;
56     }
57
58     @Override
59     public String getUnits() {
60         return units;
61     }
62
63     @Override
64     public Object getDefaultValue() {
65         return null;
66     }
67
68     @Override
69     public QName getQName() {
70         return qName;
71     }
72
73     @Override
74     public SchemaPath getPath() {
75         return path;
76     }
77
78     @Override
79     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
80         return Collections.emptyList();
81     }
82
83     @Override
84     public String getDescription() {
85         return description;
86     }
87
88     @Override
89     public String getReference() {
90         return REFERENCE_INT;
91     }
92
93     @Override
94     public Status getStatus() {
95         return Status.CURRENT;
96     }
97
98     @Override
99     public int hashCode() {
100         final int prime = 31;
101         int result = 1;
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());
107         return result;
108     }
109
110     @Override
111     public boolean equals(final Object obj) {
112         if (this == obj) {
113             return true;
114         }
115         if (obj == null) {
116             return false;
117         }
118         if (getClass() != obj.getClass()) {
119             return false;
120         }
121         UnsignedIntegerEffectiveImplBase other = (UnsignedIntegerEffectiveImplBase) obj;
122         if (description == null) {
123             if (other.description != null) {
124                 return false;
125             }
126         } else if (!description.equals(other.description)) {
127             return false;
128         }
129         if (qName == null) {
130             if (other.qName != null) {
131                 return false;
132             }
133         } else if (!qName.equals(other.qName)) {
134             return false;
135         }
136         if (path == null) {
137             if (other.path != null) {
138                 return false;
139             }
140         } else if (!path.equals(other.path)) {
141             return false;
142         }
143         if (rangeStatements == null) {
144             if (other.rangeStatements != null) {
145                 return false;
146             }
147         } else if (!rangeStatements.equals(other.rangeStatements)) {
148             return false;
149         }
150         if (units == null) {
151             if (other.units != null) {
152                 return false;
153             }
154         } else if (!units.equals(other.units)) {
155             return false;
156         }
157         return true;
158     }
159
160     @Override
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);
176         builder.append("]");
177         return builder.toString();
178     }
179 }