51e0306e8b8737c1e7450c6fe60a8767b6c43280
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / 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.controller.yang.model.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.SchemaPath;
15 import org.opendaylight.controller.yang.model.api.Status;
16 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.controller.yang.model.api.type.BitsTypeDefinition;
18
19 /**
20  * The <code>default</code> implementation of Bits Type Definition interface.
21  *
22  * @see BitsTypeDefinition
23  */
24 public final class BitsType implements BitsTypeDefinition {
25
26     private final QName name = BaseTypes.constructQName("bits");
27     private final SchemaPath path;
28     private 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.";
31
32     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.7";
33     private final BitsTypeDefinition baseType;
34     private final List<Bit> bits;
35     private String units = "";
36
37     /**
38      * Default constructor. <br>
39      * Instantiates Bits type as empty bits list.
40      */
41     private BitsType() {
42         super();
43         this.bits = Collections.emptyList();
44         this.path = BaseTypes.schemaPath(name);
45         this.baseType = this;
46     }
47
48     public BitsType(final SchemaPath path) {
49         super();
50         this.bits = Collections.emptyList();
51         this.path = path;
52         this.baseType = new BitsType();
53     }
54
55     /**
56      * Constructor with explicit definition of bits assigned to BitsType.
57      *
58      * @param actualPath
59      * @param namespace
60      * @param revision
61      * @param bits
62      *            The bits assigned for Bits Type
63      */
64     public BitsType(final SchemaPath path, final List<Bit> bits) {
65         super();
66         this.bits = Collections.unmodifiableList(bits);
67         this.units = "";
68         this.path = path;
69         this.baseType = new BitsType();
70     }
71
72     /**
73      * Constructor with explicit definition of bits assigned to BitsType and
74      * Units. <br>
75      * The default value of Bits Type is List of bits.
76      *
77      * @param bits
78      *            The bits assigned for Bits Type
79      * @param units
80      *            units for bits type
81      */
82     public BitsType(final SchemaPath path, List<Bit> bits, String units) {
83         super();
84         this.bits = Collections.unmodifiableList(bits);
85         this.units = units;
86         this.path = path;
87         this.baseType = new BitsType();
88     }
89
90     /*
91      * (non-Javadoc)
92      *
93      * @see
94      * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
95      */
96     @Override
97     public BitsTypeDefinition getBaseType() {
98         return baseType;
99     }
100
101     /*
102      * (non-Javadoc)
103      *
104      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
105      */
106     @Override
107     public String getUnits() {
108         return units;
109     }
110
111     /*
112      * (non-Javadoc)
113      *
114      * @see
115      * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
116      * ()
117      */
118     @Override
119     public Object getDefaultValue() {
120         return bits;
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
127      */
128     @Override
129     public QName getQName() {
130         return name;
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
137      */
138     @Override
139     public SchemaPath getPath() {
140         return path;
141     }
142
143     /*
144      * (non-Javadoc)
145      *
146      * @see
147      * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
148      */
149     @Override
150     public String getDescription() {
151         return description;
152     }
153
154     /*
155      * (non-Javadoc)
156      *
157      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
158      */
159     @Override
160     public String getReference() {
161         return reference;
162     }
163
164     /*
165      * (non-Javadoc)
166      *
167      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
168      */
169     @Override
170     public Status getStatus() {
171         return Status.CURRENT;
172     }
173
174     @Override
175     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
176         return Collections.emptyList();
177     }
178
179     @Override
180     public List<Bit> getBits() {
181         return bits;
182     }
183
184     @Override
185     public int hashCode() {
186         final int prime = 31;
187         int result = 1;
188         result = prime * result + ((bits == null) ? 0 : bits.hashCode());
189         result = prime * result
190                 + ((description == null) ? 0 : description.hashCode());
191         result = prime * result + ((name == null) ? 0 : name.hashCode());
192         result = prime * result + ((path == null) ? 0 : path.hashCode());
193         result = prime * result
194                 + ((reference == null) ? 0 : reference.hashCode());
195         result = prime * result + ((units == null) ? 0 : units.hashCode());
196         return result;
197     }
198
199     @Override
200     public boolean equals(Object obj) {
201         if (this == obj) {
202             return true;
203         }
204         if (obj == null) {
205             return false;
206         }
207         if (getClass() != obj.getClass()) {
208             return false;
209         }
210         BitsType other = (BitsType) obj;
211         if (bits == null) {
212             if (other.bits != null) {
213                 return false;
214             }
215         } else if (!bits.equals(other.bits)) {
216             return false;
217         }
218         if (description == null) {
219             if (other.description != null) {
220                 return false;
221             }
222         } else if (!description.equals(other.description)) {
223             return false;
224         }
225         if (name == null) {
226             if (other.name != null) {
227                 return false;
228             }
229         } else if (!name.equals(other.name)) {
230             return false;
231         }
232         if (path == null) {
233             if (other.path != null) {
234                 return false;
235             }
236         } else if (!path.equals(other.path)) {
237             return false;
238         }
239         if (reference == null) {
240             if (other.reference != null) {
241                 return false;
242             }
243         } else if (!reference.equals(other.reference)) {
244             return false;
245         }
246         if (units == null) {
247             if (other.units != null) {
248                 return false;
249             }
250         } else if (!units.equals(other.units)) {
251             return false;
252         }
253         return true;
254     }
255
256     @Override
257     public String toString() {
258         StringBuilder builder = new StringBuilder();
259         builder.append("BitsType [name=");
260         builder.append(name);
261         builder.append(", path=");
262         builder.append(path);
263         builder.append(", description=");
264         builder.append(description);
265         builder.append(", reference=");
266         builder.append(reference);
267         builder.append(", bits=");
268         builder.append(bits);
269         builder.append(", units=");
270         builder.append(units);
271         builder.append("]");
272         return builder.toString();
273     }
274 }