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.meta.EffectiveStatement;
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.stmt.TypeStatement;
20 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
23 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
24 import org.opendaylight.yangtools.yang.model.util.BitsType;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveStatementBase;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
29 public class BitsSpecificationEffectiveStatementImpl extends
30 EffectiveStatementBase<String, TypeStatement.BitsSpecification> implements BitsTypeDefinition, TypeDefinitionEffectiveBuilder {
32 private static final QName QNAME = BaseTypes.BITS_QNAME;
33 private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
34 + "That is, a bits value is a set of flags identified by small integer position "
35 + "numbers starting at 0. Each bit number has an assigned name.";
37 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
38 private static final String UNITS = "";
39 private final SchemaPath path;
40 private final List<Bit> bits;
42 public BitsSpecificationEffectiveStatementImpl(StmtContext<String, TypeStatement.BitsSpecification, EffectiveStatement<String, TypeStatement.BitsSpecification>> ctx) {
45 List<Bit> bitsInit = new ArrayList<>();
47 path = Utils.getSchemaPath(ctx.getParentContext()).createChild(QNAME);
49 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
50 if (effectiveStatement instanceof Bit) {
51 bitsInit.add(((Bit) effectiveStatement));
55 bits = ImmutableList.copyOf(bitsInit);
59 public List<Bit> getBits() {
64 public BitsTypeDefinition getBaseType() {
69 public String getUnits() {
74 public Object getDefaultValue() {
79 public QName getQName() {
84 public SchemaPath getPath() {
89 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
90 return Collections.emptyList();
94 public String getDescription() {
99 public String getReference() {
104 public Status getStatus() {
105 return Status.CURRENT;
109 public int hashCode() {
110 final int prime = 31;
112 result = prime * result + Objects.hashCode(bits);
113 result = prime * result + QNAME.hashCode();
114 result = prime * result + path.hashCode();
119 public boolean equals(final Object obj) {
126 if (getClass() != obj.getClass()) {
129 BitsSpecificationEffectiveStatementImpl other = (BitsSpecificationEffectiveStatementImpl) obj;
131 if (other.bits != null) {
134 } else if (!bits.equals(other.bits)) {
138 if (other.path != null) {
141 } else if (!path.equals(other.path)) {
148 public String toString() {
149 StringBuilder builder = new StringBuilder();
150 builder.append(BitsSpecificationEffectiveStatementImpl.class.getSimpleName());
151 builder.append(" [name=");
152 builder.append(QNAME);
153 builder.append(", path=");
154 builder.append(path);
155 builder.append(", description=");
156 builder.append(DESCRIPTION);
157 builder.append(", reference=");
158 builder.append(REFERENCE);
159 builder.append(", bits=");
160 builder.append(bits);
161 builder.append(", units=");
162 builder.append(UNITS);
164 return builder.toString();
167 private BitsType bitsTypeInstance = null;
169 public TypeDefinition<?> buildType() {
171 if(bitsTypeInstance != null) {
172 return bitsTypeInstance;
175 bitsTypeInstance = BitsType.create(path, bits);
177 return bitsTypeInstance;