2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
11 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
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;
28 abstract class IntegerEffectiveImplBase extends
29 EffectiveStatementBase<String,TypeStatement> implements IntegerTypeDefinition {
31 private static final String REFERENCE_INT = "https://tools.ietf.org/html/rfc6020#section-9.2";
33 protected QName qName;
34 private SchemaPath path;
35 private String units = "";
36 private final String description;
37 private List<RangeConstraint> rangeStatements;
39 protected IntegerEffectiveImplBase(final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
40 final String localName, final Number minRange, final Number maxRange, final String description) {
44 this.qName = QName.create(YangConstants.RFC6020_YANG_MODULE, localName);
45 path = Utils.getSchemaPath(ctx);
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);
52 this.description = description;
56 public List<RangeConstraint> getRangeConstraints() {
57 return rangeStatements;
61 public IntegerTypeDefinition getBaseType() {
66 public String getUnits() {
71 public Object getDefaultValue() {
76 public QName getQName() {
81 public SchemaPath getPath() {
86 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
87 return Collections.emptyList();
91 public String getDescription() {
96 public String getReference() {
101 public Status getStatus() {
102 return Status.CURRENT;
106 public int hashCode() {
107 final int prime = 31;
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());
118 public boolean equals(final Object obj) {
125 if (getClass() != obj.getClass()) {
128 IntegerEffectiveImplBase other = (IntegerEffectiveImplBase) obj;
129 if (description == null) {
130 if (other.description != null) {
133 } else if (!description.equals(other.description)) {
137 if (other.qName != null) {
140 } else if (!qName.equals(other.qName)) {
144 if (other.path != null) {
147 } else if (!path.equals(other.path)) {
150 if (rangeStatements == null) {
151 if (other.rangeStatements != null) {
154 } else if (!rangeStatements.equals(other.rangeStatements)) {
158 if (other.units != null) {
161 } else if (!units.equals(other.units)) {
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);
184 return builder.toString();