X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fpersisted%2FByteState.java;fp=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fpersisted%2FByteState.java;h=42411a95c4c28f6bc48ef1d965d3535e6136773f;hb=2faf656bf68dd3843fd59520b27a7ec2abbdcc68;hp=0000000000000000000000000000000000000000;hpb=d04b71990a802071a786fe8f0df57bc4adbdec3f;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/persisted/ByteState.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/persisted/ByteState.java new file mode 100644 index 0000000000..42411a95c4 --- /dev/null +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/persisted/ByteState.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.raft.persisted; + +import com.google.common.base.Preconditions; +import java.util.Arrays; +import javax.annotation.Nonnull; + +/** + * Snapshot State implementation backed by a byte[]. + * + * @author Thomas Pantelis + */ +public class ByteState implements Snapshot.State { + private static final long serialVersionUID = 1L; + + private final byte[] bytes; + + private ByteState(@Nonnull byte[] bytes) { + this.bytes = Preconditions.checkNotNull(bytes); + } + + public static ByteState of(@Nonnull byte[] bytes) { + return new ByteState(bytes); + } + + public static ByteState empty() { + return new ByteState(new byte[0]); + } + + public byte[] getBytes() { + return bytes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(bytes); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ByteState other = (ByteState) obj; + if (!Arrays.equals(bytes, other.bytes)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "ByteState [bytes=" + Arrays.toString(bytes) + "]"; + } +}