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