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 java.util.Collections;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
19 import com.google.common.base.Preconditions;
20 import com.google.common.collect.ImmutableList;
23 * The <code>default</code> implementation of Bits Type Definition interface.
25 * @see BitsTypeDefinition
27 public final class BitsType implements BitsTypeDefinition {
28 private final static QName NAME = BaseTypes.BITS_QNAME;
30 private final SchemaPath path;
31 private final String description = "The bits built-in type represents a bit set. "
32 + "That is, a bits value is a set of flags identified by small integer position "
33 + "numbers starting at 0. Each bit number has an assigned name.";
35 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
36 private final List<Bit> bits;
37 private static final String UNITS = "";
40 * Default constructor. <br>
41 * Instantiates Bits type as empty bits list.
44 * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
47 public BitsType(final SchemaPath path) {
49 this.bits = Collections.emptyList();
50 this.path = Preconditions.checkNotNull(path,"path must not be null");
54 * Constructor with explicit definition of bits assigned to BitsType.
58 * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
61 public BitsType(final SchemaPath path, final List<Bit> bits) {
63 this.bits = ImmutableList.copyOf(bits);
64 this.path = Preconditions.checkNotNull(path,"path must not be null");
67 public static BitsType create(final SchemaPath path, final List<Bit> bits) {
68 return new BitsType(path,bits);
75 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
78 public BitsTypeDefinition getBaseType() {
85 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
88 public String getUnits() {
96 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
100 public Object getDefaultValue() {
107 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
110 public QName getQName() {
117 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
120 public SchemaPath getPath() {
128 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
131 public String getDescription() {
138 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
141 public String getReference() {
148 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
151 public Status getStatus() {
152 return Status.CURRENT;
156 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
157 return Collections.emptyList();
161 public List<Bit> getBits() {
166 public int hashCode() {
167 final int prime = 31;
169 result = prime * result + ((bits == null) ? 0 : bits.hashCode());
170 result = prime * result + ((description == null) ? 0 : description.hashCode());
171 result = prime * result + NAME.hashCode();
172 result = prime * result + path.hashCode();
177 public boolean equals(final Object obj) {
184 if (getClass() != obj.getClass()) {
187 BitsType other = (BitsType) obj;
189 if (other.bits != null) {
192 } else if (!bits.equals(other.bits)) {
195 if (description == null) {
196 if (other.description != null) {
199 } else if (!description.equals(other.description)) {
204 if (other.path != null) {
207 } else if (!path.equals(other.path)) {
214 public String toString() {
215 StringBuilder builder = new StringBuilder();
216 builder.append("BitsType [name=");
217 builder.append(NAME);
218 builder.append(", path=");
219 builder.append(path);
220 builder.append(", description=");
221 builder.append(description);
222 builder.append(", reference=");
223 builder.append(REFERENCE);
224 builder.append(", bits=");
225 builder.append(bits);
226 builder.append(", units=");
227 builder.append(UNITS);
229 return builder.toString();