Fix checkstyle reported by odlparent-3.0.0
[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 com.google.common.base.Preconditions;
11 import java.util.Arrays;
12 import javax.annotation.Nonnull;
13
14 /**
15  * Snapshot State implementation backed by a byte[].
16  *
17  * @author Thomas Pantelis
18  */
19 public final class ByteState implements Snapshot.State {
20     private static final long serialVersionUID = 1L;
21
22     private final byte[] bytes;
23
24     private ByteState(@Nonnull final byte[] bytes) {
25         this.bytes = Preconditions.checkNotNull(bytes);
26     }
27
28     public static ByteState of(@Nonnull final byte[] bytes) {
29         return new ByteState(bytes);
30     }
31
32     public static ByteState empty() {
33         return new ByteState(new byte[0]);
34     }
35
36     public byte[] getBytes() {
37         return bytes;
38     }
39
40     @Override
41     public int hashCode() {
42         final int prime = 31;
43         int result = 1;
44         result = prime * result + Arrays.hashCode(bytes);
45         return result;
46     }
47
48     @Override
49     public boolean equals(final Object obj) {
50         if (this == obj) {
51             return true;
52         }
53         if (obj == null) {
54             return false;
55         }
56         if (getClass() != obj.getClass()) {
57             return false;
58         }
59         ByteState other = (ByteState) obj;
60         if (!Arrays.equals(bytes, other.bytes)) {
61             return false;
62         }
63         return true;
64     }
65
66     @Override
67     public String toString() {
68         return "ByteState [bytes=" + Arrays.toString(bytes) + "]";
69     }
70 }