Bug 6414: Fixed DataNodeIterator's traverseModule method
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BitsType.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
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;
20
21 /**
22  * The <code>default</code> implementation of Bits Type Definition interface.
23  *
24  * @see BitsTypeDefinition
25  * @deprecated Use {@link org.opendaylight.yangtools.yang.model.util.type.BaseTypes#bitsTypeBuilder(SchemaPath)} instead
26  */
27 @Deprecated
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.";
33
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;
38
39     /**
40      * Constructor with explicit definition of bits assigned to BitsType.
41      *
42      * @param path
43      * @param bits
44      */
45     private BitsType(final SchemaPath path, final List<Bit> bits) {
46         super();
47         this.bits = ImmutableList.copyOf(bits);
48         this.path = Preconditions.checkNotNull(path, "path must not be null");
49     }
50
51     public static BitsType create(final SchemaPath path, final List<Bit> bits) {
52         return new BitsType(path,bits);
53     }
54
55     /*
56      * (non-Javadoc)
57      *
58      * @see
59      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
60      */
61     @Override
62     public BitsTypeDefinition getBaseType() {
63         return null;
64     }
65
66     /*
67      * (non-Javadoc)
68      *
69      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
70      */
71     @Override
72     public String getUnits() {
73         return UNITS;
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see
80      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
81      * ()
82      */
83     @Override
84     public Object getDefaultValue() {
85         // FIXME: Return real bits.
86         return null;
87     }
88
89     /*
90      * (non-Javadoc)
91      *
92      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
93      */
94     @Override
95     public QName getQName() {
96         return NAME;
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
103      */
104     @Override
105     public SchemaPath getPath() {
106         return path;
107     }
108
109     /*
110      * (non-Javadoc)
111      *
112      * @see
113      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
114      */
115     @Override
116     public String getDescription() {
117         return DESCRIPTION;
118     }
119
120     /*
121      * (non-Javadoc)
122      *
123      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
124      */
125     @Override
126     public String getReference() {
127         return REFERENCE;
128     }
129
130     /*
131      * (non-Javadoc)
132      *
133      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
134      */
135     @Override
136     public Status getStatus() {
137         return Status.CURRENT;
138     }
139
140     @Override
141     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
142         return Collections.emptyList();
143     }
144
145     @Override
146     public List<Bit> getBits() {
147         return bits;
148     }
149
150     @Override
151     public int hashCode() {
152         final int prime = 31;
153         int result = 1;
154         result = prime * result + Objects.hashCode(bits);
155         result = prime * result + NAME.hashCode();
156         result = prime * result + path.hashCode();
157         return result;
158     }
159
160     @Override
161     public boolean equals(final Object obj) {
162         if (this == obj) {
163             return true;
164         }
165         if (obj == null) {
166             return false;
167         }
168         if (getClass() != obj.getClass()) {
169             return false;
170         }
171         BitsType other = (BitsType) obj;
172         return Objects.equals(bits, other.bits) && Objects.equals(path, other.path);
173     }
174
175     @Override
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);
190         builder.append("]");
191         return builder.toString();
192     }
193 }