Populate data/ hierarchy
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / BinaryTypeDefinition.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.api.type;
9
10 import java.util.Objects;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13
14 /**
15  * The binary built-in type represents any binary data, i.e., a sequence of octets. Binary values are encoded with the
16  * Base64 encoding scheme (see <a href="https://tools.ietf.org/html/rfc4648#section-4">[RFC4648], Section 4</a>).<br>
17  * The canonical form of a binary value follows the rules defined in
18  * <a href="https://tools.ietf.org/html/rfc4648">[RFC4648]</a>.
19  *
20  * <p>
21  * This interface was modeled according to definition in
22  * <a href="https://tools.ietf.org/html/rfc6020#section-9.8">[RFC-6020] The binary Built-In Type</a>
23  */
24 public interface BinaryTypeDefinition extends LengthRestrictedTypeDefinition<BinaryTypeDefinition> {
25     static String toString(final @NonNull BinaryTypeDefinition type) {
26         return TypeDefinitions.toStringHelper(type).add("length", type.getLengthConstraint().orElse(null)).toString();
27     }
28
29     static int hashCode(final @NonNull BinaryTypeDefinition type) {
30         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
31             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getLengthConstraint().orElse(null));
32     }
33
34     static boolean equals(final @NonNull BinaryTypeDefinition type, final @Nullable Object obj) {
35         if (type == obj) {
36             return true;
37         }
38
39         final BinaryTypeDefinition other = TypeDefinitions.castIfEquals(BinaryTypeDefinition.class, type, obj);
40         return other != null && type.getLengthConstraint().equals(other.getLengthConstraint());
41     }
42 }