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.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;
28 abstract class UnsignedIntegerEffectiveImplBase extends
29 EffectiveStatementBase<String, TypeStatement> implements UnsignedIntegerTypeDefinition {
31 private static final String REFERENCE_INT = "https://tools.ietf.org/html/rfc6020#section-9.2";
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;
40 protected UnsignedIntegerEffectiveImplBase(final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
41 final String localName, final Number maxRange, final String description) {
45 this.qName = QName.create(YangConstants.RFC6020_YANG_MODULE, localName);
46 path = Utils.getSchemaPath(ctx);
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);
53 this.description = description;
57 public List<RangeConstraint> getRangeConstraints() {
58 return rangeStatements;
62 public UnsignedIntegerTypeDefinition getBaseType() {
67 public String getUnits() {
72 public Object getDefaultValue() {
77 public QName getQName() {
82 public SchemaPath getPath() {
87 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
88 return Collections.emptyList();
92 public String getDescription() {
97 public String getReference() {
102 public Status getStatus() {
103 return Status.CURRENT;
107 public int hashCode() {
108 final int prime = 31;
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());
119 public boolean equals(final Object obj) {
126 if (getClass() != obj.getClass()) {
129 UnsignedIntegerEffectiveImplBase other = (UnsignedIntegerEffectiveImplBase) obj;
130 if (description == null) {
131 if (other.description != null) {
134 } else if (!description.equals(other.description)) {
138 if (other.qName != null) {
141 } else if (!qName.equals(other.qName)) {
145 if (other.path != null) {
148 } else if (!path.equals(other.path)) {
151 if (rangeStatements == null) {
152 if (other.rangeStatements != null) {
155 } else if (!rangeStatements.equals(other.rangeStatements)) {
159 if (other.units != null) {
162 } else if (!units.equals(other.units)) {
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);
185 return builder.toString();