Merge from development repository.
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / model / util / BinaryType.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.BinaryTypeDefinition;\r
14 import org.opendaylight.controller.model.api.type.LengthConstraint;\r
15 import org.opendaylight.controller.yang.common.QName;\r
16 import org.opendaylight.controller.yang.model.api.SchemaPath;\r
17 import org.opendaylight.controller.yang.model.api.Status;\r
18 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;\r
19 \r
20 public class BinaryType implements BinaryTypeDefinition {\r
21 \r
22     private final QName name = BaseTypes.constructQName("binary");\r
23     private final SchemaPath path = BaseTypes.schemaPath(name);\r
24     private final String description = "";\r
25     private final String reference = "";\r
26 \r
27     private List<Byte> bytes;\r
28     private final List<LengthConstraint> lengthConstraints;\r
29     private String units = "";\r
30 \r
31     public BinaryType() {\r
32         super();\r
33 \r
34         lengthConstraints = Collections.emptyList();\r
35         bytes = Collections.emptyList();\r
36         bytes = Collections.unmodifiableList(bytes);\r
37     }\r
38 \r
39     public BinaryType(final List<Byte> bytes,\r
40             final List<LengthConstraint> lengthConstraints, final String units) {\r
41         super();\r
42         this.bytes = bytes;\r
43         this.lengthConstraints = lengthConstraints;\r
44         this.units = units;\r
45     }\r
46 \r
47     /*\r
48      * (non-Javadoc)\r
49      *\r
50      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()\r
51      */\r
52     @Override\r
53     public BinaryTypeDefinition getBaseType() {\r
54         return this;\r
55     }\r
56 \r
57     /*\r
58      * (non-Javadoc)\r
59      *\r
60      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()\r
61      */\r
62     @Override\r
63     public String getUnits() {\r
64         return units;\r
65     }\r
66 \r
67     /*\r
68      * (non-Javadoc)\r
69      *\r
70      * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()\r
71      */\r
72     @Override\r
73     public Object getDefaultValue() {\r
74         return bytes;\r
75     }\r
76 \r
77     /*\r
78      * (non-Javadoc)\r
79      *\r
80      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()\r
81      */\r
82     @Override\r
83     public QName getQName() {\r
84         return name;\r
85     }\r
86 \r
87     /*\r
88      * (non-Javadoc)\r
89      *\r
90      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()\r
91      */\r
92     @Override\r
93     public SchemaPath getPath() {\r
94         return path;\r
95     }\r
96 \r
97     /*\r
98      * (non-Javadoc)\r
99      *\r
100      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()\r
101      */\r
102     @Override\r
103     public String getDescription() {\r
104         return description;\r
105     }\r
106 \r
107     /*\r
108      * (non-Javadoc)\r
109      *\r
110      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()\r
111      */\r
112     @Override\r
113     public String getReference() {\r
114         return reference;\r
115     }\r
116 \r
117     /*\r
118      * (non-Javadoc)\r
119      *\r
120      * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()\r
121      */\r
122     @Override\r
123     public Status getStatus() {\r
124         return Status.CURRENT;\r
125     }\r
126 \r
127     /*\r
128      * (non-Javadoc)\r
129      *\r
130      * @see\r
131      * org.opendaylight.controller.yang.model.base.type.api.BinaryTypeDefinition#getLengthConstraint\r
132      * ()\r
133      */\r
134     @Override\r
135     public List<LengthConstraint> getLengthConstraints() {\r
136         return lengthConstraints;\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 int hashCode() {\r
146         final int prime = 31;\r
147         int result = 1;\r
148         result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());\r
149         result = prime * result\r
150                 + ((description == null) ? 0 : description.hashCode());\r
151         result = prime\r
152                 * result\r
153                 + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());\r
154         result = prime * result + ((name == null) ? 0 : name.hashCode());\r
155         result = prime * result + ((path == null) ? 0 : path.hashCode());\r
156         result = prime * result\r
157                 + ((reference == null) ? 0 : reference.hashCode());\r
158         result = prime * result + ((units == null) ? 0 : units.hashCode());\r
159         return result;\r
160     }\r
161 \r
162     @Override\r
163     public boolean equals(Object obj) {\r
164         if (this == obj) {\r
165             return true;\r
166         }\r
167         if (obj == null) {\r
168             return false;\r
169         }\r
170         if (getClass() != obj.getClass()) {\r
171             return false;\r
172         }\r
173         BinaryType other = (BinaryType) obj;\r
174         if (bytes == null) {\r
175             if (other.bytes != null) {\r
176                 return false;\r
177             }\r
178         } else if (!bytes.equals(other.bytes)) {\r
179             return false;\r
180         }\r
181         if (description == null) {\r
182             if (other.description != null) {\r
183                 return false;\r
184             }\r
185         } else if (!description.equals(other.description)) {\r
186             return false;\r
187         }\r
188         if (lengthConstraints == null) {\r
189             if (other.lengthConstraints != null) {\r
190                 return false;\r
191             }\r
192         } else if (!lengthConstraints.equals(other.lengthConstraints)) {\r
193             return false;\r
194         }\r
195         if (name == null) {\r
196             if (other.name != null) {\r
197                 return false;\r
198             }\r
199         } else if (!name.equals(other.name)) {\r
200             return false;\r
201         }\r
202         if (path == null) {\r
203             if (other.path != null) {\r
204                 return false;\r
205             }\r
206         } else if (!path.equals(other.path)) {\r
207             return false;\r
208         }\r
209         if (reference == null) {\r
210             if (other.reference != null) {\r
211                 return false;\r
212             }\r
213         } else if (!reference.equals(other.reference)) {\r
214             return false;\r
215         }\r
216         if (units == null) {\r
217             if (other.units != null) {\r
218                 return false;\r
219             }\r
220         } else if (!units.equals(other.units)) {\r
221             return false;\r
222         }\r
223         return true;\r
224     }\r
225 \r
226     @Override\r
227     public String toString() {\r
228         StringBuilder builder = new StringBuilder();\r
229         builder.append("BinaryType [name=");\r
230         builder.append(name);\r
231         builder.append(", path=");\r
232         builder.append(path);\r
233         builder.append(", description=");\r
234         builder.append(description);\r
235         builder.append(", reference=");\r
236         builder.append(reference);\r
237         builder.append(", bytes=");\r
238         builder.append(bytes);\r
239         builder.append(", lengthConstraints=");\r
240         builder.append(lengthConstraints);\r
241         builder.append(", units=");\r
242         builder.append(units);\r
243         builder.append("]");\r
244         return builder.toString();\r
245     }\r
246 }\r