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
26 public final class BitsType implements BitsTypeDefinition {
27 private static final QName NAME = BaseTypes.BITS_QNAME;
28 private static final String DESCRIPTION = "The bits built-in type represents a bit set. "
29 + "That is, a bits value is a set of flags identified by small integer position "
30 + "numbers starting at 0. Each bit number has an assigned name.";
32 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.7";
33 private static final String UNITS = "";
34 private final SchemaPath path;
35 private final List<Bit> bits;
38 * Constructor with explicit definition of bits assigned to BitsType.
43 private BitsType(final SchemaPath path, final List<Bit> bits) {
45 this.bits = ImmutableList.copyOf(bits);
46 this.path = Preconditions.checkNotNull(path, "path must not be null");
49 public static BitsType create(final SchemaPath path, final List<Bit> bits) {
50 return new BitsType(path,bits);
57 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
60 public BitsTypeDefinition getBaseType() {
67 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
70 public String getUnits() {
78 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
82 public Object getDefaultValue() {
83 // FIXME: Return real bits.
90 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
93 public QName getQName() {
100 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
103 public SchemaPath getPath() {
111 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
114 public String getDescription() {
121 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
124 public String getReference() {
131 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
134 public Status getStatus() {
135 return Status.CURRENT;
139 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
140 return Collections.emptyList();
144 public List<Bit> getBits() {
149 public int hashCode() {
150 final int prime = 31;
152 result = prime * result + Objects.hashCode(bits);
153 result = prime * result + NAME.hashCode();
154 result = prime * result + path.hashCode();
159 public boolean equals(final Object obj) {
166 if (getClass() != obj.getClass()) {
169 BitsType other = (BitsType) obj;
170 return Objects.equals(bits, other.bits) && Objects.equals(path, other.path);
174 public String toString() {
175 StringBuilder builder = new StringBuilder();
176 builder.append("BitsType [name=");
177 builder.append(NAME);
178 builder.append(", path=");
179 builder.append(path);
180 builder.append(", description=");
181 builder.append(DESCRIPTION);
182 builder.append(", reference=");
183 builder.append(REFERENCE);
184 builder.append(", bits=");
185 builder.append(bits);
186 builder.append(", units=");
187 builder.append(UNITS);
189 return builder.toString();