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 {
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 = "";
36 public BinaryType(final SchemaPath path) {
37 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
38 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "",
40 this.lengthConstraints = Collections.unmodifiableList(constraints);
41 this.bytes = Collections.emptyList();
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, "",
50 this.lengthConstraints = Collections.unmodifiableList(constraints);
51 this.bytes = Collections.unmodifiableList(bytes);
60 * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
63 public BinaryTypeDefinition getBaseType() {
70 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
73 public String getUnits() {
81 * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
85 public Object getDefaultValue() {
92 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
95 public QName getQName() {
102 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
105 public SchemaPath getPath() {
113 * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
116 public String getDescription() {
123 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
126 public String getReference() {
133 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
136 public Status getStatus() {
137 return Status.CURRENT;
144 * org.opendaylight.controller.yang.model.base.type.api.BinaryTypeDefinition
145 * #getLengthConstraint ()
148 public List<LengthConstraint> getLengthConstraints() {
149 return lengthConstraints;
153 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
154 return Collections.emptyList();
158 public int hashCode() {
159 final int prime = 31;
161 result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
162 result = prime * result
163 + ((description == null) ? 0 : description.hashCode());
166 + ((lengthConstraints == null) ? 0 : lengthConstraints
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());
177 public boolean equals(Object obj) {
184 if (getClass() != obj.getClass()) {
187 BinaryType other = (BinaryType) obj;
189 if (other.bytes != null) {
192 } else if (!bytes.equals(other.bytes)) {
195 if (description == null) {
196 if (other.description != null) {
199 } else if (!description.equals(other.description)) {
202 if (lengthConstraints == null) {
203 if (other.lengthConstraints != null) {
206 } else if (!lengthConstraints.equals(other.lengthConstraints)) {
210 if (other.name != null) {
213 } else if (!name.equals(other.name)) {
217 if (other.path != null) {
220 } else if (!path.equals(other.path)) {
223 if (reference == null) {
224 if (other.reference != null) {
227 } else if (!reference.equals(other.reference)) {
231 if (other.units != null) {
234 } else if (!units.equals(other.units)) {
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);
258 return builder.toString();