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 final static QName NAME = BaseTypes.BITS_QNAME;
28 private final SchemaPath path;
29 private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
30 + "That is, a bits value is a set of flags identified by small integer position "
31 + "numbers starting at 0. Each bit number has an assigned name.";
33 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
34 private final List<Bit> bits;
35 private static final String UNITS = "";
38 * Default constructor. <br>
39 * Instantiates Bits type as empty bits list.
42 * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
45 public BitsType(final SchemaPath path) {
47 this.bits = Collections.emptyList();
48 this.path = Preconditions.checkNotNull(path,"path must not be null");
52 * Constructor with explicit definition of bits assigned to BitsType.
56 * @deprecated Use static factory method {@link #create(SchemaPath, List)} instead.
59 public BitsType(final SchemaPath path, final List<Bit> bits) {
61 this.bits = ImmutableList.copyOf(bits);
62 this.path = Preconditions.checkNotNull(path,"path must not be null");
65 public static BitsType create(final SchemaPath path, final List<Bit> bits) {
66 return new BitsType(path,bits);
73 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
76 public BitsTypeDefinition getBaseType() {
83 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
86 public String getUnits() {
94 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
98 public Object getDefaultValue() {
105 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
108 public QName getQName() {
115 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
118 public SchemaPath getPath() {
126 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
129 public String getDescription() {
136 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
139 public String getReference() {
146 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
149 public Status getStatus() {
150 return Status.CURRENT;
154 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
155 return Collections.emptyList();
159 public List<Bit> getBits() {
164 public int hashCode() {
165 final int prime = 31;
167 result = prime * result + ((bits == null) ? 0 : bits.hashCode());
168 result = prime * result + NAME.hashCode();
169 result = prime * result + path.hashCode();
174 public boolean equals(final Object obj) {
181 if (getClass() != obj.getClass()) {
184 BitsType other = (BitsType) obj;
186 if (other.bits != null) {
189 } else if (!bits.equals(other.bits)) {
193 if (other.path != null) {
196 } else if (!path.equals(other.path)) {
203 public String toString() {
204 StringBuilder builder = new StringBuilder();
205 builder.append("BitsType [name=");
206 builder.append(NAME);
207 builder.append(", path=");
208 builder.append(path);
209 builder.append(", description=");
210 builder.append(DESCRIPTION);
211 builder.append(", reference=");
212 builder.append(REFERENCE);
213 builder.append(", bits=");
214 builder.append(bits);
215 builder.append(", units=");
216 builder.append(UNITS);
218 return builder.toString();