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
25 * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#bitsTypeBuilder(SchemaPath)} instead
28 public final class BitsType implements BitsTypeDefinition {
29 private static final QName NAME = BaseTypes.BITS_QNAME;
30 private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
31 + "That is, a bits value is a set of flags identified by small integer position "
32 + "numbers starting at 0. Each bit number has an assigned name.";
34 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
35 private static final String UNITS = "";
36 private final SchemaPath path;
37 private final List<Bit> bits;
40 * Constructor with explicit definition of bits assigned to BitsType.
45 private BitsType(final SchemaPath path, final List<Bit> bits) {
47 this.bits = ImmutableList.copyOf(bits);
48 this.path = Preconditions.checkNotNull(path, "path must not be null");
51 public static BitsType create(final SchemaPath path, final List<Bit> bits) {
52 return new BitsType(path,bits);
59 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
62 public BitsTypeDefinition getBaseType() {
69 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
72 public String getUnits() {
80 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
84 public Object getDefaultValue() {
85 // FIXME: Return real bits.
92 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
95 public QName getQName() {
102 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
105 public SchemaPath getPath() {
113 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
116 public String getDescription() {
123 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
126 public String getReference() {
133 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
136 public Status getStatus() {
137 return Status.CURRENT;
141 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
142 return Collections.emptyList();
146 public List<Bit> getBits() {
151 public int hashCode() {
152 final int prime = 31;
154 result = prime * result + Objects.hashCode(bits);
155 result = prime * result + NAME.hashCode();
156 result = prime * result + path.hashCode();
161 public boolean equals(final Object obj) {
168 if (getClass() != obj.getClass()) {
171 BitsType other = (BitsType) obj;
172 return Objects.equals(bits, other.bits) && Objects.equals(path, other.path);
176 public String toString() {
177 StringBuilder builder = new StringBuilder();
178 builder.append("BitsType [name=");
179 builder.append(NAME);
180 builder.append(", path=");
181 builder.append(path);
182 builder.append(", description=");
183 builder.append(DESCRIPTION);
184 builder.append(", reference=");
185 builder.append(REFERENCE);
186 builder.append(", bits=");
187 builder.append(bits);
188 builder.append(", units=");
189 builder.append(UNITS);
191 return builder.toString();