Fix FindBugs warnings in sal-distributed-datastore and enable enforcement
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / DatastoreSnapshot.java
1 /*
2  * Copyright (c) 2015 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.datastore.messages;
9
10 import com.google.common.base.Preconditions;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.io.Serializable;
13 import java.util.List;
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16
17 /**
18  * Stores a snapshot of the internal state of a data store.
19  *
20  * @author Thomas Pantelis
21  */
22 public class DatastoreSnapshot implements Serializable {
23     private static final long serialVersionUID = 1L;
24
25     private final String type;
26     private final byte[] shardManagerSnapshot;
27     private final List<ShardSnapshot> shardSnapshots;
28
29     @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Stores a reference to an externally mutable byte[] "
30             + "object but this is OK since this class is merely a DTO and does not process byte[] internally. "
31             + "Also it would be inefficient to create a return copy as the byte[] could be large.")
32     public DatastoreSnapshot(@Nonnull String type, @Nullable byte[] shardManagerSnapshot,
33             @Nonnull List<ShardSnapshot> shardSnapshots) {
34         this.type = Preconditions.checkNotNull(type);
35         this.shardManagerSnapshot = shardManagerSnapshot;
36         this.shardSnapshots = Preconditions.checkNotNull(shardSnapshots);
37     }
38
39     @Nonnull
40     public String getType() {
41         return type;
42     }
43
44     @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but "
45             + "this is OK since this class is merely a DTO and does not process byte[] internally. "
46             + "Also it would be inefficient to create a return copy as the byte[] could be large.")
47     @Nullable
48     public byte[] getShardManagerSnapshot() {
49         return shardManagerSnapshot;
50     }
51
52     @Nonnull
53     public List<ShardSnapshot> getShardSnapshots() {
54         return shardSnapshots;
55     }
56
57     public static class ShardSnapshot implements Serializable {
58         private static final long serialVersionUID = 1L;
59
60         private final String name;
61         private final byte[] snapshot;
62
63         public ShardSnapshot(@Nonnull String name, @Nonnull byte[] snapshot) {
64             this.name = Preconditions.checkNotNull(name);
65             this.snapshot = Preconditions.checkNotNull(snapshot);
66         }
67
68         @Nonnull
69         public String getName() {
70             return name;
71         }
72
73         @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but "
74                 + "this is OK since this class is merely a DTO and does not process byte[] internally. "
75                 + "Also it would be inefficient to create a return copy as the byte[] could be large.")
76         @Nonnull
77         public byte[] getSnapshot() {
78             return snapshot;
79         }
80     }
81 }