Bump versions 9.0.4-SNAPSHOT
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / DatastoreSnapshot.java
index b37fb4d001f72d00848ee59de8a0eadcd533c3d7..9c0a3acc72d12c4a406ef4085aca068f5c9ee29b 100644 (file)
@@ -7,17 +7,13 @@
  */
 package org.opendaylight.controller.cluster.datastore.persisted;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableList;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.List;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 
 /**
@@ -25,140 +21,61 @@ import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
  *
  * @author Thomas Pantelis
  */
-public class DatastoreSnapshot implements Serializable {
+public final class DatastoreSnapshot implements Serializable {
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
 
-    private static final class Proxy implements Externalizable {
-        private static final long serialVersionUID = 1L;
-
-        private DatastoreSnapshot datastoreSnapshot;
-
-        // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
-        // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
-        @SuppressWarnings("checkstyle:RedundantModifier")
-        public Proxy() {
-            // For Externalizable
-        }
-
-        Proxy(final DatastoreSnapshot datastoreSnapshot) {
-            this.datastoreSnapshot = datastoreSnapshot;
-        }
-
-        @Override
-        public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(datastoreSnapshot.type);
-            out.writeObject(datastoreSnapshot.shardManagerSnapshot);
-
-            out.writeInt(datastoreSnapshot.shardSnapshots.size());
-            for (ShardSnapshot shardSnapshot: datastoreSnapshot.shardSnapshots) {
-                out.writeObject(shardSnapshot);
-            }
-        }
-
-        @Override
-        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            String type = (String)in.readObject();
-            ShardManagerSnapshot shardManagerSnapshot = (ShardManagerSnapshot) in.readObject();
-
-            int size = in.readInt();
-            List<ShardSnapshot> shardSnapshots = new ArrayList<>(size);
-            for (int i = 0; i < size; i++) {
-                shardSnapshots.add((ShardSnapshot) in.readObject());
-            }
-
-            datastoreSnapshot = new DatastoreSnapshot(type, shardManagerSnapshot, shardSnapshots);
-        }
-
-        private Object readResolve() {
-            return datastoreSnapshot;
-        }
-    }
-
-    private final String type;
+    private final @NonNull String type;
     private final ShardManagerSnapshot shardManagerSnapshot;
-    private final List<ShardSnapshot> shardSnapshots;
+    private final @NonNull ImmutableList<ShardSnapshot> shardSnapshots;
 
-    public DatastoreSnapshot(@Nonnull String type, @Nullable ShardManagerSnapshot shardManagerSnapshot,
-            @Nonnull List<ShardSnapshot> shardSnapshots) {
-        this.type = Preconditions.checkNotNull(type);
+    public DatastoreSnapshot(final @NonNull String type, final @Nullable ShardManagerSnapshot shardManagerSnapshot,
+            final @NonNull List<ShardSnapshot> shardSnapshots) {
+        this.type = requireNonNull(type);
         this.shardManagerSnapshot = shardManagerSnapshot;
-        this.shardSnapshots = ImmutableList.copyOf(Preconditions.checkNotNull(shardSnapshots));
+        this.shardSnapshots = ImmutableList.copyOf(shardSnapshots);
     }
 
-    @Nonnull
-    public String getType() {
+    public @NonNull String getType() {
         return type;
     }
 
-    @Nullable
-    public ShardManagerSnapshot getShardManagerSnapshot() {
+    public @Nullable ShardManagerSnapshot getShardManagerSnapshot() {
         return shardManagerSnapshot;
     }
 
-    @Nonnull
-    public List<ShardSnapshot> getShardSnapshots() {
+    public @NonNull List<ShardSnapshot> getShardSnapshots() {
         return shardSnapshots;
     }
 
+    @java.io.Serial
     private Object writeReplace() {
-        return new Proxy(this);
+        return new DS(this);
     }
 
-    public static class ShardSnapshot implements Serializable {
+    public static final class ShardSnapshot implements Serializable {
+        @java.io.Serial
         private static final long serialVersionUID = 1L;
 
-        private static final class Proxy implements Externalizable {
-            private static final long serialVersionUID = 1L;
-
-            private ShardSnapshot shardSnapshot;
-
-            // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
-            // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
-            @SuppressWarnings("checkstyle:RedundantModifier")
-            public Proxy() {
-                // For Externalizable
-            }
-
-            Proxy(final ShardSnapshot shardSnapshot) {
-                this.shardSnapshot = shardSnapshot;
-            }
-
-            @Override
-            public void writeExternal(ObjectOutput out) throws IOException {
-                out.writeObject(shardSnapshot.name);
-                out.writeObject(shardSnapshot.snapshot);
-            }
-
-            @Override
-            public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-                shardSnapshot = new ShardSnapshot((String)in.readObject(), (Snapshot) in.readObject());
-            }
-
-            private Object readResolve() {
-                return shardSnapshot;
-            }
-        }
-
-        private final String name;
-        private final Snapshot snapshot;
+        private final @NonNull String name;
+        private final @NonNull Snapshot snapshot;
 
-        public ShardSnapshot(@Nonnull String name, @Nonnull Snapshot snapshot) {
-            this.name = Preconditions.checkNotNull(name);
-            this.snapshot = Preconditions.checkNotNull(snapshot);
+        public ShardSnapshot(final @NonNull String name, final @NonNull Snapshot snapshot) {
+            this.name = requireNonNull(name);
+            this.snapshot = requireNonNull(snapshot);
         }
 
-        @Nonnull
-        public String getName() {
+        public @NonNull String getName() {
             return name;
         }
 
-        @Nonnull
-        public Snapshot getSnapshot() {
+        public @NonNull Snapshot getSnapshot() {
             return snapshot;
         }
 
+        @java.io.Serial
         private Object writeReplace() {
-            return new Proxy(this);
+            return new DSS(this);
         }
     }
 }