2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.data.impl.schema.tree;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Arrays;
13 import java.util.Base64;
14 import org.opendaylight.yangtools.concepts.Immutable;
16 final class BinaryValue implements Immutable {
17 private final byte[] value;
19 private BinaryValue(final byte[] value) {
20 this.value = requireNonNull(value);
23 static Object wrap(final Object value) {
24 return value instanceof byte[] ? new BinaryValue((byte[]) value) : value;
27 static Object wrapToString(final Object value) {
28 return value instanceof byte[] ? toString((byte[]) value) : value;
32 public int hashCode() {
33 return Arrays.hashCode(value);
37 public boolean equals(final Object obj) {
38 return obj == this || obj instanceof BinaryValue && Arrays.equals(value, ((BinaryValue) obj).value);
42 public String toString() {
43 return toString(value);
46 private static String toString(final byte[] value) {
47 return Base64.getEncoder().encodeToString(value);