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