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.IntegerTypeDefinition;
23 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
27 abstract class IntegerEffectiveImplBase extends
28 EffectiveStatementBase<String,TypeStatement> implements IntegerTypeDefinition {
30 private static final String REFERENCE_INT = "https://tools.ietf.org/html/rfc6020#section-9.2";
32 private final QName qName;
33 private final SchemaPath path;
34 private final String units = "";
35 private final String description;
36 private final List<RangeConstraint> rangeStatements;
38 protected IntegerEffectiveImplBase(final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
39 final String localName, final Number minRange, final Number maxRange, final String description) {
43 this.qName = QName.create(YangConstants.RFC6020_YANG_MODULE, localName);
44 path = ctx.getSchemaPath().get();
46 final String rangeDescription = "Integer values between " + minRange + " and " + maxRange + ", inclusively.";
47 final RangeConstraint defaultRange = new RangeConstraintEffectiveImpl(minRange, maxRange,
48 Optional.of(rangeDescription), Optional.of(RangeConstraintEffectiveImpl.DEFAULT_REFERENCE));
49 rangeStatements = Collections.singletonList(defaultRange);
51 this.description = description;
55 public List<RangeConstraint> getRangeConstraints() {
56 return rangeStatements;
60 public IntegerTypeDefinition getBaseType() {
65 public String getUnits() {
70 public Object getDefaultValue() {
75 public QName getQName() {
80 public SchemaPath getPath() {
85 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
86 return Collections.emptyList();
90 public String getDescription() {
95 public String getReference() {
100 public Status getStatus() {
101 return Status.CURRENT;
105 public int hashCode() {
106 final int prime = 31;
108 result = prime * result + Objects.hashCode(description);
109 result = prime * result + Objects.hashCode(qName);
110 result = prime * result + Objects.hashCode(path);
111 result = prime * result + Objects.hashCode(rangeStatements);
112 result = prime * result + Objects.hashCode(units);
117 public boolean equals(final Object obj) {
124 if (getClass() != obj.getClass()) {
127 IntegerEffectiveImplBase other = (IntegerEffectiveImplBase) obj;
128 if (!Objects.equals(description, other.description)) {
131 if (!Objects.equals(qName, other.qName)) {
134 if (!Objects.equals(path, other.path)) {
137 if (!Objects.equals(rangeStatements, other.rangeStatements)) {
140 if (!Objects.equals(units, other.units)) {
147 public String toString() {
148 StringBuilder builder = new StringBuilder();
149 builder.append(getClass().getSimpleName());
150 builder.append(" [name=");
151 builder.append(qName);
152 builder.append(", path=");
153 builder.append(path);
154 builder.append(", description=");
155 builder.append(description);
156 builder.append(", reference=");
157 builder.append(REFERENCE_INT);
158 builder.append(", units=");
159 builder.append(units);
160 builder.append(", rangeStatements=");
161 builder.append(rangeStatements);
163 return builder.toString();