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