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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
10 import com.google.common.collect.ImmutableList;
11 import java.util.ArrayList;
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.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
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.TypeEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement.BitsSpecification;
23 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
24 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
25 import org.opendaylight.yangtools.yang.model.util.BitsType;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
30 public class BitsSpecificationEffectiveStatementImpl extends
31 EffectiveStatementBase<String, BitsSpecification> implements BitsTypeDefinition, TypeEffectiveStatement<BitsSpecification> {
33 private static final QName QNAME = BaseTypes.BITS_QNAME;
34 private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
35 + "That is, a bits value is a set of flags identified by small integer position "
36 + "numbers starting at 0. Each bit number has an assigned name.";
38 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
39 private static final String UNITS = "";
40 private final SchemaPath path;
41 private final List<Bit> bits;
42 private BitsType bitsTypeInstance = null;
44 public BitsSpecificationEffectiveStatementImpl(final StmtContext<String, BitsSpecification, EffectiveStatement<String, BitsSpecification>> ctx) {
47 List<Bit> bitsInit = new ArrayList<>();
49 path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
51 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
52 if (effectiveStatement instanceof Bit) {
53 bitsInit.add(((Bit) effectiveStatement));
57 bits = ImmutableList.copyOf(bitsInit);
61 public List<Bit> getBits() {
66 public BitsTypeDefinition getBaseType() {
71 public String getUnits() {
76 public Object getDefaultValue() {
81 public QName getQName() {
86 public SchemaPath getPath() {
91 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
92 return Collections.emptyList();
96 public String getDescription() {
101 public String getReference() {
106 public Status getStatus() {
107 return Status.CURRENT;
111 public int hashCode() {
112 final int prime = 31;
114 result = prime * result + Objects.hashCode(bits);
115 result = prime * result + QNAME.hashCode();
116 result = prime * result + path.hashCode();
121 public boolean equals(final Object obj) {
128 if (getClass() != obj.getClass()) {
131 BitsSpecificationEffectiveStatementImpl other = (BitsSpecificationEffectiveStatementImpl) obj;
132 return Objects.equals(bits, other.bits) && Objects.equals(path, other.path);
136 public String toString() {
137 StringBuilder builder = new StringBuilder();
138 builder.append(BitsSpecificationEffectiveStatementImpl.class.getSimpleName());
139 builder.append(" [name=");
140 builder.append(QNAME);
141 builder.append(", path=");
142 builder.append(path);
143 builder.append(", description=");
144 builder.append(DESCRIPTION);
145 builder.append(", reference=");
146 builder.append(REFERENCE);
147 builder.append(", bits=");
148 builder.append(bits);
149 builder.append(", units=");
150 builder.append(UNITS);
152 return builder.toString();
156 public TypeDefinition<?> getTypeDefinition() {
157 if(bitsTypeInstance != null) {
158 return bitsTypeInstance;
161 bitsTypeInstance = BitsType.create(path, bits);
163 return bitsTypeInstance;