2 * Copyright (c) 2013 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.model.util;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableList;
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.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
22 * The <code>default</code> implementation of Bits Type Definition interface.
24 * @see BitsTypeDefinition
26 public final class BitsType implements BitsTypeDefinition {
27 private static final QName NAME = BaseTypes.BITS_QNAME;
28 private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
29 + "That is, a bits value is a set of flags identified by small integer position "
30 + "numbers starting at 0. Each bit number has an assigned name.";
32 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
33 private static final String UNITS = "";
34 private final SchemaPath path;
35 private final List<Bit> bits;
38 * Constructor with explicit definition of bits assigned to BitsType.
43 private BitsType(final SchemaPath path, final List<Bit> bits) {
45 this.bits = ImmutableList.copyOf(bits);
46 this.path = Preconditions.checkNotNull(path, "path must not be null");
49 public static BitsType create(final SchemaPath path, final List<Bit> bits) {
50 return new BitsType(path,bits);
57 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
60 public BitsTypeDefinition getBaseType() {
67 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
70 public String getUnits() {
78 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
82 public Object getDefaultValue() {
89 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
92 public QName getQName() {
99 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
102 public SchemaPath getPath() {
110 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
113 public String getDescription() {
120 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
123 public String getReference() {
130 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
133 public Status getStatus() {
134 return Status.CURRENT;
138 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
139 return Collections.emptyList();
143 public List<Bit> getBits() {
148 public int hashCode() {
149 final int prime = 31;
151 result = prime * result + Objects.hashCode(bits);
152 result = prime * result + NAME.hashCode();
153 result = prime * result + path.hashCode();
158 public boolean equals(final Object obj) {
165 if (getClass() != obj.getClass()) {
168 BitsType other = (BitsType) obj;
170 if (other.bits != null) {
173 } else if (!bits.equals(other.bits)) {
177 if (other.path != null) {
180 } else if (!path.equals(other.path)) {
187 public String toString() {
188 StringBuilder builder = new StringBuilder();
189 builder.append("BitsType [name=");
190 builder.append(NAME);
191 builder.append(", path=");
192 builder.append(path);
193 builder.append(", description=");
194 builder.append(DESCRIPTION);
195 builder.append(", reference=");
196 builder.append(REFERENCE);
197 builder.append(", bits=");
198 builder.append(bits);
199 builder.append(", units=");
200 builder.append(UNITS);
202 return builder.toString();