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;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
16 import org.opendaylight.controller.yang.common.QName;
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
18 import org.opendaylight.controller.yang.model.api.Status;
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
20 import org.opendaylight.controller.yang.model.api.type.BinaryTypeDefinition;
21 import org.opendaylight.controller.yang.model.api.type.LengthConstraint;
24 * The <code>default</code> implementation of Binary Type Definition interface.
26 * @see BinaryTypeDefinition
28 public class BinaryType implements BinaryTypeDefinition {
30 private final QName name = BaseTypes.constructQName("binary");
31 private final SchemaPath path;
32 private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
33 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
34 private final BinaryTypeDefinition baseType;
35 private List<Byte> bytes;
36 private final List<LengthConstraint> lengthConstraints;
37 private String units = "";
39 private BinaryType() {
42 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
43 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
44 this.lengthConstraints = Collections.unmodifiableList(constraints);
45 this.bytes = Collections.emptyList();
46 this.path = BaseTypes.schemaPath(name);
50 public BinaryType(final List<String> actualPath, final URI namespace,
51 final Date revision) {
54 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
55 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
56 this.lengthConstraints = Collections.unmodifiableList(constraints);
57 this.bytes = Collections.emptyList();
58 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
59 this.baseType = new BinaryType();
66 * @param lengthConstraints
69 public BinaryType(final List<String> actualPath, final URI namespace,
70 final Date revision, final List<Byte> bytes,
71 final List<LengthConstraint> lengthConstraints, final String units) {
74 if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
75 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
76 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
77 this.lengthConstraints = Collections.unmodifiableList(constraints);
79 this.lengthConstraints = Collections.unmodifiableList(lengthConstraints);
82 this.path = BaseTypes.schemaPath(actualPath, namespace, revision);
83 this.bytes = Collections.unmodifiableList(bytes);
85 this.baseType = new BinaryType();
91 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
94 public BinaryTypeDefinition getBaseType() {
101 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
104 public String getUnits() {
111 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
114 public Object getDefaultValue() {
121 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
124 public QName getQName() {
131 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
134 public SchemaPath getPath() {
141 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
144 public String getDescription() {
151 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
154 public String getReference() {
161 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
164 public Status getStatus() {
165 return Status.CURRENT;
172 * org.opendaylight.controller.yang.model.base.type.api.BinaryTypeDefinition#getLengthConstraint
176 public List<LengthConstraint> getLengthConstraints() {
177 return lengthConstraints;
181 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
182 return Collections.emptyList();
186 public int hashCode() {
187 final int prime = 31;
189 result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
190 result = prime * result
191 + ((description == null) ? 0 : description.hashCode());
194 + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
195 result = prime * result + ((name == null) ? 0 : name.hashCode());
196 result = prime * result + ((path == null) ? 0 : path.hashCode());
197 result = prime * result
198 + ((reference == null) ? 0 : reference.hashCode());
199 result = prime * result + ((units == null) ? 0 : units.hashCode());
204 public boolean equals(Object obj) {
211 if (getClass() != obj.getClass()) {
214 BinaryType other = (BinaryType) obj;
216 if (other.bytes != null) {
219 } else if (!bytes.equals(other.bytes)) {
222 if (description == null) {
223 if (other.description != null) {
226 } else if (!description.equals(other.description)) {
229 if (lengthConstraints == null) {
230 if (other.lengthConstraints != null) {
233 } else if (!lengthConstraints.equals(other.lengthConstraints)) {
237 if (other.name != null) {
240 } else if (!name.equals(other.name)) {
244 if (other.path != null) {
247 } else if (!path.equals(other.path)) {
250 if (reference == null) {
251 if (other.reference != null) {
254 } else if (!reference.equals(other.reference)) {
258 if (other.units != null) {
261 } else if (!units.equals(other.units)) {
268 public String toString() {
269 StringBuilder builder = new StringBuilder();
270 builder.append("BinaryType [name=");
271 builder.append(name);
272 builder.append(", path=");
273 builder.append(path);
274 builder.append(", description=");
275 builder.append(description);
276 builder.append(", reference=");
277 builder.append(reference);
278 builder.append(", bytes=");
279 builder.append(bytes);
280 builder.append(", lengthConstraints=");
281 builder.append(lengthConstraints);
282 builder.append(", units=");
283 builder.append(units);
285 return builder.toString();