Fix UnsignedLongSet entry lifecycle
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / utils / UnsignedLongSet.java
index daf958a987eece6b262bf1d729ac2ce012d31c45..e3fa6263e634a99078de115f7ba51314b76ebb60 100644 (file)
@@ -19,6 +19,7 @@ import com.google.common.primitives.UnsignedLong;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.NavigableSet;
 import java.util.TreeSet;
@@ -67,10 +68,6 @@ abstract class UnsignedLongSet {
             return UnsignedLong.fromLongBits(upperBits);
         }
 
-        boolean contains(final long longBits) {
-            return Long.compareUnsigned(lowerBits, longBits) <= 0 && Long.compareUnsigned(upperBits, longBits) >= 0;
-        }
-
         Entry copy() {
             return new Entry(lowerBits, upperBits);
         }
@@ -139,7 +136,9 @@ abstract class UnsignedLongSet {
 
     public final boolean contains(final long longBits) {
         final var head = ranges.floor(Entry.of(longBits));
-        return head != null && head.contains(longBits);
+        return head != null
+            && Long.compareUnsigned(head.lowerBits, longBits) <= 0
+            && Long.compareUnsigned(head.upperBits, longBits) >= 0;
     }
 
     public final boolean isEmpty() {
@@ -153,7 +152,7 @@ abstract class UnsignedLongSet {
     public abstract @NonNull ImmutableUnsignedLongSet immutableCopy();
 
     public final @NonNull MutableUnsignedLongSet mutableCopy() {
-        return new MutableUnsignedLongSet(new TreeSet<>(Collections2.transform(ranges, Entry::copy)));
+        return new MutableUnsignedLongSet(new TreeSet<>(copiedRanges()));
     }
 
     public final @NonNull NavigableSet<Entry> ranges() {
@@ -164,6 +163,10 @@ abstract class UnsignedLongSet {
         return ranges;
     }
 
+    final @NonNull Collection<Entry> copiedRanges() {
+        return Collections2.transform(ranges, Entry::copy);
+    }
+
     @Override
     public final int hashCode() {
         return ranges.hashCode();