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.yangtools.yang.model.util;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
19 import org.opendaylight.yangtools.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 static final BinaryType INSTANCE = new BinaryType();
28 private final QName name = BaseTypes.constructQName("binary");
29 private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
30 private static final String DESCRIPTION = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
31 private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.8";
32 private final List<Byte> bytes;
33 private final List<LengthConstraint> lengthConstraints;
34 private static final String UNITS = "";
36 private BinaryType() {
37 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
38 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
39 this.lengthConstraints = Collections.unmodifiableList(constraints);
40 this.bytes = Collections.emptyList();
43 public static BinaryType getInstance() {
51 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
54 public BinaryTypeDefinition getBaseType() {
61 * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
64 public String getUnits() {
72 * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
76 public Object getDefaultValue() {
83 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
86 public QName getQName() {
93 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
96 public SchemaPath getPath() {
104 * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
107 public String getDescription() {
114 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
117 public String getReference() {
124 * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
127 public Status getStatus() {
128 return Status.CURRENT;
135 * org.opendaylight.yangtools.yang.model.base.type.api.BinaryTypeDefinition
136 * #getLengthConstraint ()
139 public List<LengthConstraint> getLengthConstraints() {
140 return lengthConstraints;
144 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
145 return Collections.emptyList();
149 public int hashCode() {
150 final int prime = 31;
152 result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
153 result = prime * result + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
154 result = prime * result + ((name == null) ? 0 : name.hashCode());
155 result = prime * result + ((path == null) ? 0 : path.hashCode());
160 public boolean equals(Object obj) {
167 if (getClass() != obj.getClass()) {
170 BinaryType other = (BinaryType) obj;
172 if (other.bytes != null) {
175 } else if (!bytes.equals(other.bytes)) {
178 if (lengthConstraints == null) {
179 if (other.lengthConstraints != null) {
182 } else if (!lengthConstraints.equals(other.lengthConstraints)) {
186 if (other.name != null) {
189 } else if (!name.equals(other.name)) {
193 if (other.path != null) {
196 } else if (!path.equals(other.path)) {
203 public String toString() {
204 StringBuilder builder = new StringBuilder();
205 builder.append("BinaryType [name=");
206 builder.append(name);
207 builder.append(", path=");
208 builder.append(path);
209 builder.append(", description=");
210 builder.append(DESCRIPTION);
211 builder.append(", reference=");
212 builder.append(REFERENCE);
213 builder.append(", bytes=");
214 builder.append(bytes);
215 builder.append(", lengthConstraints=");
216 builder.append(lengthConstraints);
217 builder.append(", units=");
218 builder.append(UNITS);
220 return builder.toString();