Fix license header violations in yang-parser-impl
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / UnsignedIntegerEffectiveImplBase.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
10
11 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
12
13 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
14 import com.google.common.base.Optional;
15 import java.util.Collections;
16 import java.util.List;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.YangConstants;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.Status;
21 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
24 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
27
28 abstract class UnsignedIntegerEffectiveImplBase extends
29         EffectiveStatementBase<String, TypeStatement> implements UnsignedIntegerTypeDefinition {
30
31     private static final String REFERENCE_INT = "https://tools.ietf.org/html/rfc6020#section-9.2";
32
33     protected static final Number MIN_RANGE = 0;
34     protected QName qName;
35     private SchemaPath path;
36     private String units = "";
37     private final String description;
38     private List<RangeConstraint> rangeStatements;
39
40     protected UnsignedIntegerEffectiveImplBase(final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
41             final String localName, final Number maxRange, final String description) {
42
43         super(ctx);
44
45         this.qName = QName.create(YangConstants.RFC6020_YANG_MODULE, localName);
46         path = Utils.getSchemaPath(ctx);
47
48         final String rangeDescription = "Integer values between " + MIN_RANGE + " and " + maxRange + ", inclusively.";
49         final RangeConstraint defaultRange = new RangeConstraintEffectiveImpl(MIN_RANGE, maxRange,
50                 Optional.of(rangeDescription), Optional.of(RangeConstraintEffectiveImpl.DEFAULT_REFERENCE));
51         rangeStatements = Collections.singletonList(defaultRange);
52
53         this.description = description;
54     }
55
56     @Override
57     public List<RangeConstraint> getRangeConstraints() {
58         return rangeStatements;
59     }
60
61     @Override
62     public UnsignedIntegerTypeDefinition getBaseType() {
63         return null;
64     }
65
66     @Override
67     public String getUnits() {
68         return units;
69     }
70
71     @Override
72     public Object getDefaultValue() {
73         return null;
74     }
75
76     @Override
77     public QName getQName() {
78         return qName;
79     }
80
81     @Override
82     public SchemaPath getPath() {
83         return path;
84     }
85
86     @Override
87     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
88         return Collections.emptyList();
89     }
90
91     @Override
92     public String getDescription() {
93         return description;
94     }
95
96     @Override
97     public String getReference() {
98         return REFERENCE_INT;
99     }
100
101     @Override
102     public Status getStatus() {
103         return Status.CURRENT;
104     }
105
106     @Override
107     public int hashCode() {
108         final int prime = 31;
109         int result = 1;
110         result = prime * result + ((description == null) ? 0 : description.hashCode());
111         result = prime * result + ((qName == null) ? 0 : qName.hashCode());
112         result = prime * result + ((path == null) ? 0 : path.hashCode());
113         result = prime * result + ((rangeStatements == null) ? 0 : rangeStatements.hashCode());
114         result = prime * result + ((units == null) ? 0 : units.hashCode());
115         return result;
116     }
117
118     @Override
119     public boolean equals(final Object obj) {
120         if (this == obj) {
121             return true;
122         }
123         if (obj == null) {
124             return false;
125         }
126         if (getClass() != obj.getClass()) {
127             return false;
128         }
129         UnsignedIntegerEffectiveImplBase other = (UnsignedIntegerEffectiveImplBase) obj;
130         if (description == null) {
131             if (other.description != null) {
132                 return false;
133             }
134         } else if (!description.equals(other.description)) {
135             return false;
136         }
137         if (qName == null) {
138             if (other.qName != null) {
139                 return false;
140             }
141         } else if (!qName.equals(other.qName)) {
142             return false;
143         }
144         if (path == null) {
145             if (other.path != null) {
146                 return false;
147             }
148         } else if (!path.equals(other.path)) {
149             return false;
150         }
151         if (rangeStatements == null) {
152             if (other.rangeStatements != null) {
153                 return false;
154             }
155         } else if (!rangeStatements.equals(other.rangeStatements)) {
156             return false;
157         }
158         if (units == null) {
159             if (other.units != null) {
160                 return false;
161             }
162         } else if (!units.equals(other.units)) {
163             return false;
164         }
165         return true;
166     }
167
168     @Override
169     public String toString() {
170         StringBuilder builder = new StringBuilder();
171         builder.append(getClass().getSimpleName());
172         builder.append(" [name=");
173         builder.append(qName);
174         builder.append(", path=");
175         builder.append(path);
176         builder.append(", description=");
177         builder.append(description);
178         builder.append(", reference=");
179         builder.append(REFERENCE_INT);
180         builder.append(", units=");
181         builder.append(units);
182         builder.append(", rangeStatements=");
183         builder.append(rangeStatements);
184         builder.append("]");
185         return builder.toString();
186     }
187 }