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 * Constructor with explicit definition of bits assigned to BitsType.
42 private BitsType(final SchemaPath path, final List<Bit> bits) {
44 this.bits = ImmutableList.copyOf(bits);
45 this.path = Preconditions.checkNotNull(path, "path must not be null");
48 public static BitsType create(final SchemaPath path, final List<Bit> bits) {
49 return new BitsType(path,bits);
56 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
59 public BitsTypeDefinition getBaseType() {
66 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
69 public String getUnits() {
77 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
81 public Object getDefaultValue() {
88 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
91 public QName getQName() {
98 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
101 public SchemaPath getPath() {
109 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
112 public String getDescription() {
119 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
122 public String getReference() {
129 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
132 public Status getStatus() {
133 return Status.CURRENT;
137 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
138 return Collections.emptyList();
142 public List<Bit> getBits() {
147 public int hashCode() {
148 final int prime = 31;
150 result = prime * result + ((bits == null) ? 0 : bits.hashCode());
151 result = prime * result + NAME.hashCode();
152 result = prime * result + path.hashCode();
157 public boolean equals(final Object obj) {
164 if (getClass() != obj.getClass()) {
167 BitsType other = (BitsType) obj;
169 if (other.bits != null) {
172 } else if (!bits.equals(other.bits)) {
176 if (other.path != null) {
179 } else if (!path.equals(other.path)) {
186 public String toString() {
187 StringBuilder builder = new StringBuilder();
188 builder.append("BitsType [name=");
189 builder.append(NAME);
190 builder.append(", path=");
191 builder.append(path);
192 builder.append(", description=");
193 builder.append(DESCRIPTION);
194 builder.append(", reference=");
195 builder.append(REFERENCE);
196 builder.append(", bits=");
197 builder.append(bits);
198 builder.append(", units=");
199 builder.append(UNITS);
201 return builder.toString();