2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.model.util;
\r
10 import java.util.ArrayList;
\r
11 import java.util.Collections;
\r
12 import java.util.List;
\r
14 import org.opendaylight.controller.model.api.type.BinaryTypeDefinition;
\r
15 import org.opendaylight.controller.model.api.type.LengthConstraint;
\r
16 import org.opendaylight.controller.yang.common.QName;
\r
17 import org.opendaylight.controller.yang.model.api.SchemaPath;
\r
18 import org.opendaylight.controller.yang.model.api.Status;
\r
19 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
\r
22 * The <code>default</code> implementation of Binary Type Definition interface.
\r
24 * @see BinaryTypeDefinition
\r
26 public class BinaryType implements BinaryTypeDefinition {
\r
28 private final QName name = BaseTypes.constructQName("binary");
\r
29 private final SchemaPath path = BaseTypes.schemaPath(name);
\r
30 private final String description = "The binary built-in type represents any binary data, i.e., a sequence of octets.";
\r
31 private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.8";
\r
33 private List<Byte> bytes;
\r
34 private final List<LengthConstraint> lengthConstraints;
\r
35 private String units = "";
\r
40 public BinaryType() {
\r
43 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
\r
44 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
\r
45 lengthConstraints = Collections.unmodifiableList(constraints);
\r
46 bytes = Collections.emptyList();
\r
53 * @param lengthConstraints
\r
56 public BinaryType(final List<Byte> bytes,
\r
57 final List<LengthConstraint> lengthConstraints, final String units) {
\r
60 if ((lengthConstraints == null) || (lengthConstraints.isEmpty())) {
\r
61 final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
\r
62 constraints.add(BaseConstraints.lengthConstraint(0, Long.MAX_VALUE, "", ""));
\r
63 this.lengthConstraints = Collections.unmodifiableList(constraints);
\r
65 this.lengthConstraints = Collections.unmodifiableList(lengthConstraints);
\r
68 this.bytes = Collections.unmodifiableList(bytes);
\r
75 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
\r
78 public BinaryTypeDefinition getBaseType() {
\r
85 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getUnits()
\r
88 public String getUnits() {
\r
95 * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
\r
98 public Object getDefaultValue() {
\r
105 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getQName()
\r
108 public QName getQName() {
\r
115 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getPath()
\r
118 public SchemaPath getPath() {
\r
125 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
\r
128 public String getDescription() {
\r
129 return description;
\r
135 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getReference()
\r
138 public String getReference() {
\r
145 * @see org.opendaylight.controller.yang.model.api.SchemaNode#getStatus()
\r
148 public Status getStatus() {
\r
149 return Status.CURRENT;
\r
156 * org.opendaylight.controller.yang.model.base.type.api.BinaryTypeDefinition#getLengthConstraint
\r
160 public List<LengthConstraint> getLengthConstraints() {
\r
161 return lengthConstraints;
\r
165 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
\r
166 return Collections.emptyList();
\r
170 public int hashCode() {
\r
171 final int prime = 31;
\r
173 result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
\r
174 result = prime * result
\r
175 + ((description == null) ? 0 : description.hashCode());
\r
178 + ((lengthConstraints == null) ? 0 : lengthConstraints.hashCode());
\r
179 result = prime * result + ((name == null) ? 0 : name.hashCode());
\r
180 result = prime * result + ((path == null) ? 0 : path.hashCode());
\r
181 result = prime * result
\r
182 + ((reference == null) ? 0 : reference.hashCode());
\r
183 result = prime * result + ((units == null) ? 0 : units.hashCode());
\r
188 public boolean equals(Object obj) {
\r
195 if (getClass() != obj.getClass()) {
\r
198 BinaryType other = (BinaryType) obj;
\r
199 if (bytes == null) {
\r
200 if (other.bytes != null) {
\r
203 } else if (!bytes.equals(other.bytes)) {
\r
206 if (description == null) {
\r
207 if (other.description != null) {
\r
210 } else if (!description.equals(other.description)) {
\r
213 if (lengthConstraints == null) {
\r
214 if (other.lengthConstraints != null) {
\r
217 } else if (!lengthConstraints.equals(other.lengthConstraints)) {
\r
220 if (name == null) {
\r
221 if (other.name != null) {
\r
224 } else if (!name.equals(other.name)) {
\r
227 if (path == null) {
\r
228 if (other.path != null) {
\r
231 } else if (!path.equals(other.path)) {
\r
234 if (reference == null) {
\r
235 if (other.reference != null) {
\r
238 } else if (!reference.equals(other.reference)) {
\r
241 if (units == null) {
\r
242 if (other.units != null) {
\r
245 } else if (!units.equals(other.units)) {
\r
252 public String toString() {
\r
253 StringBuilder builder = new StringBuilder();
\r
254 builder.append("BinaryType [name=");
\r
255 builder.append(name);
\r
256 builder.append(", path=");
\r
257 builder.append(path);
\r
258 builder.append(", description=");
\r
259 builder.append(description);
\r
260 builder.append(", reference=");
\r
261 builder.append(reference);
\r
262 builder.append(", bytes=");
\r
263 builder.append(bytes);
\r
264 builder.append(", lengthConstraints=");
\r
265 builder.append(lengthConstraints);
\r
266 builder.append(", units=");
\r
267 builder.append(units);
\r
268 builder.append("]");
\r
269 return builder.toString();
\r