Merge from development repository.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / model / util / BitsType.java
1 /*\r
2   * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3   *\r
4   * This program and the accompanying materials are made available under the\r
5   * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6   * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7   */\r
8 package org.opendaylight.controller.model.util;\r
9 \r
10 import java.util.Collections;\r
11 import java.util.List;\r
12 \r
13 import org.opendaylight.controller.model.api.type.BitsTypeDefinition;\r
14 import org.opendaylight.controller.yang.common.QName;\r
15 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
16 import org.opendaylight.controller.yang.model.api.Status;\r
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
18 \r
19 public class BitsType implements BitsTypeDefinition {\r
20 \r
21     private final QName name = BaseTypes.constructQName("bits");\r
22     private final SchemaPath path = BaseTypes.schemaPath(name);\r
23     private final String description = "";\r
24     private final String reference = "";\r
25 \r
26     private final List<Bit> bits;\r
27     private String units = "";\r
28 \r
29     /**\r
30      * Default constructor. <br>\r
31      * Instantiates Bits type as empty bits list.\r
32      * \r
33      */\r
34     public BitsType() {\r
35         super();\r
36         bits = Collections.emptyList();\r
37     }\r
38 \r
39     /**\r
40      * Overloaded constructor with explicit definition of bits assigned to\r
41      * BitsType.\r
42      * \r
43      * @param bits\r
44      *            The bits assigned for Bits Type\r
45      */\r
46     public BitsType(final List<Bit> bits) {\r
47         super();\r
48         this.bits = Collections.unmodifiableList(bits);\r
49         this.units = "";\r
50     }\r
51 \r
52     public BitsType(List<Bit> bits, String units) {\r
53         super();\r
54         this.bits = Collections.unmodifiableList(bits);\r
55         ;\r
56         this.units = units;\r
57     }\r
58 \r
59     /*\r
60      * (non-Javadoc)\r
61      * \r
62      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()\r
63      */\r
64     @Override\r
65     public BitsTypeDefinition getBaseType() {\r
66         return this;\r
67     }\r
68 \r
69     /*\r
70      * (non-Javadoc)\r
71      * \r
72      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()\r
73      */\r
74     @Override\r
75     public String getUnits() {\r
76         return units;\r
77     }\r
78 \r
79     /*\r
80      * (non-Javadoc)\r
81      * \r
82      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()\r
83      */\r
84     @Override\r
85     public Object getDefaultValue() {\r
86         return bits;\r
87     }\r
88 \r
89     /*\r
90      * (non-Javadoc)\r
91      * \r
92      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()\r
93      */\r
94     @Override\r
95     public QName getQName() {\r
96         return name;\r
97     }\r
98 \r
99     /*\r
100      * (non-Javadoc)\r
101      * \r
102      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()\r
103      */\r
104     @Override\r
105     public SchemaPath getPath() {\r
106         return path;\r
107     }\r
108 \r
109     /*\r
110      * (non-Javadoc)\r
111      * \r
112      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()\r
113      */\r
114     @Override\r
115     public String getDescription() {\r
116         return description;\r
117     }\r
118 \r
119     /*\r
120      * (non-Javadoc)\r
121      * \r
122      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()\r
123      */\r
124     @Override\r
125     public String getReference() {\r
126         return reference;\r
127     }\r
128 \r
129     /*\r
130      * (non-Javadoc)\r
131      * \r
132      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()\r
133      */\r
134     @Override\r
135     public Status getStatus() {\r
136         return Status.CURRENT;\r
137     }\r
138 \r
139     @Override\r
140     public List<UnknownSchemaNode> getUnknownSchemaNodes() {\r
141         return Collections.emptyList();\r
142     }\r
143 \r
144     @Override\r
145     public List<Bit> getBits() {\r
146         return bits;\r
147     }\r
148 \r
149     @Override\r
150     public int hashCode() {\r
151         final int prime = 31;\r
152         int result = 1;\r
153         result = prime * result + ((bits == null) ? 0 : bits.hashCode());\r
154         result = prime * result\r
155                 + ((description == null) ? 0 : description.hashCode());\r
156         result = prime * result + ((name == null) ? 0 : name.hashCode());\r
157         result = prime * result + ((path == null) ? 0 : path.hashCode());\r
158         result = prime * result\r
159                 + ((reference == null) ? 0 : reference.hashCode());\r
160         result = prime * result + ((units == null) ? 0 : units.hashCode());\r
161         return result;\r
162     }\r
163 \r
164     @Override\r
165     public boolean equals(Object obj) {\r
166         if (this == obj) {\r
167             return true;\r
168         }\r
169         if (obj == null) {\r
170             return false;\r
171         }\r
172         if (getClass() != obj.getClass()) {\r
173             return false;\r
174         }\r
175         BitsType other = (BitsType) obj;\r
176         if (bits == null) {\r
177             if (other.bits != null) {\r
178                 return false;\r
179             }\r
180         } else if (!bits.equals(other.bits)) {\r
181             return false;\r
182         }\r
183         if (description == null) {\r
184             if (other.description != null) {\r
185                 return false;\r
186             }\r
187         } else if (!description.equals(other.description)) {\r
188             return false;\r
189         }\r
190         if (name == null) {\r
191             if (other.name != null) {\r
192                 return false;\r
193             }\r
194         } else if (!name.equals(other.name)) {\r
195             return false;\r
196         }\r
197         if (path == null) {\r
198             if (other.path != null) {\r
199                 return false;\r
200             }\r
201         } else if (!path.equals(other.path)) {\r
202             return false;\r
203         }\r
204         if (reference == null) {\r
205             if (other.reference != null) {\r
206                 return false;\r
207             }\r
208         } else if (!reference.equals(other.reference)) {\r
209             return false;\r
210         }\r
211         if (units == null) {\r
212             if (other.units != null) {\r
213                 return false;\r
214             }\r
215         } else if (!units.equals(other.units)) {\r
216             return false;\r
217         }\r
218         return true;\r
219     }\r
220 \r
221     @Override\r
222     public String toString() {\r
223         StringBuilder builder = new StringBuilder();\r
224         builder.append("BitsType [name=");\r
225         builder.append(name);\r
226         builder.append(", path=");\r
227         builder.append(path);\r
228         builder.append(", description=");\r
229         builder.append(description);\r
230         builder.append(", reference=");\r
231         builder.append(reference);\r
232         builder.append(", bits=");\r
233         builder.append(bits);\r
234         builder.append(", units=");\r
235         builder.append(units);\r
236         builder.append("]");\r
237         return builder.toString();\r
238     }\r
239 }\r