2 * Copyright (c) 2017 Brocade Communications Systems, Inc. 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.controller.cluster.raft.persisted;
10 import com.google.common.base.Preconditions;
11 import java.util.Arrays;
12 import javax.annotation.Nonnull;
15 * Snapshot State implementation backed by a byte[].
17 * @author Thomas Pantelis
19 public class ByteState implements Snapshot.State {
20 private static final long serialVersionUID = 1L;
22 private final byte[] bytes;
24 private ByteState(@Nonnull byte[] bytes) {
25 this.bytes = Preconditions.checkNotNull(bytes);
28 public static ByteState of(@Nonnull byte[] bytes) {
29 return new ByteState(bytes);
32 public static ByteState empty() {
33 return new ByteState(new byte[0]);
36 public byte[] getBytes() {
41 public int hashCode() {
44 result = prime * result + Arrays.hashCode(bytes);
49 public boolean equals(Object obj) {
56 if (getClass() != obj.getClass()) {
59 ByteState other = (ByteState) obj;
60 if (!Arrays.equals(bytes, other.bytes)) {
67 public String toString() {
68 return "ByteState [bytes=" + Arrays.toString(bytes) + "]";