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.controller.yang.model.util;
11 import java.util.Collections;
12 import java.util.Date;
13 import java.util.List;
15 import org.opendaylight.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
22 * The <code>default</code> implementation of Bits Type Definition interface.
24 * @see BitsTypeDefinition
26 public class BitsType implements BitsTypeDefinition {
28 private final QName name = BaseTypes.constructQName("bits");
29 private final SchemaPath path;
30 private 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 final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
35 private final BitsTypeDefinition baseType;
36 private final List<Bit> bits;
37 private String units = "";
40 * Default constructor. <br>
41 * Instantiates Bits type as empty bits list.
45 this.bits = Collections.emptyList();
46 this.path = BaseTypes.schemaPath(name);
50 public BitsType(final List<String> actualPath, final URI namespace,
51 final Date revision) {
53 this.bits = Collections.emptyList();
54 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
55 this.baseType = new BitsType();
59 * Constructor with explicit definition of bits assigned to BitsType.
65 * The bits assigned for Bits Type
67 public BitsType(final List<String> actualPath, final URI namespace,
68 final Date revision, final List<Bit> bits) {
70 this.bits = Collections.unmodifiableList(bits);
72 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
73 this.baseType = new BitsType();
77 * Constructor with explicit definition of bits assigned to BitsType and
79 * The default value of Bits Type is List of bits.
82 * The bits assigned for Bits Type
86 public BitsType(final List<String> actualPath, final URI namespace,
87 final Date revision, List<Bit> bits, String units) {
89 this.bits = Collections.unmodifiableList(bits);
91 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
92 this.baseType = new BitsType();
99 * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
102 public BitsTypeDefinition getBaseType() {
109 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
112 public String getUnits() {
120 * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
124 public Object getDefaultValue() {
131 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
134 public QName getQName() {
141 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
144 public SchemaPath getPath() {
152 * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
155 public String getDescription() {
162 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
165 public String getReference() {
172 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
175 public Status getStatus() {
176 return Status.CURRENT;
180 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
181 return Collections.emptyList();
185 public List<Bit> getBits() {
190 public int hashCode() {
191 final int prime = 31;
193 result = prime * result + ((bits == null) ? 0 : bits.hashCode());
194 result = prime * result
195 + ((description == null) ? 0 : description.hashCode());
196 result = prime * result + ((name == null) ? 0 : name.hashCode());
197 result = prime * result + ((path == null) ? 0 : path.hashCode());
198 result = prime * result
199 + ((reference == null) ? 0 : reference.hashCode());
200 result = prime * result + ((units == null) ? 0 : units.hashCode());
205 public boolean equals(Object obj) {
212 if (getClass() != obj.getClass()) {
215 BitsType other = (BitsType) obj;
217 if (other.bits != null) {
220 } else if (!bits.equals(other.bits)) {
223 if (description == null) {
224 if (other.description != null) {
227 } else if (!description.equals(other.description)) {
231 if (other.name != null) {
234 } else if (!name.equals(other.name)) {
238 if (other.path != null) {
241 } else if (!path.equals(other.path)) {
244 if (reference == null) {
245 if (other.reference != null) {
248 } else if (!reference.equals(other.reference)) {
252 if (other.units != null) {
255 } else if (!units.equals(other.units)) {
262 public String toString() {
263 StringBuilder builder = new StringBuilder();
264 builder.append("BitsType [name=");
265 builder.append(name);
266 builder.append(", path=");
267 builder.append(path);
268 builder.append(", description=");
269 builder.append(description);
270 builder.append(", reference=");
271 builder.append(reference);
272 builder.append(", bits=");
273 builder.append(bits);
274 builder.append(", units=");
275 builder.append(units);
277 return builder.toString();