Improve Frontend{Client,History}Metadata 01/98301/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 6 Nov 2021 09:20:00 +0000 (10:20 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 6 Nov 2021 10:20:56 +0000 (11:20 +0100)
We are using Guava's immutable implementations, make sure we annotate
fields with @NonNull and use concrete types.

Change-Id: I4fc2a0ff39b2b8166deca41425771ea9ed04e469
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendClientMetadata.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendHistoryMetadata.java

index c9b2430..c119969 100644 (file)
@@ -22,15 +22,16 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.concepts.WritableObject;
 import org.opendaylight.yangtools.concepts.WritableObjects;
 
 public final class FrontendClientMetadata implements Identifiable<ClientIdentifier>, WritableObject {
-    private final Collection<FrontendHistoryMetadata> currentHistories;
-    private final RangeSet<UnsignedLong> purgedHistories;
-    private final ClientIdentifier identifier;
+    private final @NonNull ImmutableList<FrontendHistoryMetadata> currentHistories;
+    private final @NonNull ImmutableRangeSet<UnsignedLong> purgedHistories;
+    private final @NonNull ClientIdentifier identifier;
 
     public FrontendClientMetadata(final ClientIdentifier identifier, final RangeSet<UnsignedLong> purgedHistories,
             final Collection<FrontendHistoryMetadata> currentHistories) {
index fc0bd44..e9a076e 100644 (file)
@@ -22,12 +22,13 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.WritableObject;
 import org.opendaylight.yangtools.concepts.WritableObjects;
 
 public final class FrontendHistoryMetadata implements WritableObject {
-    private final RangeSet<UnsignedLong> purgedTransactions;
-    private final Map<UnsignedLong, Boolean> closedTransactions;
+    private final @NonNull ImmutableRangeSet<UnsignedLong> purgedTransactions;
+    private final @NonNull ImmutableMap<UnsignedLong, Boolean> closedTransactions;
     private final long historyId;
     private final long cookie;
     private final boolean closed;
@@ -70,7 +71,7 @@ public final class FrontendHistoryMetadata implements WritableObject {
         WritableObjects.writeLongs(out, closedTransactions.size(), purgedRanges.size());
         for (Entry<UnsignedLong, Boolean> e : closedTransactions.entrySet()) {
             WritableObjects.writeLong(out, e.getKey().longValue());
-            out.writeBoolean(e.getValue().booleanValue());
+            out.writeBoolean(e.getValue());
         }
         for (Range<UnsignedLong> r : purgedRanges) {
             WritableObjects.writeLongs(out, r.lowerEndpoint().longValue(), r.upperEndpoint().longValue());
@@ -95,7 +96,7 @@ public final class FrontendHistoryMetadata implements WritableObject {
         final Map<UnsignedLong, Boolean> closedTransactions = new HashMap<>(csize);
         for (int i = 0; i < csize; ++i) {
             final UnsignedLong key = UnsignedLong.fromLongBits(WritableObjects.readLong(in));
-            final Boolean value = Boolean.valueOf(in.readBoolean());
+            final Boolean value = in.readBoolean();
             closedTransactions.put(key, value);
         }
         final RangeSet<UnsignedLong> purgedTransactions = TreeRangeSet.create();