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 class BinaryType implements BinaryTypeDefinition {
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";
33 private List<Byte> bytes;
34 private final List<LengthConstraint> lengthConstraints;
35 private String units = "";
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();
53 * @param lengthConstraints
56 public BinaryType(final List<Byte> bytes,
57 final List<LengthConstraint> lengthConstraints, final String units) {
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);
65 this.lengthConstraints = Collections.unmodifiableList(lengthConstraints);
68 this.bytes = Collections.unmodifiableList(bytes);
75 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
78 public BinaryTypeDefinition getBaseType() {
85 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
88 public String getUnits() {
95 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
98 public Object getDefaultValue() {
105 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
108 public QName getQName() {
115 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
118 public SchemaPath getPath() {
125 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
128 public String getDescription() {
135 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
138 public String getReference() {
145 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
148 public Status getStatus() {
149 return Status.CURRENT;
156 * org.opendaylight.controller.yang.model.base.type.api.BinaryTypeDefinition#getLengthConstraint
160 public List<LengthConstraint> getLengthConstraints() {
161 return lengthConstraints;
165 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
166 return Collections.emptyList();
170 public int hashCode() {
171 final int prime = 31;
173 result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
174 result = prime * result
175 + ((description == null) ? 0 : description.hashCode());
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());
188 public boolean equals(Object obj) {
195 if (getClass() != obj.getClass()) {
198 BinaryType other = (BinaryType) obj;
200 if (other.bytes != null) {
203 } else if (!bytes.equals(other.bytes)) {
206 if (description == null) {
207 if (other.description != null) {
210 } else if (!description.equals(other.description)) {
213 if (lengthConstraints == null) {
214 if (other.lengthConstraints != null) {
217 } else if (!lengthConstraints.equals(other.lengthConstraints)) {
221 if (other.name != null) {
224 } else if (!name.equals(other.name)) {
228 if (other.path != null) {
231 } else if (!path.equals(other.path)) {
234 if (reference == null) {
235 if (other.reference != null) {
238 } else if (!reference.equals(other.reference)) {
242 if (other.units != null) {
245 } else if (!units.equals(other.units)) {
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);
269 return builder.toString();