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