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