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 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 List<Byte> bytes;
33 private final List<LengthConstraint> lengthConstraints;
34 private 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 + ((description == null) ? 0 : description.hashCode());
154 result = prime * result + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
155 result = prime * result + ((name == null) ? 0 : name.hashCode());
156 result = prime * result + ((path == null) ? 0 : path.hashCode());
157 result = prime * result + ((reference == null) ? 0 : reference.hashCode());
158 result = prime * result + ((units == null) ? 0 : units.hashCode());
163 public boolean equals(Object obj) {
170 if (getClass() != obj.getClass()) {
173 BinaryType other = (BinaryType) obj;
175 if (other.bytes != null) {
178 } else if (!bytes.equals(other.bytes)) {
181 if (description == null) {
182 if (other.description != null) {
185 } else if (!description.equals(other.description)) {
188 if (lengthConstraints == null) {
189 if (other.lengthConstraints != null) {
192 } else if (!lengthConstraints.equals(other.lengthConstraints)) {
196 if (other.name != null) {
199 } else if (!name.equals(other.name)) {
203 if (other.path != null) {
206 } else if (!path.equals(other.path)) {
209 if (reference == null) {
210 if (other.reference != null) {
213 } else if (!reference.equals(other.reference)) {
217 if (other.units != null) {
220 } else if (!units.equals(other.units)) {
227 public String toString() {
228 StringBuilder builder = new StringBuilder();
229 builder.append("BinaryType [name=");
230 builder.append(name);
231 builder.append(", path=");
232 builder.append(path);
233 builder.append(", description=");
234 builder.append(description);
235 builder.append(", reference=");
236 builder.append(reference);
237 builder.append(", bytes=");
238 builder.append(bytes);
239 builder.append(", lengthConstraints=");
240 builder.append(lengthConstraints);
241 builder.append(", units=");
242 builder.append(units);
244 return builder.toString();