2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.yang.model.util;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
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;
22 * The <code>default</code> implementation of Binary Type Definition interface.
24 * @see BinaryTypeDefinition
26 public final class BinaryType implements BinaryTypeDefinition {
28 private final QName name = BaseTypes.constructQName("binary");
29 private final SchemaPath path;
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 private final BinaryTypeDefinition baseType;
33 private List<Byte> bytes;
34 private final List<LengthConstraint> lengthConstraints;
35 private String units = "";
37 private BinaryType() {
40 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
41 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
43 this.lengthConstraints = Collections.unmodifiableList(constraints);
44 this.bytes = Collections.emptyList();
45 this.path = BaseTypes.schemaPath(name);
49 public BinaryType(final SchemaPath path) {
52 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
53 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
55 this.lengthConstraints = Collections.unmodifiableList(constraints);
56 this.bytes = Collections.emptyList();
58 this.baseType = new BinaryType();
65 * @param lengthConstraints
68 public BinaryType(final SchemaPath path, final List<Byte> bytes,
69 final List<LengthConstraint> lengthConstraints, final String units) {
72 if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
73 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
74 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE,
76 this.lengthConstraints = Collections.unmodifiableList(constraints);
78 this.lengthConstraints = Collections
79 .unmodifiableList(lengthConstraints);
83 this.bytes = Collections.unmodifiableList(bytes);
85 this.baseType = new BinaryType();
92 * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
95 public BinaryTypeDefinition getBaseType() {
102 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
105 public String getUnits() {
113 * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
117 public Object getDefaultValue() {
124 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
127 public QName getQName() {
134 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
137 public SchemaPath getPath() {
145 * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
148 public String getDescription() {
155 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
158 public String getReference() {
165 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
168 public Status getStatus() {
169 return Status.CURRENT;
176 * org.opendaylight.controller.yang.model.base.type.api.BinaryTypeDefinition
177 * #getLengthConstraint ()
180 public List<LengthConstraint> getLengthConstraints() {
181 return lengthConstraints;
185 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
186 return Collections.emptyList();
190 public int hashCode() {
191 final int prime = 31;
193 result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
194 result = prime * result
195 + ((description == null) ? 0 : description.hashCode());
198 + ((lengthConstraints == null) ? 0 : lengthConstraints
200 result = prime * result + ((name == null) ? 0 : name.hashCode());
201 result = prime * result + ((path == null) ? 0 : path.hashCode());
202 result = prime * result
203 + ((reference == null) ? 0 : reference.hashCode());
204 result = prime * result + ((units == null) ? 0 : units.hashCode());
209 public boolean equals(Object obj) {
216 if (getClass() != obj.getClass()) {
219 BinaryType other = (BinaryType) obj;
221 if (other.bytes != null) {
224 } else if (!bytes.equals(other.bytes)) {
227 if (description == null) {
228 if (other.description != null) {
231 } else if (!description.equals(other.description)) {
234 if (lengthConstraints == null) {
235 if (other.lengthConstraints != null) {
238 } else if (!lengthConstraints.equals(other.lengthConstraints)) {
242 if (other.name != null) {
245 } else if (!name.equals(other.name)) {
249 if (other.path != null) {
252 } else if (!path.equals(other.path)) {
255 if (reference == null) {
256 if (other.reference != null) {
259 } else if (!reference.equals(other.reference)) {
263 if (other.units != null) {
266 } else if (!units.equals(other.units)) {
273 public String toString() {
274 StringBuilder builder = new StringBuilder();
275 builder.append("BinaryType [name=");
276 builder.append(name);
277 builder.append(", path=");
278 builder.append(path);
279 builder.append(", description=");
280 builder.append(description);
281 builder.append(", reference=");
282 builder.append(reference);
283 builder.append(", bytes=");
284 builder.append(bytes);
285 builder.append(", lengthConstraints=");
286 builder.append(lengthConstraints);
287 builder.append(", units=");
288 builder.append(units);
290 return builder.toString();