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 com.google.common.base.Optional;
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Objects;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.YangConstants;
17 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 import org.opendaylight.yangtools.yang.model.api.Status;
19 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
22 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
23 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
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 private final QName qName;
35 private final SchemaPath path;
36 private final String units = "";
37 private final String description;
38 private final 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 + Objects.hashCode(description);
111 result = prime * result + Objects.hashCode(qName);
112 result = prime * result + Objects.hashCode(path);
113 result = prime * result + Objects.hashCode(rangeStatements);
114 result = prime * result + Objects.hashCode(units);
119 public boolean equals(final Object obj) {
126 if (getClass() != obj.getClass()) {
129 UnsignedIntegerEffectiveImplBase other = (UnsignedIntegerEffectiveImplBase) obj;
130 if (!Objects.equals(description, other.description)) {
133 if (!Objects.equals(qName, other.qName)) {
136 if (!Objects.equals(path, other.path)) {
139 if (!Objects.equals(rangeStatements, other.rangeStatements)) {
142 if (!Objects.equals(units, other.units)) {
149 public String toString() {
150 StringBuilder builder = new StringBuilder();
151 builder.append(getClass().getSimpleName());
152 builder.append(" [name=");
153 builder.append(qName);
154 builder.append(", path=");
155 builder.append(path);
156 builder.append(", description=");
157 builder.append(description);
158 builder.append(", reference=");
159 builder.append(REFERENCE_INT);
160 builder.append(", units=");
161 builder.append(units);
162 builder.append(", rangeStatements=");
163 builder.append(rangeStatements);
165 return builder.toString();