Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / persisted / ByteState.java
1 /*
2  * Copyright (c) 2017 Brocade Communications 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.controller.cluster.raft.persisted;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Arrays;
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * Snapshot State implementation backed by a byte[].
17  *
18  * @author Thomas Pantelis
19  */
20 public final class ByteState implements Snapshot.State {
21     private static final long serialVersionUID = 1L;
22
23     private final byte @NonNull[] bytes;
24
25     private ByteState(final byte @NonNull[] bytes) {
26         this.bytes = requireNonNull(bytes);
27     }
28
29     public static @NonNull ByteState of(final byte @NonNull[] bytes) {
30         return new ByteState(bytes);
31     }
32
33     public static @NonNull ByteState empty() {
34         return new ByteState(new byte[0]);
35     }
36
37     public byte @NonNull[] getBytes() {
38         return bytes;
39     }
40
41     @Override
42     public int hashCode() {
43         final int prime = 31;
44         int result = 1;
45         result = prime * result + Arrays.hashCode(bytes);
46         return result;
47     }
48
49     @Override
50     public boolean equals(final Object obj) {
51         if (this == obj) {
52             return true;
53         }
54         if (obj == null) {
55             return false;
56         }
57         if (getClass() != obj.getClass()) {
58             return false;
59         }
60         ByteState other = (ByteState) obj;
61         if (!Arrays.equals(bytes, other.bytes)) {
62             return false;
63         }
64         return true;
65     }
66
67     @Override
68     public String toString() {
69         return "ByteState [bytes=" + Arrays.toString(bytes) + "]";
70     }
71 }