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 org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
21 * The <code>default</code> implementation of Bits Type Definition interface.
23 * @see BitsTypeDefinition
25 public final class BitsType implements BitsTypeDefinition {
26 private static final QName NAME = BaseTypes.BITS_QNAME;
27 private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
28 + "That is, a bits value is a set of flags identified by small integer position "
29 + "numbers starting at 0. Each bit number has an assigned name.";
31 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
32 private static final String UNITS = "";
33 private final SchemaPath path;
34 private final List<Bit> bits;
37 * Default constructor. <br>
38 * Instantiates Bits type as empty bits list.
41 * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
44 public BitsType(final SchemaPath path) {
46 this.bits = Collections.emptyList();
47 this.path = Preconditions.checkNotNull(path,"path must not be null");
51 * Constructor with explicit definition of bits assigned to BitsType.
55 * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
58 public BitsType(final SchemaPath path, final List<Bit> bits) {
60 this.bits = ImmutableList.copyOf(bits);
61 this.path = Preconditions.checkNotNull(path,"path must not be null");
64 public static BitsType create(final SchemaPath path, final List<Bit> bits) {
65 return new BitsType(path,bits);
72 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
75 public BitsTypeDefinition getBaseType() {
82 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
85 public String getUnits() {
93 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
97 public Object getDefaultValue() {
104 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
107 public QName getQName() {
114 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
117 public SchemaPath getPath() {
125 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
128 public String getDescription() {
135 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
138 public String getReference() {
145 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
148 public Status getStatus() {
149 return Status.CURRENT;
153 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
154 return Collections.emptyList();
158 public List<Bit> getBits() {
163 public int hashCode() {
164 final int prime = 31;
166 result = prime * result + ((bits == null) ? 0 : bits.hashCode());
167 result = prime * result + NAME.hashCode();
168 result = prime * result + path.hashCode();
173 public boolean equals(final Object obj) {
180 if (getClass() != obj.getClass()) {
183 BitsType other = (BitsType) obj;
185 if (other.bits != null) {
188 } else if (!bits.equals(other.bits)) {
192 if (other.path != null) {
195 } else if (!path.equals(other.path)) {
202 public String toString() {
203 StringBuilder builder = new StringBuilder();
204 builder.append("BitsType [name=");
205 builder.append(NAME);
206 builder.append(", path=");
207 builder.append(path);
208 builder.append(", description=");
209 builder.append(DESCRIPTION);
210 builder.append(", reference=");
211 builder.append(REFERENCE);
212 builder.append(", bits=");
213 builder.append(bits);
214 builder.append(", units=");
215 builder.append(UNITS);
217 return builder.toString();