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