Rename UnsignedLongSet.size() 94/98394/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Nov 2021 21:05:44 +0000 (22:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Nov 2021 21:33:21 +0000 (22:33 +0100)
Since we have 'Set' in our name, size() invokes Set.size(), which is
not we provide w.r.t. the number of distinct elements that are contained
in the set.

We are communicating how many ranges are stored, hence the method's name
is 'rangeSize()'.

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

index c698ccf8d22e158fc5b74c1b2b2fd9958560912a..a27b2c0311b3a0431af0cf036296b146bde82661 100644 (file)
@@ -61,7 +61,7 @@ public final class FrontendHistoryMetadata implements WritableObject {
         out.writeBoolean(closed);
 
         final int closedSize = closedTransactions.size();
         out.writeBoolean(closed);
 
         final int closedSize = closedTransactions.size();
-        final int purgedSize = purgedTransactions.size();
+        final int purgedSize = purgedTransactions.rangeSize();
         WritableObjects.writeLongs(out, closedSize, purgedSize);
         closedTransactions.writeEntriesTo(out, closedSize);
         purgedTransactions.writeRangesTo(out, purgedSize);
         WritableObjects.writeLongs(out, closedSize, purgedSize);
         closedTransactions.writeEntriesTo(out, closedSize);
         purgedTransactions.writeRangesTo(out, purgedSize);
index 47b8a8b01552dc3fee3c7ad34a2fd5783b395e03..39348716f3e696f972b823547cdb1df031834a05 100644 (file)
@@ -35,7 +35,7 @@ public final class ImmutableUnsignedLongSet extends UnsignedLongSet implements I
         if (mutable.isEmpty()) {
             return of();
         }
         if (mutable.isEmpty()) {
             return of();
         }
-        if (mutable.size() <= ARRAY_MAX_ELEMENTS) {
+        if (mutable.rangeSize() <= ARRAY_MAX_ELEMENTS) {
             return new ImmutableUnsignedLongSet(ImmutableSortedSet.copyOfSorted(mutable.trustedRanges()));
         }
         return new ImmutableUnsignedLongSet(new TreeSet<>(mutable.trustedRanges()));
             return new ImmutableUnsignedLongSet(ImmutableSortedSet.copyOfSorted(mutable.trustedRanges()));
         }
         return new ImmutableUnsignedLongSet(new TreeSet<>(mutable.trustedRanges()));
@@ -77,13 +77,14 @@ public final class ImmutableUnsignedLongSet extends UnsignedLongSet implements I
 
     @Override
     public void writeTo(final DataOutput out) throws IOException {
 
     @Override
     public void writeTo(final DataOutput out) throws IOException {
-        out.writeInt(size());
+        out.writeInt(rangeSize());
         writeRanges(out);
     }
 
     public void writeRangesTo(final @NonNull DataOutput out, final int size) throws IOException {
         writeRanges(out);
     }
 
     public void writeRangesTo(final @NonNull DataOutput out, final int size) throws IOException {
-        if (size != size()) {
-            throw new IOException("Mismatched size: expected " + size() + ", got " + size);
+        final int rangeSize = rangeSize();
+        if (size != rangeSize) {
+            throw new IOException("Mismatched size: expected " + rangeSize + ", got " + size);
         }
         writeRanges(out);
     }
         }
         writeRanges(out);
     }
index b42a945519b97204352bb1afbd9c0fc34940c110..d225033ebc9b02119cf6e76912666f7a6e174427 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore.utils;
 import com.google.common.annotations.Beta;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableRangeSet;
 import com.google.common.annotations.Beta;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.Range;
 import com.google.common.primitives.UnsignedLong;
 import java.util.NavigableSet;
 import java.util.TreeSet;
 import com.google.common.primitives.UnsignedLong;
 import java.util.NavigableSet;
 import java.util.TreeSet;
@@ -185,7 +186,9 @@ public final class MutableUnsignedLongSet extends UnsignedLongSet implements Mut
         return Entry.of(lowerBits, newUpper);
     }
 
         return Entry.of(lowerBits, newUpper);
     }
 
+    // Provides compatibility with RangeSet<UnsignedLong> using [lower, upper + 1)
     public ImmutableRangeSet<UnsignedLong> toRangeSet() {
     public ImmutableRangeSet<UnsignedLong> toRangeSet() {
-        return ImmutableRangeSet.copyOf(Collections2.transform(trustedRanges(), Entry::toUnsigned));
+        return ImmutableRangeSet.copyOf(Collections2.transform(trustedRanges(), entry -> Range.closedOpen(
+            UnsignedLong.fromLongBits(entry.lowerBits), UnsignedLong.fromLongBits(entry.upperBits + 1))));
     }
 }
     }
 }
index b9bf8c33f3df8c889c9a3bc293a7179f9e8c0aa2..59393a3ee0c4699e06093a2e3750170625a01257 100644 (file)
@@ -12,9 +12,7 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
-import com.google.common.collect.Range;
 import com.google.common.collect.RangeSet;
 import com.google.common.collect.RangeSet;
-import com.google.common.primitives.UnsignedLong;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
@@ -39,8 +37,8 @@ abstract class UnsignedLongSet {
     @Beta
     @VisibleForTesting
     public static final class Entry implements Comparable<Entry>, Immutable {
     @Beta
     @VisibleForTesting
     public static final class Entry implements Comparable<Entry>, Immutable {
-        final long lowerBits;
-        final long upperBits;
+        public final long lowerBits;
+        public final long upperBits;
 
         private Entry(final long lowerBits, final long upperBits) {
             this.lowerBits = lowerBits;
 
         private Entry(final long lowerBits, final long upperBits) {
             this.lowerBits = lowerBits;
@@ -55,16 +53,6 @@ abstract class UnsignedLongSet {
             return new Entry(lowerBits, upperBits);
         }
 
             return new Entry(lowerBits, upperBits);
         }
 
-        @VisibleForTesting
-        public @NonNull UnsignedLong lower() {
-            return UnsignedLong.fromLongBits(lowerBits);
-        }
-
-        @VisibleForTesting
-        public @NonNull UnsignedLong upper() {
-            return UnsignedLong.fromLongBits(upperBits);
-        }
-
         @NonNull Entry withLower(final long newLowerBits) {
             return of(newLowerBits, upperBits);
         }
         @NonNull Entry withLower(final long newLowerBits) {
             return of(newLowerBits, upperBits);
         }
@@ -73,11 +61,6 @@ abstract class UnsignedLongSet {
             return of(lowerBits, newUpperBits);
         }
 
             return of(lowerBits, newUpperBits);
         }
 
-        // Provides compatibility with RangeSet<UnsignedLong> using [lower, upper + 1)
-        @NonNull Range<UnsignedLong> toUnsigned() {
-            return Range.closedOpen(UnsignedLong.fromLongBits(lowerBits), UnsignedLong.fromLongBits(upperBits + 1));
-        }
-
         // These two methods provide the same serialization format as the one we've used to serialize
         // Range<UnsignedLong>
         static @NonNull Entry readUnsigned(final DataInput in) throws IOException {
         // These two methods provide the same serialization format as the one we've used to serialize
         // Range<UnsignedLong>
         static @NonNull Entry readUnsigned(final DataInput in) throws IOException {
@@ -146,7 +129,7 @@ abstract class UnsignedLongSet {
         return ranges.isEmpty();
     }
 
         return ranges.isEmpty();
     }
 
-    public final int size() {
+    public final int rangeSize() {
         return ranges.size();
     }
 
         return ranges.size();
     }