1// Copyright (c) Facebook, Inc. and its affiliates
2// SPDX-License-Identifier: MIT OR Apache-2.0
6import java.util.Arrays;
7import java.util.Objects;
10 * Immutable wrapper class around byte[].
12 * Enforces value-semantice for `equals` and `hashCode`.
14public final class Bytes {
15 private final byte[] content;
17 private static final Bytes EMPTY = new Bytes(new byte[0]);
19 /// Low-level constructor (use with care).
20 public Bytes(byte[] content) {
21 Objects.requireNonNull(content, "content must not be null");
22 this.content = content;
25 public static Bytes empty() {
29 public static Bytes valueOf(byte[] content) {
30 Objects.requireNonNull(content, "content must not be null");
31 if (content.length == 0) {
34 return new Bytes(content.clone());
38 public byte[] content() {
39 return this.content.clone();
42 public boolean equals(Object obj) {
43 if (this == obj) return true;
44 if (obj == null) return false;
45 if (getClass() != obj.getClass()) return false;
46 Bytes other = (Bytes) obj;
47 return Arrays.equals(this.content, other.content);
50 public int hashCode() {
51 return Arrays.hashCode(content);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list