Remove yang.model.util.BaseTypes
[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 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.YangConstants;
15
16 /**
17  * The binary built-in type represents any binary data, i.e., a sequence of octets. Binary values are encoded with the
18  * Base64 encoding scheme (see <a href="https://tools.ietf.org/html/rfc4648#section-4">[RFC4648], Section 4</a>).<br>
19  * The canonical form of a binary value follows the rules defined in
20  * <a href="https://tools.ietf.org/html/rfc4648">[RFC4648]</a>.
21  *
22  * <p>
23  * This interface was modeled according to definition in
24  * <a href="https://tools.ietf.org/html/rfc6020#section-9.8">[RFC-6020] The binary Built-In Type</a>
25  */
26 public interface BinaryTypeDefinition extends LengthRestrictedTypeDefinition<BinaryTypeDefinition> {
27     /**
28      * Well-known QName of the {@code binary} built-in type.
29      */
30     QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, "binary").intern();
31
32     static String toString(final @NonNull BinaryTypeDefinition type) {
33         return TypeDefinitions.toStringHelper(type).add("length", type.getLengthConstraint().orElse(null)).toString();
34     }
35
36     static int hashCode(final @NonNull BinaryTypeDefinition type) {
37         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
38             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getLengthConstraint().orElse(null));
39     }
40
41     static boolean equals(final @NonNull BinaryTypeDefinition type, final @Nullable Object obj) {
42         if (type == obj) {
43             return true;
44         }
45
46         final BinaryTypeDefinition other = TypeDefinitions.castIfEquals(BinaryTypeDefinition.class, type, obj);
47         return other != null && type.getLengthConstraint().equals(other.getLengthConstraint());
48     }
49 }